Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to redirect connections made inside a linux host to a guest VM, say 192.168.122.158, for a certain port range, say 8000:8500, i.e.:

telnet localhost 8000

should actually result in a connection to the VM. I can easily redirect connections from outside machines with:

iptables -t nat -I PREROUTING -p tcp --dport 8000:8500 -j DNAT --to 192.168.122.158

But from what I can gather traffic originating on the host machine does not go through the PREROUTING chain. I have tried to use the OUTPUT chain instead with:

iptables -t nat -I OUTPUT -p tcp --dport 8000:8500 -j DNAT --to 192.168.122.158

This does not seem to work. I ran a wireshark capture on all interfaces and when this rule is in place no traffic is generated for port 8000.

I was hoping to use iptables for this but I have not been able to make it work. I am considering using redir but I was hoping there is an iptables solution.

share|improve this question
    
Does that happen if you had any connection (ping would be enough) to 192.168.122.158 immediately before, too? I tried to reproduce this here and had ARP problems. Does it work for telnet $eth_ip 8000? –  Hauke Laging May 12 '13 at 22:11
    
telnet $eth_ip 8000 does work but not telnet localhost 8000 –  samwise May 12 '13 at 22:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.