Iptables opening or closing ports Debian 10

Enabling Connections on HTTP, SSH, and SSL Ports

These iptables rules will open ports 80,443 and 22

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

Deleting Rules

This command erases all current rules

iptables -F

However, to delete a specific rule, you must use the -D option. First, you need to see all the available rules by entering the following command:

iptables -L --line-numbers

You will get a list of rules with numbers,for example:-

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     all -- 192.168.0.4          anywhere
2    ACCEPT     tcp -- anywhere             anywhere tcp dpt:https
3    ACCEPT     tcp -- anywhere             anywhere tcp dpt:http
4    ACCEPT     tcp -- anywhere             anywhere tcp dpt:ssh

To delete a rule, insert the corresponding chain and the number from the list. Let’s say for this iptables tutorial, we want to get rid of rule number three of the INPUT chain. The command should be:

iptables -D INPUT 3

Leave a Comment

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