一、IP归属地数据库中导出需要的地址段列表,并用netmask工具转换成掩码格式
use strict; my $arg; open INPUT,"ip.txt"; while (<INPUT>){ my $line=$_; chomp $line; my @line=split /\t/,$line; $arg.="$line[0]:$line[1] "; } system ("netmask $arg"); close INPUT;
二、安装ipset
三、建立access白名单
ipset create access hash:net
四、导入IP地址
use strict; open INPUT,"output.txt"; while (<INPUT>){ my $line=$_; chomp $line; system ("ipset add access $line"); } close INPUT;
五、设置iptables规则
iptables -A INPUT -m set --match-set access src -p udp --destination-port 53 -j ACCEPT iptables -A INPUT -p udp --destination-port 53 -j DROP
转载于:https://blog.51cto.com/417722381/1971479