IPtables help needed. Simple port redirect

Permabanned
Joined
13 Nov 2006
Posts
5,798
I cannot seem to find anywhere that describes how to do a simple port redirect on a linux box using iptables.

I don't want it going to another ip address, I just want the port to be locally redirected. I ended up with this which im not sure about...

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5000 -j REDIRECT --to-port 8000

Would this mean anything incoming on 5000 gets redirected to 8000 on the local machine? Is there anyway to check if this is working correct.

Please help. Thanks.
 
Last edited:
iptables -t nat -A PREROUTING -p tcp -m tcp -i eth0 --dport 5000 -j DNAT --to-destination 127.0.0.1:8000

Is probably more likely (or rather, that's the way i'd do it) you can use tcpdump -i lo port 8000 to see if localhost:8000 is getting packets when you access system:5000
 
Back
Top Bottom