To read a list of IP addresses from a file and block them using iptables
, you can use the -R
option to read the IP addresses from a file and the -A
option to append a rule to the INPUT
chain.
Here's an example of how to do this:
iptables -R INPUT < /path/to/ip_list.txt -j DROP
This will read the IP addresses from the file /path/to/ip_list.txt
and append a rule to the INPUT
chain that drops incoming connections from those IP addresses.
The ip_list.txt
file should contain a list of IP addresses, one per line. For example:
192.0.2.1 192.0.2.2 192.0.2.3
Note that the iptables
command is not persistent, so if you reboot your system or restart the iptables
service, your rules will be lost. To make the rules persistent, you can use the iptables-save
and iptables-restore
commands to save the current rules to a file and restore them on boot.
It's also worth noting that the iptables
command is deprecated in many modern Linux distributions in favor of the nftables
command. If you are using a recent version of Linux, you may want to consider using nftables
instead.