Steps to load iptable rules automatically on Ubuntu Linux using package iptables-persistent.
- Install iptables-persistent
$ sudo apt-get install iptables-persistent
- When asked during installation should it save current iptables to /etc/iptables/rules.v4 and /etc/iptables/rules.v6, enter yes.
- In case you make any changes to iptables, run the following to persist these. Note that rules won’t get persisted automatically.
$ sudo /etc/init.d/iptables-persistent save
- Do a diff of changes made to ip tables with persisted values in /etc/iptables/rules.v4
$ sudo iptables-save > unsaved_rules $ diff unsaved_rules /etc/iptables/rules.v4
Similarly we can diff v6 rules using ip6tables-save
- To reload iptables rules (v4 and v6 both) using /etc/init.d/iptables-persistent
$ sudo /etc/init.d/iptables-persistent reload
Note that this will override current loaded rules in iptables.
- On reboot /etc/init.d/iptables-persistent will load saved rules automatically.