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

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.

share|improve this question
    
So…you have an HTTP server listening on port 1234…why not just have the server listen on port 4321 as well? I’m confused what you’re trying to do i guess…if the firewall (and by extension, NAT) isn’t the problem, then can you explain a little more? –  peelman Jun 27 '10 at 16:59
    
Make sure you have IP forwarding enabled in /etc/sysctrl : net.ipv4.ip_forward=1 and net.ipv6.conf.all.forwarding=1 –  wag2639 Jun 27 '10 at 18:19

1 Answer 1

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...

share|improve this answer
1  
You could also use a rule like /sbin/iptables -t nat -A PREROUTING -p tcp --dport 4321 -j REDIRECT --to-ports 1234. –  Zoredache Jun 27 '10 at 22:40

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.