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.