Suppose I have a network with a server routing all connections from inside the network to the Internet. How can I set up iptables so that instead of routing incoming connections to the Internet, it instead routes them to localhost port 8080. All help is appreciated.
that can be done with
iptables, but only with kernel >= 3.6.
You will have to do:
sysctl -w net.ipv4.conf.all.route_localnet=1 iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 127.0.0.1:8080
ip_forward is not necessary, because the packet is not forwarded, but if you don't include the sysctl for
route_localnet (which works only in kernels >= 3.6), the packet will be dropped by the kernel because it considers it a "martian", coming from the outside and having a destination address of 127.0.0.1