安装 ipset

https://lolico.moe

# Debian / Ubuntu
apt-get install -y ipset
# CentOS系统
yum install -y ipset

下载脚本

wget https://raw.githubusercontent.com/YKilin/Block-IPs-from-countries/master/block-ips.sh

使用

屏蔽某国IP
比如要屏蔽中国IP

  1. 添加中国IP到 ipset 添加的时候会自动下载一个IP段集delegated-apnic-latest.txt,请不要删除它
bash block-ips.sh -a cn
  1. 屏蔽中国IP
bash block-ips.sh -b cn
如果真的要试的话就别屏蔽中国IP了啊,小心屏蔽完了 ssh 上不去(。
你可以尝试拿邻国友人jp,kr,sg之类的开刀(x
你可以到 http://doc.chacuo.net/iso-3166-1 或者 https://www.iso.org/obp/ui/ 查看可用的国家代码(二字母),使用的时候大小写无所谓

解除屏蔽

如果要解封中国IP

bash block-ips.sh -u cn

查看你已经屏蔽了哪些国家

bash block-ips.sh -l

更新IP列表

如果你需要更新IP列表,你需要先删除delegated-apnic-latest.txt文件,然后再次使用-a参数添加即可,脚本会自动先清空原 ipset 然后重新添加数据

rm delegated-apnic-latest.txt
bash block-ips.sh -a cn

本文链接:https://www.hcyacg.com/projects/block-countries-ips.html

最后修改:2019 年 12 月 11 日
如果觉得我的文章对你有用,请随意赞赏