Home   >>   Iptables   >>   How To Redirect Traffic To A New IP Using IPtables
How To Redirect Traffic To A New IP Using IPtables PDF Print E-mail
( 7 Votes )
How To - Iptables
Written by Christian Foronda   
Thursday, 03 March 2011 16:57

Enable IP forwarding:

# echo 1 > /proc/sys/net/ipv4/ip_forward

Or

# sysctl net.ipv4.ip_forward=1

Forward all traffic on port 80 to IP xxx.xxx.xxx.xxx on port 80:

# iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination xxx.xxx.xxx.xxx:80

Or

Forward specific host going on port 80 to IP xxx.xxx.xxx.xxx on port 80:

# iptables -t nat -A PREROUTING -s sou.rce.ip.add -p tcp --dport 80 -j DNAT --to-destination xxx.xxx.xxx.xxx:80

Or

Forward specific network going on port 80 to IP xxx.xxx.xxx.xxx on port 80:

# iptables -t nat -A PREROUTING -s sou.rce.ip.net/24 -p tcp --dport 80 -j DNAT --to-destination xxx.xxx.xxx.xxx:80

 

Tell IPtables to masquerade:

# iptables -t nat -A POSTROUTING -j MASQUERADE



blog comments powered by Disqus