Community discussions

MikroTik App
 
Ick
newbie
Topic Author
Posts: 26
Joined: Sat Mar 11, 2006 5:31 pm

Block certian mail

Tue Nov 02, 2010 3:52 pm

We need to add a rule that would block/drop all outgoing mail except destined for certain mail servers. What is the best way to do this? Still new to MT, but learning lots!

Eric
 
Feklar
Forum Guru
Forum Guru
Posts: 1724
Joined: Tue Dec 01, 2009 11:46 pm

Re: Block certian mail

Wed Nov 03, 2010 4:40 pm

/ip firewall filter
add chain=forward action=accept protocol=tcp dst-port=25 dst-address-list=mail_servers in-interface=LAN
add chain=forward action=drop protocol=tcp dst-port=25 in-interface=LAN
Alternatively you can redirect all port 25 traffic to one of your mail servers with a NAT rule instead of just dropping SMTP to mail servers you don't know about.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26981
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Block certian mail

Thu Nov 04, 2010 10:38 am

destined to certain servers, or sent via certain servers? RouterOS can't filter messages, that you need to do in the mail server that sends them.
 
Ick
newbie
Topic Author
Posts: 26
Joined: Sat Mar 11, 2006 5:31 pm

Re: Block certian mail

Thu Nov 04, 2010 7:32 pm

Destined to certain servers. We just want to drop everything that isn't meant for our specific mail servers.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26981
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Block certian mail

Fri Nov 05, 2010 7:47 am

Destined to certain servers. We just want to drop everything that isn't meant for our specific mail servers.
destination of the email message is inside the message. filtering based on that can only be done if you are the SMTP server that sends it. not possible on RouterOS
 
Ick
newbie
Topic Author
Posts: 26
Joined: Sat Mar 11, 2006 5:31 pm

Re: Block certian mail

Thu Nov 18, 2010 5:07 pm

Destined to certain servers. We just want to drop everything that isn't meant for our specific mail servers.
destination of the email message is inside the message. filtering based on that can only be done if you are the SMTP server that sends it. not possible on RouterOS
We changed out our core router for MT. With our previous router, we had it setup so that it would drop Bots and Worms that were being sent out by infected client computers. So if emails were sent out from client machines that used any email servers other than ours they were dropped.

Some of our professional clients had other company email servers that they used for their business, in this case we would add the ip address of their email server to our list of "approved" Email servers and their email would go through as well.

I still need to get the setup because our upstream provider is whining about it. Any help on this would be appreciated, Thanks

Eric
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Block certian mail

Thu Nov 18, 2010 5:10 pm

RouterOS cannot do that.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Block certian mail

Thu Nov 18, 2010 5:14 pm

You want to block any new connections from your localnet clients to other email servers than yours for outbound email? This should do:
/ip firewall filter
add chain=forward protocol=tcp port=25 connection-state=new dst-address=!xx.xx.xx.xx action=drop
Replace xx.xx.xx.xx with your email sever ip.
 
Ick
newbie
Topic Author
Posts: 26
Joined: Sat Mar 11, 2006 5:31 pm

Re: Block certian mail

Thu Nov 18, 2010 5:19 pm

You want to block any new connections from your localnet clients to other email servers than yours for outbound email? This should do:
/ip firewall filter
add chain=forward protocol=tcp port=25 connection-state=new dst-address=!xx.xx.xx.xx action=drop
Replace xx.xx.xx.xx with your email sever ip.
Thanks for the quick reply, how do I add the list of email servers that are ok to send to?
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Block certian mail

Thu Nov 18, 2010 5:21 pm

Make an address list enumerating all the servers and use the line Tim gave you with a slight modification to check the address list rather than the destination address directly:
/ip firewall address-list
add list=OK-smtp address=1.1.1.1
add list=OK-smtp address=2.2.2.2
/ip firewall filter
add chain=forward protocol=tcp port=25 connection-state=new dst-address=!OK-smtp action=drop
Completely missed that you weren't trying to block content, just destination.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Block certian mail

Thu Nov 18, 2010 5:28 pm

Then use these instead:
/ip firewall filter
add chain=forward protocol=tcp port=25 connection-state=new dst-address-list=email action=accept
add chain=forward protocol=tcp port=25 connection-state=new action=drop
Then put the good server ips (including yours) in
/ip firewall address-list
add address=xx.xx.xx.xx list=email
EDIT: I added "connection-state=new" to each above.

I see fewi already answered. His is the same with one less entry.
 
Ick
newbie
Topic Author
Posts: 26
Joined: Sat Mar 11, 2006 5:31 pm

Re: Block certian mail

Mon Nov 22, 2010 6:26 pm

Got my list created and all looks good there, however when I type in the last line I get the following:

[admin@www.mikrotikrouter.com] /ip firewall filter> add chain=forward protocol=t
cp port=25 connection-state=new dst-address=!OK-smtp action=drop
value of range must have ip address before '-'
[admin@www.mikrotikrouter.com] /ip firewall filter>
Make an address list enumerating all the servers and use the line Tim gave you with a slight modification to check the address list rather than the destination address directly:
/ip firewall address-list
add list=OK-smtp address=1.1.1.1
add list=OK-smtp address=2.2.2.2
/ip firewall filter
add chain=forward protocol=tcp port=25 connection-state=new dst-address=!OK-smtp action=drop
Completely missed that you weren't trying to block content, just destination.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Block certian mail

Mon Nov 22, 2010 6:30 pm

That should have been "dst-address-list=!OK-smtp", not "dst-address". That is why I use my way. I can see easier what is being accepted and what is being dropped. I have not tried "dst-address-list=!address-list".