Iptables
Managing traffic: iptables and ip6tables
iptables is used to manage IPv4. ip6tables is used to manage IPv6.
Using iptables rules
Ubuntu recommends using ufw to easily manage iptables rules.
- View current rules:
iptables -L - Rules are applied in order
- One a rule
ACCEPTs orDROPs a packet, no further rules are applied
- One a rule
- Three
chains:INPUT,FORWARD,OUTPUT
Saving & Restoring iptables rules
iptables-savedumps the current iptables to stdout.iptables-restoreflushes iptables and restores aiptables-savedump.- Procedure
- When your
iptablesis correct, run as root:$ iptables-save > dump.iptables - To flush
iptablesand reload, run as root:$ iptables-restore < dump.iptables
- When your
- There are additional options to maintain packet/byte counters, skip flushing, or save only one table by name.
Permanently modifying iptables in a debian/ubuntu system
By default, iptables is only stored in memory. Management tools exist for iptables including ufw and the iptables service.
iptablesinitial ruleset comes from/etc/network/interfaces(may be/etc/sysconfig/iptables)
Resources
- help.ubuntu.com IptablesHowTo
- nixCraft: How Do I Save Iptables Rules and Settings?
- askubuntu managing iptables with ip6tables
- manpages:
iptables,iptables-save,iptables-restore