Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 2 down vote accepted

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

Incomming 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 at 21:19
add comment

Your Answer

 
discard

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.