Port-based Redirect
assuming 10.2.3.4 is the ip of the box we are redirecting to and 10.2.3.5 is the ip of the box handling the redirect. Forwarding port 3306
echo "1" > /proc/sys/net/ipv4/ip_forward iptables -P FORWARD ACCEPT iptables -A FORWARD -i eth0 -p tcp --dport 3306 -j ACCEPT iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3306 -j DNAT --to-destination 10.2.3.4:3306 iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 10.2.3.5
To undo this
iptables -D FORWARD -i eth0 -p tcp --dport 3306 -j ACCEPT iptables -t nat -D PREROUTING -p tcp -i eth0 --dport 3306 -j DNAT --to-destination 10.2.3.4:3306 iptables -t nat -D POSTROUTING -o eth0 -j SNAT --to-source 10.2.3.5