All of the port forwarding examples I can find are for NAT, which is not what I want. We have an HTTP server application that only binds to 1 port at a time. However, we need to bind to an additional port to get around a silly corporate firewall. For example, if my http server is listening on 1234, how do we forward 4321 to this port also? The server is debian, and I believe we can use iptables to accomplish this.
1 Answer
Well, I guess it's simply to write a DNAT rule:
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d xxx.xxx.xxx.xxx
--dport 4321 -j DNAT --to 127.0.0.1:1234
As it's in the prerouting chain it should work without interference from the routing. But it seems like an awfully complicated way to solve the problem.
Instead, why don't you simply tell your HTTP server to bind to both ports? As you are on Debian I assume you use Apache. Then it's just adding two Listen directives in the httpd.conf:
Listen 1234
Listen 4321
Note that serving the same content on both ports won't work, as you will have to change all URL's depending on the port the users are connecting on, or all links will be broken...
-
2You could also use a rule like
/sbin/iptables -t nat -A PREROUTING -p tcp --dport 4321 -j REDIRECT --to-ports 1234
. Jun 27, 2010 at 22:40
/etc/sysctrl
:net.ipv4.ip_forward=1
andnet.ipv6.conf.all.forwarding=1