First verify that Tomcat is running on port 8080. Run the following command
# netstat -ntl
The output will look something like
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN
tcp 0 0 :::8009 :::* LISTEN
tcp 0 0 :::8080 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
Run the following command to redirect port 80 traffic to port 8080
# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Run the folloing command to verify that redirect is working fine
# iptables -t nat -L
The output will look something like
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Run the following command to remove the routing
# iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Advertisements

wow , You’ve just mastered that
LikeLike
Reblogged this on TechCentral.
LikeLike
Amazing! Its actually remarkable post, I have got much clear idea about from this piece of writing.
LikeLike
I loved up to you’ll obtain performed proper here. The sketch is tasteful, your authored material stylish. nevertheless, you command get bought an impatience over that you want be delivering the following. unwell definitely come more earlier again as exactly the similar just about very continuously inside case you protect this hike.
LikeLike
Pingback: Tomcat: redirecting traffic from port 8080 to 80 using iptables | G0dspeed's Blog
Great post, thanks.
LikeLike
For someone who doesnt know IP table commands, this post is confusing. The title of the post says “redirecting traffic from port 8080 to 80 using iptables” but the text in the article says “Run the following command to redirect port 80 traffic to port 8080”.
LikeLike
Works great, thanks.
LikeLike
awesome and so easy ! thanks a lot
LikeLike
As i did the same as above for squid port 3128. but it’s not working. what is left ..?
i don;t want to set client’s browser’s settings for my proxy server.
LikeLike
As i did the same as above for squid port 3128. but it’s not working. what is left ..?
LikeLike