Redirect port 80 to port 8080 on linux server

When you installed an application server on a linux server, the port number can be any numbers depending on the application. For example, the tomcat server is using 8080 as the default port number. By default, http and https are using port 80 and port 443 respectively. If you are running a website on the tomcat server, then you will want to use port 80 instead because browsers connect to a web server through port 80 by default unless you specifiy a port number at the end of the domain ( To respond with the website application on port 8080 for incoming requests to port 80, a redirection of the incoming request is needed. The command line tool iptables does what we needed here for redirection. Here are 3 iptables commands, the first and the second are to configure the machine to accept incoming connections to port 80 and port 8080 respectively, the third one will redirect incomming requests from port 80 to port 8080.

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

Search within Codexpedia

Custom Search

Search the entire web

Custom Search