October 6, 2015

Forward traffic from one IP address to another

The first thing to do is do enable IP forwarding. This is done either by using:
 echo "1" > /proc/sys/net/ipv4/ip_forward
 sysctl net.ipv4.ip_forward=1

Then, we will add a rule telling to forward the traffic on port 1111 to ip on port 1111:
 iptables -t nat -A PREROUTING -p tcp --dport 1111 -j DNAT --to-destination

and finally, we ask Iptables to masquerade:

iptables -t nat -A POSTROUTING -j MASQUERADE

No comments:

Post a Comment