Port range forwarding using iptables

Ranged port forwarding has its uses. I want to port forward port number 1025 to 50000 from Machine A to Machine B’s 1025 to 50000. Here is how I did it with iptables.

Machine A:
Machine B:

All operations are done in Machine A.

iptables -A INPUT -p tcp -m multiport --dports 1025:50000 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -m tcp --dport 1025:50000 -j DNAT --to-destination
iptables -A FORWARD -d -i eth0 -p tcp -m tcp --dport 1024:50000 -j ACCEPT

If you use UDP, alter the above command to UDP and apply it again.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.