IPTables Commands

Comments Off on IPTables Commands

1. Iptables Status

$ service iptables status

$ service iptables start


2. List current iptables rules

$ iptables -L


3. Add an incoming rule

$ iptables -A INPUT -p tcp –dport 8080 -j ACCEPT        //Append this rule to iptables

$ iptables -I INPUT -p tcp –dport 8080 -j ACCEPT         //Add this rule to top of existing rules


4. Remove existing rule

$ iptables -D INPUT -p tcp –dport 8080 -j ACCEPT


All in One WordPress Hosting Starts at 30$ per month
All in One WordPress Hosting
High optimized WordPress hosting, secure firewall, HTTPS, Backup, hack-fix guarantee and many others at 30$ per month

5. Save rule changes

Any changes made to iptables are lost after reboot, unless you manually save to persist.

Option 1:

$ iptables-save > /root/iptable_rules

Edit /etc/rc.local and add following entry to restore iptable rules after reboot

$ iptables-restore < /root/iptable_rules


Option 2:

The easiest way is to install and use the iptables-persistent package. In order to make this package work, rules must be stored in /etc/iptables/rules.v4 for IPv4 and /etc/iptables/rules.v6 for IPv6.

$ sudo apt-get install iptables-persistent

After making changes in iptables,  use

$ sudo netfilter-persistent save 

Please check that your rules are loaded as desired following the first reboot after configuration.

Menu Title