Forwarding web traffic to a different server

Sometimes you need to forward traffic from an old server to a new server until the DNS changes propagate. In this case there are two very simple commands to execute that will allow you to do so.

Forward the traffic sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 123.333.112.153 Mask the traffic sudo iptables -t nat -A POSTROUTING -p tcp -d 123.333.112.153 --dport 80 -j MASQUERADE

If you want to delete the rules, simply replace the -A with -D

Comments are closed.