Append vs Insert
Before I answer the question, let's look at the structure of the command:
iptables -A INPUT 'the rule'
-Append at the end of the
INPUT chain the following rule. The other common way to add a rule to
iptables is by the insert option:
iptables -I INPUT 'the rule'
-Iinsert at the beginning of the
INPUT chain the following rule. Or when we want to insert the rule at certain place, for example before some existing rule that is number 3 in the chain:
iptables -I INPUT 3 'the rule'
The Numbers of the Rules
The numbers of the rules play significant role in
ipchain). As illustration - let's say we have the following structure of rules:
1. Deny all UDP
2. Allow UDP on port 456
The UDP shouldn't be allowed on port 456, because it is already denied for all ports, so the structure must be:
1. Allow UDP on port 456
2. Deny all (rest) UDP
If you want to read the structure of the chain
sudo iptables -S INPUT
If you need to get the numbers of the rules, then you can use the command:
sudo iptables -L INPUT -n --line-numbers # you can omit '-n'
In order to delete some rule from a known chain, you can use the command:
iptables -D CHAIN_NAME 'the rule'
CHAIN_NAME the following rule. Or in your case the command should be:
sudo iptables -D INPUT -p tcp --dport 5000 -m state --state NEW -j ACCEPT
Also, you can delete the rule by its number within the chain, let's say it is number 3:
sudo iptables -D INPUT 3
I'm sharing the opinion that, the tool Uncomplicated firewall -
ufw, that is front-end of
iptables, - sometimes can make the things much more complicated as they actally are :)
Here is a good article, provided by DigitalOcean, that describes the same as this answer, but in more details: How To List and Delete Iptables Firewall Rules.