Search code examples
iptablessubnet

How to allow only IPs ending with a specific number in IPTABLES?


I want to allow only the ips that end with number 1 and number 250. X can be any number from 1 to 255.

192.168.X.1 y 192.168.X.250

I'm not sure if IPTABLES has a specific command for this or if it is a subnetting problem.


Solution

  • You can allow an ip subnet or ip range. For your question you can write an bash script:

    for ((i=1;i<=255;i++)); do
        iptables -I INPUT -m iprange --src-range 192.168.$i.1-192.168.$i.250 -j ACCEPT
    
    done