I'd like to set up a TCP DNAT from 127.0.0.1, port 4242 to 220.127.116.11, port 5353 on Linux 3.x (currently 3.2.52, but I can upgrade if needed).
It looks like the simple DNAT rule setup doesn't work,
telnet 127.0.0.1 4242 hangs for a minute in
Trying 127.0.0.1..., and then it times out. Maybe it's because the kernel is discarding the returning packets (e.g. SYN+ACK), because it considers them Martian. I don't need an explanation why the simple solution doesn't work, I need a solution, even if it's complicated (e.g. it involves creating may rules).
I could set up a usual DNAT from another local IP address, outside the
127.0.0.0/8 network, but now I need 127.0.0.1 as the destination address. I know that I can set up a user-level port forwarding process, but now I need a solution which can be set up using
iptables and doesn't need helper processes.
I was googling for this for an hour. It was asked multiple times, but I couldn't find any working solutions.
Also there are many questions about DNAT to 127.0.0.1, but I don't need that, I need the opposite.
Please note that a single
iptables -j REDIRECT rule wouldn't work, because I need to change the IP address of the outgoing packet from 127.0.0.1 to 18.104.22.168, and
-j REDIRECT can't change the IP address.