Menu Title

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

 

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.

$ sudo apt-get install iptables-persistent

After making changes in iptables,  use

$ sudo netfilter-persistent save 

You may also like...

Thank you for visiting us. To continue receiving updates, please Subscribe to our Social Media Channels.