How to open range of IP addresses on Linux server using Iptables
How to open range of IP addresses using Iptables
Allowing accesses to a single IP address is already explained in the previous article. Steps to allow access to multiple IP address is almost the same. Follow the below instructions to whitelist / Allow IP range in IPtables.
How to whitelist whole IP address range
Step 1: Log into Linux server via SSH as ‘root’ user
Step 2: Run the command “iptables -A INPUT -s 192.168.2.1/24 -j ACCEPT” to whitelist IP address range
Step 3: Run the command “service iptables save” to save the firewall rule that you have added
In the above example the whole IP address range will be whitelisted. Do the below steps if you want to whitelist only few IP address (Allow small range of IP addresses).
*The IP address range “192.168.2.1/24” in Step 2, should be replaced with the IP address you wish to allow.
Examples :
To whitelist /16 range :
iptables -A INPUT -s 192.168.2.1/16 -j ACCEPT
To whitelist /28 range :
iptables -A INPUT -s 192.168.2.1/28 -j ACCEPT
How to whitelist a range of IP’s in Iptables Firewall without specifying CIDR
Step 1: Log into Linux server via SSH as ‘root’ user
Step 2: Run the command “iptables -A INPUT -m iprange –src-range 192.168.2.1-192.168.2.9 -j ACCEPT” to whitelist IP range
Step 3: You must save the IPtables rules by running the command “service iptables save”
In the above example, you must change the IP address range in Step 2 with the IP range that you wish to allow.
Type the command “iptables -nL” to see the IPtables rules that you have added.