How to allow a range of IP's with IPTABLES?

Solution 1:

If you only want to allow a certain range of IP addresses inside of 10.50.0.0 (such as from 10.50.10.20 through 10.50.10.80) you can use the following command:

iptables -A INPUT -i eth1 -m iprange --src-range 10.50.10.20-10.50.10.80 -j ACCEPT

If you want to allow the entire range you can use this instead:

iptables -A INPUT -i eth1 -s 10.50.0.0/16 -j ACCEPT

See iptables man page and this question here on ServerFault: Whitelist allowed IPs (in/out) using iptables

Solution 2:

For a specific port, say 22:

iptables -A INPUT -p tcp  -m iprange --src-range  10.50.10.20-10.50.10.80  --dport 22  -j ACCEPT

Tags:

Iptables