full of … these

Port forwarding for tomcat with iptables

Posted: June 14th, 2007 | Author: | Filed under: howto, linux | Tags: , , , , , , | No Comments »

Givens: one linux machine with one NIC but with two IPs on it, apache running on 80, tomcat on 8080

Needs: apache on port 80 using first IP, tomcat on second IP using port 80.

Easyest way: use iptables to forward all requests to second IP port 80 to first ip port 8080

iptables -t nat -A PREROUTING -p tcp -d second_ip --dport 80 -j REDIRECT --to-port 8080

Please note that the -i ethx was removed to bind to the default network adapter/first IP.

You may want to consider using apache in front of tomcat by using mod_jk, mod_proxy_ajp or ProxyPass.

Leave a Reply