Skip to contentSkip to conversation

Redirecting outgoing SMTP from LAN to another LAN server

DISCUSSION Gavin Hamill 5 participants 9 messages Apr 29, 2004 – May 15, 2004

lore
Share & tools
lore
#0 lore raw

Hullo :)

I'd like to do $SUBJECT, but after much playing with commands like

iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 25 -j DNAT --to 10.0.0.253:25

I have given up and have come to you fine people for help...

My LAN is on eth1, with WAN on eth0. The gateway machine is 10.0.0.254 doing masq for LAN clients, but I'd like to send any outgoing SMTP connections to 10.0.0.253 - alas any time I've tried, I just end up killing ALL outgoing SMTP :(

Any suggestions warmly received!

Cheers,
Gavin.

#1 lore raw
Quoted 5 lines · Gavin Hamill

Hullo :)

I'd like to do $SUBJECT, but after much playing with commands like

iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 25 -j DNAT --to 10.0.0.253:25

what about

iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25 -j DNAT --to 10.0.0.253:25

I presume 10.0.0.253 is also on eth1.

Quoted 13 lines

I have given up and have come to you fine people for help...

My LAN is on eth1, with WAN on eth0. The gateway machine is 10.0.0.254 doing masq for LAN clients, but I'd like to send any outgoing SMTP connections to 10.0.0.253 - alas any time I've tried, I just end up killing ALL outgoing SMTP :(

Any suggestions warmly received!

Cheers,
Gavin.

#2 lore raw

On Thu, Apr 29, 2004 at 11:37:57PM +1000, Alexander Samad told us:

Quoted 5 lines · Gavin Hamill
Quoted 4 lines

Hullo :)

I'd like to do $SUBJECT, but after much playing with commands like

Quoted 8 lines
Quoted 1 line

iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 25 -j DNAT --to 10.0.0.253:25

what about

iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25 -j DNAT --to 10.0.0.253:25

I presume 10.0.0.253 is also on eth1.

The problem here might be that both the client and the server are on the same physical network. This means

