Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I connect thought tunnel to other machine like this: ssh user@ip -L2000:192.168.64.88:80

So on my local machine I want to configure iptables that way like I have a "native" access to 192.168.64.88 address. I mean when I enter on web browser http:// 192.168.64.88 iptables will redirect to my localhost port 2000 which is connected to remote machine.

How can I configure iptables to redirect from 192.168.64.88 port 80 to localhost port 2000?

I tried this but with no luck:

sudo iptables -t nat -A PREROUTING -p tcp -d 192.168.64.88 --dport 80 -j DNAT --to-destination 127.0.0.1:2000

On mac os x machine I do it like this:

sudo ifconfig lo0 192.168.64.88 alias
sudo ipfw add fwd 127.0.0.1,2000 tcp from me to 192.168.64.88 dst-port 80

But I don't know how to do this on linux machine.

share|improve this question
    
related serverfault.com/questions/140622/… –  tair Mar 17 '13 at 11:33
    
I guess I miss something like "alias" –  Yoldar-Zi Mar 18 '13 at 4:40

1 Answer 1

iptables -t nat -I PREROUTING -p tcp -d 192.168.64.88 --dport 80 -j DNAT --to-destination 127.0.0.1:2000

IE your command was pretty much correct. I'm guessing another rule is being matched first so this rule is never being hit. Using -I instead of -A puts this rule at the beginning rather then end of the table.

share|improve this answer

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.