Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Forward all incoming packets through a certain port

In this example all incoming traffic on port 80 redirect to port 8123

...

Code Block
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 63001 -j DNAT --to-destination 10.0.3.10:3306
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 64001 -j DNAT --to-destination 10.0.3.10:6379
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 63101 -j DNAT --to-destination 10.0.3.20:3306
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 64101 -j DNAT --to-destination 10.0.3.20:6379
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 60050 -j DNAT --to-destination 10.0.3.50:5044
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE



Show all the list in the iptables

Code Block
sudo iptables -S

...

Code Block
sudo iptables -t nat -L --line-numbers



Delete all existing rules

Code Block
sudo iptables -F



Save the existing iptable settings

Code Block
/etc/init.d/iptables save