Friday, November 30, 2012

How to redirect incoming TCP connections to other ports (Example : 80 to 8080)


 Hello Everybody,

Today, I will show you how I solved a problem which occurred when I started setting a java web application in a production server.
We all now that Apache Tomcat Server uses the 8080 port by default. So we have to add ":8080" every time to reach the application.

The solution is to replace the 8080 port by 80. There are two ways: 

  1. Configuring Apache Tomcat
  2. Redirect incoming TCP connections from 80 port to the 8080 one.
Below the command to redirect the incoming tcp connections :

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

I have no idea which is the best way to resolve such problem ( I think the first option is the cleanest). However, this method is the quickest because it saves you some minutes.

Good bye :-)