10 Comments

  1. Remember to enable forwarding in the FORWARD chain:

    # iptables -I FORWARD -j ACCEPT

    more strict rules are also suggested.

  2. Another option for configuring iptables:

    # iptables -I FORWARD -j ACCEPT
    # iptables -t nat -I POSTROUTING –out-interface eth1 -j MASQUERADE

  3. Instead of using SNAT, another way is to use MASQUERADE:

    # iptables -t nat -A POSTROUTING ! -d 192.168.0.0/16 -o eth1 -j MASQUERADE

    However, for static IPs, SNAT is suggested as from the iptables man page ( https://www.systutorials.com/docs/linux/man/8-iptables/ ):

    This target is only valid in the nat table, in the POSTROUTING chain. It should only be used with dynamically assigned IP (dialup) connections: if you have a static IP address, you should use the SNAT target. Masquerading is equivalent to specifying a mapping to the IP address of the interface the packet is going out, but also has the effect that connections are forgotten when the interface goes down. This is the correct behavior when the next dialup is unlikely to have the same interface address (and hence any established connections are lost anyway).

    Some other discussion on the Web:

    http://lists.debian.org/debian-firewall/2002/02/msg00020.html

  4. I guess “sysctl -w net.ipv4.ip.forward=1” should be “sysctl -w net.ipv4.ip_forward=1” with the underscore ;-)

  5. Please don’t use random IP addresses for examples. If you need an example IP address, you should review RFC5735 and look for “TEST-NET”

Leave a Reply

Your email address will not be published. Required fields are marked *