How to route multiple IP addresses with IPTABLE command?

Hi,
We have a router and devices for testing. We route devices with below command

 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 -s 10.111.111.22 -j DNAT --to-destination 10.13.0.16:3128

where 10.111.111.22 is device IP. and 10.13.0.16 is our Linux box machine.
Likewise we are having 20 devices so 20 different IPs.

So, the issue is each time we need to copy paste above command with different device IP address.

My question is will someone please point me to command where I can have 5-6 device ip addresses together so, I can route 5-6 devices symultaniously?

I tried below but failed

iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 -s 10.111.111.22,10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128
 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 -source 10.111.111.22,10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128
 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 -source 10.111.111.22 10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128

Please help me in this case.

From man iptables:

So this will work if the ip's you want to add are contigous, so that they form a range.

So in your case

--src-range 10.111.111.22-10.111.111.23
1 Like

Hi Dude2cool,

Thanks for reply.
I tried

 
 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 --src-range 10.111.111.22-10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128
 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 --source-range 10.111.111.22-10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128
 
iptables -t nat -A PREROUTING -p tcp -d 0/0 --dport 80 --src-range 10.111.111.22 - 10.111.111.23 -j DNAT --to-destination 10.13.0.16:3128
 

but
unfortunately none of them are working.

Will you please suggest me if I am making any mistake or do you have any other command?

Thanks,
Dhruvak

So when you try this;

Do you get a usage error or does the command complete without any errors?

Hi,
That command run successfully. There was no error but it does not route any of the device IP to Linux box IP.