Doing a simple port forwarding is actually a simple task:
|
|
This would redirect all traffic from 80
to 8080
. But if you have some firewall activated, you’ll have to allow both ports:
|
|
Otherwise the port forwarding won’t work. But this is not the use case you want to achieve. In most cases you want to redirect
traffic from one port (let’s say 80
) from an external interface to another IP address (let’s say 10.0.0.1:8080
). Using DNAT this
actually pretty easy to implement:
|
|
For a full example have a look at this stackoverflow. However in my case I wanted to do DNAT to the loopback interface which didn’t work (this answer confirms this). Using REDIRECT is also a pretty bad idea since I had to allow access to both ports (which is kind of stupid).
So… How to solve the problem? Using inetd. I’ve installed rinetd and configured the port forwarding:
|
|
I hope this would prevent others from spending their whole day on doing DNAT to localhost.