Tomcat: redirecting traffic from port 80 to 8080 using iptables

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

11 thoughts on “Tomcat: redirecting traffic from port 80 to 8080 using iptables

  1. 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.

    Like

  2. Pingback: Tomcat: redirecting traffic from port 8080 to 80 using iptables | G0dspeed's Blog

  3. 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”.

    Like

  4. 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.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s