Linux - Port forwarding using iptables 80 to 8080, Forward apache request to tomcat

Port forwarding using iptables 80 to 8080

How to forward all the request from apache to tomcat?
How to do port forwarding using iptables?

The applicaton developers run both apache and apache tomcat on same machines, The tomcat runs on port 8080 and it is used to serve Servlets and JSP Pages. The Servlets and JSP pages are not good as serving static pages and images like php or html pages.

Unix Operating System:
Under UNIX all ports <1024 are "privileged" ports. Only root may open a priviledged port

For forwarding the port 80 to 8080, there are several ways, like using apache proxy module or using IPTABLES or IPCHAINS in linux os. Here we will see how to set forward the port using iptables

Save the existing iptable rules
 # /etc/init.d/iptables start
 # iptables-save > /etc/sysconfig/iptables

iptables rules to forward port 80 to 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

ipchain to open ssh or putty
 #iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT

Listing iptables rules
 # iptables -L -n -v
This will list all the iptables rules set on your linux machine, once you are sure then save the iptables and restart your iptables or linux firewall

Save the iptables rules and restart firewall
 # iptables-save > /etc/sysconfig/iptables

 # cat /etc/sysconfig/iptables

 # /etc/init.d/iptables restart
Follow the above steps to forward the port 80 to port 8080 using iptables.

The topic on Linux - Port forwarding using iptables 80 to 8080 is posted by - Guru

Hope you have enjoyed, Linux - Port forwarding using iptables 80 to 8080Thanks for your time

Tech Bluff