Redirect to a different port using IPTABLES

Unless you want to run gitit as root you can’t use port 80 which is the default port for http traffic. For example typing richardfergie.com into firefox will send the http request to port 80 on this server. If gitit isn’t running on port 80 you would need to type something like richardfergie.com:8080 to send your request to port 8080.

Obviously this is a bit of a ballache for users. Rather than run gitit as root you can specify an iptables rule to direct incoming tcp requests on port 80 to port 8080. Assuming you have iptables installed the command you need is:

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

This will redirect traffic on all interfaces so if you’re doing some other stuff with the local loopback that might break. You can also specify an interface in the rule as follows:

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

This will only do the redirect for traffic on the eth0 interface.