0%

设置特定国家和地区的防火墙白名单

用以允许特定国家访问服务器以及服务,达到锁定区域的目的

部署方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apt-get -y install ipset #Ubuntu系统安装ipset
yum -y install ipset #CentOS系统安装ipset
-----
iptables -P INPUT ACCEPT #安全清空防火墙规则以防止清空后无法访问服务器以及部署过程中发生冲突
iptables -F
-----
ipset -N cndz hash:net #创建一个名为cndz的规则
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone #下载IP段
for i in $(cat /root/cn.zone ); do ipset -A cndz $i; done #将IP段添加到cndz规则中
-----
iptables -A INPUT -p tcp -m set --match-set cndz src -j ACCEPT #设置白名单IP段
-----
iptables -P INPUT DROP #对白名单外国家关闭所有端口
iptables -A INPUT -p tcp --dport 80 -j DROP #对白名单外国家关闭80端口

备注

获取特定地区IP段:http://www.ipdeny.com/ipblocks/

CentOS关闭firewall防火墙

1
2
systemctl stop firewalld.service
systemctl disable firewalld.service

Welcome to my other publishing channels