So assume we have a client (10.0.0.1) which wants to connect to a mail server (12.34.56.78) on the internet. So you DNAT the request to your internal mail server 10.0.0.253 at the firewall. Your internal mail server gets the request but will try to directly talk to the client, as in the packet the sender is still the original ip adress. (sorry if this is hard to understand, I'm not really good in explaining things :) So you will additionally need a SNAT rule on your firewall, something like

iptables -t nat -A POSTROUTING -p tcp -i eth1 -s 10.0.0.0/8 \
-d 10.0.0.253 --dport 25 -j SNAT --to 10.0.0.xx:25

where xx would be the ip of your firewall. Now both the packets from the client to the server and the returning packets from the server to the client will travel through your firewall.

HTH

Sven

Quoted 15 lines
Quoted 15 lines

I have given up and have come to you fine people for help...

My LAN is on eth1, with WAN on eth0. The gateway machine is 10.0.0.254 doing masq for LAN clients, but I'd like to send any outgoing SMTP connections to 10.0.0.253 - alas any time I've tried, I just end up killing ALL outgoing SMTP :(

Any suggestions warmly received!

Cheers,
Gavin.

Signature · 2 lines
Linux zion 2.6.6-rc1 #1 Sat Apr 17 11:50:12 CEST 2004 i686 athlon i386 GNU/Linux
 16:37:12  up 8 days, 21:26,  1 user,  load average: 0.01, 0.01, 0.00
#3 lore raw
Quoted 27 lines · Sven Schuster

On Thu, Apr 29, 2004 at 11:37:57PM +1000, Alexander Samad told us:

Quoted 5 lines · Gavin Hamill
Quoted 4 lines

Hullo :)

I'd like to do $SUBJECT, but after much playing with commands like

Quoted 8 lines
Quoted 1 line

iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 25 -j DNAT --to 10.0.0.253:25

what about

iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25 -j DNAT --to 10.0.0.253:25

I presume 10.0.0.253 is also on eth1.

The problem here might be that both the client and the server are on the same physical network. This means

So assume we have a client (10.0.0.1) which wants to connect to a mail server (12.34.56.78) on the internet. So you DNAT the request to your internal mail server 10.0.0.253 at the firewall. Your internal mail server gets the request but will try to directly talk to the client, as in the packet the sender is still the original ip adress. (sorry if this is hard to understand, I'm not really good in explaining things :) So you will additionally need a SNAT rule on your firewall, something like

Quoted 2 lines
iptables -t nat -A POSTROUTING -p tcp -i eth1 -s 10.0.0.0/8 \
   -d 10.0.0.253 --dport 25 -j SNAT --to 10.0.0.xx:25

yeap, forgot about that

Quoted 31 lines

where xx would be the ip of your firewall. Now both the packets from the client to the server and the returning packets from the server to the client will travel through your firewall.

HTH

Sven

Quoted 15 lines
Quoted 15 lines

I have given up and have come to you fine people for help...

My LAN is on eth1, with WAN on eth0. The gateway machine is 10.0.0.254 doing masq for LAN clients, but I'd like to send any outgoing SMTP connections to 10.0.0.253 - alas any time I've tried, I just end up killing ALL outgoing SMTP :(

Any suggestions warmly received!

Cheers,
Gavin.

Signature · 2 lines
Linux zion 2.6.6-rc1 #1 Sat Apr 17 11:50:12 CEST 2004 i686 athlon i386 GNU/Linux
 16:37:12  up 8 days, 21:26,  1 user,  load average: 0.01, 0.01, 0.00
#4 lore raw
In reply to Sven Schuster
Quoted 7 lines · Sven Schuster
iptables -t nat -A POSTROUTING -p tcp -i eth1 -s 10.0.0.0/8 \
   -d 10.0.0.253 --dport 25 -j SNAT --to 10.0.0.xx:25

where xx would be the ip of your firewall. Now both the packets from the client to the server and the returning packets from the server to the client will travel through your firewall.

Thanks for the reply - the explanation sounds right, and I think I understand what's going on now - I won't be able to test the theory out until next week
- I just didn't want to seem rude by staying silent to date :)

Cheers,
Gavin.

#5 lore raw
In reply to Sven Schuster
Quoted 9 lines · Sven Schuster

So you will additionally need a SNAT rule on
your firewall, something like

iptables -t nat -A POSTROUTING -p tcp -i eth1 -s 10.0.0.0/8 \
   -d 10.0.0.253 --dport 25 -j SNAT --to 10.0.0.xx:25

where xx would be the ip of your firewall. Now both the packets from the client to the server and the returning packets from the server to the client will travel through your firewall.

This is just a final followup to say thanks for the advice, and to report on the final solution.

eth0 is the 0utside, and eth1 is the 1nside (that's what I use to stop confusing myself...) and 10.0.0.254 is the firewall and default gateway for all LAN machines

$ iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25 -j 
DNAT --to 10.0.0.253:25
$ iptables -t nat -A POSTROUTING -p tcp -s 10.0.0.0/24 -d 10.0.0.253 --dport 
25 -j SNAT --to 10.0.0.254

This way, LAN users trying to connect directly to an external mail server get sent to the MTA on 10.0.0.253, and 10.0.0.253 itself still has full access to 'real' port 25 in order that it can deliver mails! :)

Cheers,
Gavin.

#6 lore raw
Quoted 12 lines · Gavin Hamill

This is just a final followup to say thanks for the advice, and to report on the final solution.

eth0 is the 0utside, and eth1 is the 1nside (that's what I use to stop confusing myself...) and 10.0.0.254 is the firewall and default gateway for all LAN machines

$ iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25
-j DNAT --to 10.0.0.253:25
$ iptables -t nat -A POSTROUTING -p tcp -s 10.0.0.0/24 -d 10.0.0.253
--dport 25 -j SNAT --to 10.0.0.254
Quoted 6 lines

This way, LAN users trying to connect directly to an external mail server get sent to the MTA on 10.0.0.253, and 10.0.0.253 itself still has full access to 'real' port 25 in order that it can deliver mails! :)

Cheers,
Gavin.

I'd just like to say that it's very nice to see a posting like this here, showing the working solution (together with an explanation of why it works, and exactly what it does), since this sort of thing is very useful to people searching the archives in future.

Find a working solution which someone has bothered to document is much more helpful than finding someone with a similar problem, and having to go through half the same effort of solving it, so thanks Gavin for providing this info.

Regards,

Antony.

Signature · 6 lines
"Black holes are where God divided by zero."

 - Steven Wright

                                                     Please reply to the list;
                                                           please don't CC me.
#7 lore raw
Quoted 15 lines · Antony Stone
Quoted 12 lines · Gavin Hamill

This is just a final followup to say thanks for the advice, and to report on the final solution.

eth0 is the 0utside, and eth1 is the 1nside (that's what I use to stop confusing myself...) and 10.0.0.254 is the firewall and default gateway for all LAN machines

$ iptables -t nat -A PREROUTING -p tcp -i eth1 -s ! 10.0.0.253 --dport 25
-j DNAT --to 10.0.0.253:25
$ iptables -t nat -A POSTROUTING -p tcp -s 10.0.0.0/24 -d 10.0.0.253
--dport 25 -j SNAT --to 10.0.0.254
Quoted 4 lines
Quoted 4 lines

This way, LAN users trying to connect directly to an external mail server get sent to the MTA on 10.0.0.253, and 10.0.0.253 itself still has full access to 'real' port 25 in order that it can deliver mails! :)

Gavin:
Why would your LAN users ever need to send SMTP to anywhere other than your MTA? With the above rules aren't you allowing an 1nside (I like that 0 1 idea!) computer, infected with a worm to propagate the virus? I apologize if I missed something in your original post that explains this.

--Micha

Quoted 12 lines
Quoted 2 lines

Cheers,
Gavin.

I'd just like to say that it's very nice to see a posting like this here, showing the working solution (together with an explanation of why it works, and exactly what it does), since this sort of thing is very useful to people searching the archives in future.

Find a working solution which someone has bothered to document is much more helpful than finding someone with a similar problem, and having to go through half the same effort of solving it, so thanks Gavin for providing this info.

Regards,

Antony.

#8 lore raw
Quoted 3 lines · Micha Silver

Gavin:
Why would your LAN users ever need to send SMTP to anywhere other than your MTA?

Mostly as a convenience. We have dozens of LAN machines with an assortment of SMTP server settings. We also have some notebooks that roam between different sites, and I deemed it more appropriate to force everyone to use the local MTA than to have to manually reconfigure everything.

Quoted 3 lines

With the above rules aren't you allowing an 1nside (I like that 0 1 idea!) computer, infected with a worm to propagate the virus?

Yes and no. Yes by allowing people to theoretically connect to any external MTA, the virus can propogate, but this is weighed against the monitoring I have in place so that the number of mails processed and load average on the MTA machine will spike up, and this allows me to quickly identify the offending machine and firewall it out completely whilst the virus is neutralised..

Thinking about it, I could simply firewall things more so that only "our" MTAs are permitted... hmm I might do that actually - thanks for the train of thought.

I'm glad you like the 0utside/1nside thing... it even holds (to a lesser extent) when you have eth2 configured as the 'DM2' interface :)

Cheers,
Gavin.