Forwarding Ports in Subnets

Redirect traffic using iptables

Activate masquerading

We need to activate masquerading for outgoing traffic.

iptables -t nat -A POSTROUTING -j MASQUERADE

Forward ports

The following command redirects incoming TCP traffic on port 80 to port 8080 on the destination host with the IP

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT \

Forward IP adresses

We can also forward all traffic with a specific IP adress as its destination. For example, this command redirects all incoming traffic for the IP adress to

iptables -t nat -A PREROUTING -p tcp --destination -j DNAT \