centos服务器如何通过iptables封禁和解封指定的ip和ip段

0 centos服务器如何通过iptables封禁和解封指定的ip和ip段

iptables封禁和解封单个ip的方法:

封禁命令:  iptables -I INPUT -s IP -j DROP

例子:

[root@node1 ~]# iptables -I INPUT -s 192.168.1.11 -j DROP
[root@node1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  192.168.1.11         anywhere

解封命令:iptables -D INPUT -s IP -d IP -j ACCEPT

例子:

[root@node1 ~]# iptables -D INPUT -s 192.168.1.11 -j DROP  # 解封IP: 192.168.1.11
[root@node1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

iptables封禁和解封ip段的方法:

封IP段: 从123.0.0.1到123.255.255.254的命令
[root@node1 ~]# iptables -I INPUT -s 123.0.0.0/8 -j DROP
[root@node1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
 
DROP       all  --  123.0.0.0/8          anywhere

封IP段: 从123.45.0.1到123.45.255.254的命令

[root@node1 ~]# iptables -I INPUT -s 123.45.0.0/16 -j DROP
[root@node1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  123.45.0.0/16        anywhere
DROP       all  --  123.0.0.0/8          anywhere

封IP段:从123.45.6.1到123.45.6.254的命令是

[root@node1 ~]# iptables -I INPUT -s 123.45.6.0/24 -j DROP
[root@node1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  123.45.6.0/24        anywhere
DROP       all  --  123.45.0.0/16        anywhere
DROP       all  --  123.0.0.0/8          anywhere

全部清理方法:

[root@node1 ~]# iptables -F

查询命令:

[root@node1 ~]# iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
[root@node1 ~]#
赞(1)
打赏 微信扫一扫微信 支付宝 QQ 扫码打赏
如若转载,请注明本文出自:https://www.guaitoo.com/show/195.html