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
ACCEPT
s orDROP
s a packet, no further rules are applied
- One a rule
- Three
chain
s:INPUT
,FORWARD
,OUTPUT
Saving & Restoring iptables rules
iptables-save
dumps the current iptables to stdout.iptables-restore
flushes iptables and restores aiptables-save
dump.- Procedure
- When your
iptables
is correct, run as root:$ iptables-save > dump.iptables
- To flush
iptables
and 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.
iptables
initial 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