DEV_WAN="eth0" DEV_LAN="eth1" IP_WAN="10.0.0.1" LAN="192.168.1.0/24" for prt in tcp udp; do for ((k=1;k<9;k++)); do iptables -t nat -I PREROUTING -i $DEV_WAN -p $prt -d $IP_WAN \ --dport 3600$k -j DNAT --to-destination 192.168.1.$k:3600$k iptables -t nat -A POSTROUTING -o $DEV_LAN -p $prt -s $LAN -d 192.168.1.$k \ --dport 3600$k -j SNAT --to $IP_WAN iptables -t nat -I PREROUTING -i $DEV_LAN -p $prt -d $IP_WAN \ --dport 3600$k -j DNAT --to-destination 192.168.1.$k:3600$k done for ((l=10;l<99;l++)); do iptables -t nat -I PREROUTING -i $DEV_WAN -p $prt -d $IP_WAN \ --dport 360$l -j DNAT --to-destination 192.168.1.$l:360$l iptables -t nat -A POSTROUTING -o $DEV_LAN -p $prt -s $LAN -d 192.168.1.$l \ --dport 360$l -j SNAT --to $IP_WAN iptables -t nat -I PREROUTING -i $DEV_LAN -p $prt -d $IP_WAN \ --dport 360$l -j DNAT --to-destination 192.168.1.$l:360$l done iptables -t nat -I PREROUTING -i $DEV_WAN -p $prt -d $IP_WAN \ --dport 36100 -j DNAT --to-destination 192.168.1.100:36100 iptables -t nat -A POSTROUTING -o $DEV_LAN -p $prt -s $LAN -d 192.168.1.100 \ --dport 36100 -j SNAT --to $IP_WAN iptables -t nat -I PREROUTING -i $DEV_LAN -p $prt -d $IP_WAN \ --dport 36100 -j DNAT --to-destination 192.168.1.100:36100 done