Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I add the following iptables rules:

iptables -A INPUT -p tcp -s localhost --dport 4444 -j ACCEPT
iptables -A INPUT -p tcp --dport 4444 -j DROP

This allows localhost to access port 4444 then blocks all other IPs from accessing port 4444...

I now want to undo these previous iptables commands. What is the easiest way to "undo" that? e.g. allow all ips to access port 4444 again.

share|improve this question

migrated from serverfault.com Aug 19 '13 at 21:51

This question came from our site for system and network administrators.

man iptables is your friend – Marki Aug 17 '13 at 17:24

From iptables --help:

--delete  -D chain      Delete matching rule from chain
--delete  -D chain rulenum
                Delete rule rulenum (1 = first) from chain

So, just issue:

iptables -D INPUT -p tcp -s localhost --dport 4444 -j ACCEPT
iptables -D INPUT -p tcp --dport 4444 -j DROP

Alternatively, you can delete by line numbers. First, get the line numbers of your rules:

iptables -L INPUT -n --line-numbers

Then, delete:

iptables -D INPUT <line_number>
share|improve this answer
oh wow. so just the same command, switching -A to -D. Didn't expect it to be so intuitive. thanks! – tester Aug 17 '13 at 16:44
It's amazing what happens when one reads the documentation. Hint, hint. :) – EEAA Aug 17 '13 at 16:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.