iptables example rulesets

Example rulesets

Simpler rulesets are at the start, with more complex scripts near the end. All rulesets are in iptables-save format and I discuss their use below.

Empty Script

Single host

Normal router

NAT Router

Bridge Router

Abnormal setups

Use of the recent module

Information

Tutorials

Papers

Diagrams

Rulesets

These rulesets are in iptables-save format. I have written some simple documentation of the iptables-save format. I use this format for several reasons: it ensures there are no other rules in iptables, it loads faster, it avoids the possibility of a race condition that most iptables scripts have (although the race window would be about 1ms for most rulesets).

There are several ways to use these rulesets.

For the best security, a firewall should be applied before the internet-facing interface is brought up. If you have a dynamic IP and need to use it in your ruleset, consider loading a simple deny-all firewall (remember to allow DHCP) before bringing up the interface, then switching to the real firewall after the you get an IP.

Related scripts

References

The iptables 1.3.6 manpage, which has a full syntax description and covers all the modules.

Netfilter, the official iptables/netfilter website.

Ask in the freenode IRC channel #iptables for more information, or for any other reason. I'm usually in there as danieldg. If you have any other examples, send them to me and I'll put them up on this page.

Last modified Thu May 3 21:05:24 2007. ©2005-2007 Daniel De Graaf