IPTables

From Bashlinux
Revision as of 22:04, 11 June 2015 by Manpaz (talk | contribs) (Created page with "__NOTOC__ === Howto setup iptables on CentOS/Fedora === Rules are always read from <tt>/etc/sysconfig/iptables</tt>, but if any "save" option is enable in <tt>/etc/sysconfig/i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Howto setup iptables on CentOS/Fedora

Rules are always read from /etc/sysconfig/iptables, but if any "save" option is enable in /etc/sysconfig/iptables, the rules added from the command line are keep in memory, but won't be available on system reboot.

It happens in Fedora that rules in /etc/sysconfig/iptables are overridden until iptables daemon is restarted.

To make the system load our rules on reboot and every time, you must ensure the rules that /etc/iptables.rules file does exist, an has the rules you just created.

How to setup a gateway with 2 Virtual NICs on GNU/Debian

For any given host with 2 virtual NICs (IP aliases)

  • WAN = eth0 -> 10.11.12.10
  • LAN = eth0:1 -> 192.168.10.10

The steps to setup the host as gateway are

  • Add to iptables the proper nat rules in order to ensure SNAT traffic pass through the "Out to the world" NIC.
*nat
:PREROUTING ACCEPT [891:110412]
:POSTROUTING ACCEPT [92:11129]
:OUTPUT ACCEPT [241:27547]
-A POSTROUTING -o eth0 -j MASQUERADE 
-A POSTROUTING -o eth0 -j SNAT --to-source 10.11.12.10
COMMIT
  • Because both network IPs are in the same NIC, then add to the filter section a forward in both directions:
-A FORWARD -i eth0 -j ACCEPT 
-A FORWARD -o eth0 -j ACCEPT
  • Ensure ip4 traffic is being forwarded on kernel enabling it on /etc/sysctl
net.ipv4.ip_forward = 1
  • Load the previous modification:
sysctl -p