Ubuntu – reload iptables rules during boot

Steps to load iptable rules automatically on Ubuntu Linux using package iptables-persistent.

  1. Install iptables-persistent
    $ sudo apt-get install iptables-persistent
    
  2. When asked during installation should it save current iptables to /etc/iptables/rules.v4 and /etc/iptables/rules.v6, enter yes.
    iptables-persistent-config-file-install-prompt

  3. 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 
    
  4. 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

  5. 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.

  6. On reboot /etc/init.d/iptables-persistent will load saved rules automatically.
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments