Configure iptables to forward subnets data on Linux

  • source: 192.168.1.0/24
  • destination: 172.16.1.0/24
  • policy: SNAT
iptables -A FORWARD -s 192.168.1.0/24 -d 172.16.1.1/24 -j ACCEPT
iptables -A FORWARD -s 172.16.1.0/24 -d 192.168.1.0/24 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 172.16.1.0/24 -j MASQUERADE

Linux PC can forwarding data as a router when you configure iptables with above.

Leave a Reply