Iptables防火墙icmp模块扩展匹配规则

Iptables防火墙icmp模块扩展匹配规则

在前面做icmp协议的DROP动作规则时,其他主机确实无法ping通本机了,但是本机也同样无法ping通别的主机,那是因为拒绝动作是在INPUT链完成的,ping是有请求和回应的,INPUT链已经把icmp协议拒绝了,无法回应,就导致本机也无法ping通其他主机。

icmp模块常用的参数:

  • --icmp-type:指定icmp协议的类型,icmp协议有请求和回应两种类型,其他主机ping本机属于请求类型,本机ping其他主机属于回应类型。
    • echo-request:请求类型,ID为8。
    • echo-reply:回应类型,ID为0。

可以在参数前面加!号表示去反。

案例:禁止其他主机ping本机,本机依旧可以ping其他主机。

1)编写防火墙规则

[root@jxl-1 ~]# iptables -t filter -I INPUT -p icmp --icmp-type "echo-request" -j DROP

2)查看设置的防火墙规则

[root@jxl-1 ~]# iptables -L -n -v --line-number 
Chain INPUT (policy ACCEPT 962 packets, 843K bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 945 packets, 1266K bytes)
num   pkts bytes target     prot opt in     out     source               destination

3)测试效果

其他主机无法ping通本机,本机依旧可以ping通其他主机。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44953658/article/details/125689848