Remove Entry From Iptables

Jul 23, 2018

Add entry with -A

sudo iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

Remove an entry with -D

sudo iptables -D INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

You can list all rules by line number

sudo iptables -L INPUT --line-numbers
Chain INPUT (policy DROP)
num  target     prot opt source               destination         
1    ACCEPT     all  --  anywhere             anywhere            
2    ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
3    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
4    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
5    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql
6    DROP       all  --  anywhere             anywhere            
7    ufw-before-logging-input  all  --  anywhere             anywhere            
8    ufw-before-input  all  --  anywhere             anywhere            
9    ufw-after-input  all  --  anywhere             anywhere            
10   ufw-after-logging-input  all  --  anywhere             anywhere            
11   ufw-reject-input  all  --  anywhere             anywhere            
12   ufw-track-input  all  --  anywhere             anywhere 

Delete rule by number

sudo iptables -D INPUT 5

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.