sky_cheng

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

一、安装ipset

yum install ipset -y

二、禁止firewalld

systemctl stop firewalld
systemctl disable firewalld

三、设置iptables默认允许规则

iptables -P INPUT ACCEPT

四、清空其他规则

[root@hlcc ~]# iptables -F

五、查看规则

复制代码
[root@hlcc ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 
复制代码

六、创建cnip规则

ipset -N cnip hash:net

七、下载国内IP地址段文件

mkdir -p /root/cnip
cd /root/cnip/
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone

八、将IP段添加到cnip规则中

for i in $(cat cn.zone ); do ipset -A cnip $i; done

九、查看数据

ipset list | wc -l

十、允许cnip里的IP段访问

iptables -A INPUT -m set --match-set cnip src -j ACCEPT

十一、允许局域网地址访问

[root@hlcc ipset]# ipset -A cnip 10.0.0.0/8
[root@hlcc ipset]# ipset -A cnip 172.0.0.0/8
[root@hlcc ipset]# ipset -A cnip 192.168.0.0/16

十二、设置默认规则为禁止

iptables -P INPUT DROP
复制代码
[root@hlcc ~]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             match-set cnip src

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination       
复制代码

 

 

posted on   sky_cheng  阅读(768)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示