Iptables Port Redirection

How to redirect to another port on the same server:

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $SERVER –dport 25 -j DNAT –to $SERVER:2525

Redirect a port to another server ($SERVER2):

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $SERVER1 –dport 25 -j DNAT –to $SERVER2:25
iptables -A FORWARD -p tcp -i eth0 -d $SERVER2 –dport 25 -j ACCEPT
iptables -t nat -A POSTROUTING -d $SERVER2 -p tcp –dport 25 -o eth0 -j MASQUERADE
iptables -A FORWARD -p tcp -i eth0 -s $SERVER2 –sport 25 -j ACCEPT
iptables -t nat -A POSTROUTING -p tcp -s $SERVER2 –sport 25 -j SNAT –to $SERVER1





Please VOTE for this page at: ADD TO DEL.ICIO.US | ADD TO DIGG | ADD TO FURL | ADD TO NEWSVINE | ADD TO NETSCAPE | ADD TO REDDIT | ADD TO STUMBLEUPON | ADD TO TECHNORATI FAVORITES | ADD TO SQUIDOO | ADD TO WINDOWS LIVE | ADD TO YAHOO MYWEB | ADD TO ASK | ADD TO GOOGLE


1 Comment


  1. wooot, yeah, wow!

    after searching the net and hours of digging into more or less useless “how to do it with a dynamic dsl and masquerading” , i found this easy and short example! thats exactly what i need!

    Thx!Thx!Thx!

    Posted April 29, 2008, 8:04 am

Leave a reply