Port Forwarding (like DMZ)

Editor

Well-Known Member
Apr 26, 2017
108
1
58
Turkey
I wrote this to redirect all ports to a single machine, but I don't know if it is working properly. Is it possible to direct the entire port range to a single machine like DMZ Logic?

Code:
post-up iptables -t nat -A PREROUTING -p tcp --dport 0:8005 -j DNAT --to-destination 192.168.128.185:0-8005
post-down  iptables -t nat -D PREROUTING -p tcp --dport 0:8005 -j DNAT --to-destination 192.168.128.185:0-8005

post-up iptables -t nat -A PREROUTING -p tcp --dport 8007:65535 -j DNAT --to-destination 192.168.128.185:8007-65535
post-down  iptables -t nat -D PREROUTING -p tcp --dport 8007:65535 -j DNAT --to-destination 192.168.128.185:8007-65535
 
hi,

yes it's possible, the command looks good to me.

Code:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 0:8005 -j DNAT --to-destination 192.168.128.185:0-8005

if you're not sure it's working you can test it by opening a port on the machine and see if you can access it?
also make sure you have ip forwarding enabled on the host