首先去 http://www.ipdeny.com/ipblocks/ 下载对应的国家IP地址端
写个脚本循环导入即可。
!/bin/bash
Block traffic from a specific country
written by vpsee.com
COUNTRY = “cn”
IPTABLES = /sbin/iptables
EGREP = /bin/egrep
if [ “$(id -u)” != “0” ]; then
echo “you must be root” 1>&2
exit 1
fi
resetrules() {
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -X
}
resetrules
for c in $COUNTRY
do
country_file = $c.zone
IPS = $($EGREP -v “^#|^$” $country_file)
for ip in $IPS
do
echo “blocking $ip”
$IPTABLES -A INPUT -s $ip -j DROP
done
done
exit 0
相关日志Linux ar 命令
Linux NAT ip_conntrack: table full
Could not open device at /dev/ipmi0
rndc-confgen 没有反应
/dev/random 与 /dev/urandom
转载请注明:爱开源 » 用 iptables 屏蔽来自某个国家的 IP