多个 ip 禁止,从文件 IP 中读取 -> iptables 中的禁止

use*_*638 3 linux iptables

我如何从文件中读出 IP 地址,然后在 iptables 中禁止。

88.123.xxx
123.456.xxx
65.234.xxx

cor*_*ump 10

简单、直接、单行的解决方案:

for IP in $(cat ip_list); do iptables -A INPUT -s $IP/32 -d 0/0 -j DROP; done
Run Code Online (Sandbox Code Playgroud)

这将阻止来自任何协议或端口上的 ip 地址的任何通信。

但也许您应该考虑使用iptables-saveiptables-restore甚至Shorewall来做一个适当的防火墙脚本。

编辑:同一行,详细:

for IP in $(cat ip_list); do echo "Banning $IP"; iptables -A INPUT -s $IP/32 -d 0/0 -j DROP; done
Run Code Online (Sandbox Code Playgroud)