一、IP归属地数据库中导出需要的地址段列表,并用netmask工具转换成掩码格式use strict;
my $arg;
open INPUT,"ip.txt";
while (){
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 (){
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