Menu Title

IPTables Commands

0 0
Read Time:44 Second

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

$ sudo apt-get install iptables-persistent

After making changes in iptables,  use

$ sudo netfilter-persistent save 

Related Post

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *