krkr
4/16/2015 - 4:56 PM

IP forwarding to update DNS without downtime with iptables rules \o/

IP forwarding to update DNS without downtime with iptables rules \o/

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

PORT=$1
IP=$2

sudo iptables -t nat -A PREROUTING -p tcp --dport $PORT -j DNAT --to-destination $IP
sudo iptables -t nat -A POSTROUTING -p tcp -d $IP --dport $PORT -j MASQUERADE

# Example to find and delete rules using their number and chain name 
# sudo iptables -t nat --line-numbers -L
# sudo iptables -t nat -D PREROUTING 2
# sudo iptables -t nat -D POSTROUTING 2