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

I am trying to forward all outgoing traffic from port 80 to port 8080 using iptables and I tried the following rule, though it did not work:

iptables -t nat -A OUTPUT -p tcp --dport 80 -j  REDIRECT --to-port 8080

Also, for incoming traffic I need a rule that forward port on the same host not to be as proxy.

share|improve this question
up vote 4 down vote accepted

You will need that under nat



-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080

you can run this: with example of forwarding 80 to 8080 and so on...

Incoming on 80 to 8080

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080

Outgoing on 80 to 8080

iptables -t nat -A POSTROUTING -p tcp --dport 80 -j SNAT --to-ports 8080

Note: I haven't tested this.

share|improve this answer
thank u i found this rule and it worked iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination :8080 – dana.ba Jul 6 '14 at 21:19

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.