Server Fault is a question and answer site for system and network administrators. 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

I need all the requests of 80 to be forwarded to 8020. I googled it up and i got it.

iptables -t nat -I PREROUTING --source 0/0 --destination 0/0 -p tcp --dport 80 -j REDIRECT --to-ports 8020

now in the furute if i had to undo it what do i do (apart from restarting the system)

Thanks in advance :)

share|improve this question
up vote 6 down vote accepted

Just delete the rule:

iptables -t nat -D PREROUTING --source 0/0 --destination 0/0 -p tcp --dport 80 -j REDIRECT --to-ports 8020
share|improve this answer
Thanks......... – raj Jul 12 '10 at 10:46

I find it a pain to completely reconstruct the iptable rule when I want to delete it. Instaed I list the rules with line numbers and then delete by number. For example:

iptables -t nat -L --line-numbers

Gives output like:

num  target     prot opt source               destination         
1    REDIRECT   tcp  --             tcp dpt:80 redir ports 8020 

Then to delete by number:

iptables -t nat -D PREROUTING 1

Caveat: When you delete a line, all the lines below will get a new line number. For example, if you had rules like:

1 rule A
2 rule B
3 rule C

and you delete rule 2, then you get:

1 rule A
2 rule C
share|improve this answer

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.