Mar
10
Redirecting Ports Using iptables Prerouting
Filed Under (Commands, Firewall, Mail) by jc on 10-03-2008
Tagged Under : iptables, mta, prerouting, redirect
Prerouting can be very useful if you need a quick fix and do not want to mess with the application itself. For example, if you need to have your MTA listen on port 587 and do not want to alter the configuration files (the daemon will not actually listen on port 587, iptables will redirect the traffic), you can use the following iptables rule to preroute traffic going to port 587 to port 25.
/sbin/iptables -t nat -I PREROUTING -p tcp --dport 587 -j REDIRECT --to-ports 25

Handy.
I never remember iptables syntax because I’m a lazy schlub. There are certainly times when one would want to use a trick like this instead of messing with config files…but my feeble brain has trouble remembering all the stuff I do on some servers.
Keep NOTES!
Rock On
Nice and handy!
Just an observation though:
Is this setting affected by the /etc/sysctl.conf setting: net.ipv4.ip_forward=0 ?
That will be interesting to know…