8

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.

1 Answer 1

4

You will need that under nat

e.g

*nat
:PREROUTING ACCEPT
:POSTROUTING ACCEPT 
:OUTPUT ACCEPT

-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.

1
  • 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
    Commented Jul 6, 2014 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .