大网数据广告活动
服务器运维问答

Block ICMP unreachable outgoing packets

· 52CE 我爱测

I am trying out iptables rules to block following traffic; which is a response for unreachable host. 17:50:11.140992 IP 10.1.1.93 > 72.21.91.29: ICMP host 10.1.1.93 unreachable, length 48 17:50:11.140997 IP 10.1.1.93 > 72.21.91.2…

问题原文

原帖链接 · soap · CC BY-SA 4.0

I am trying out iptables rules to block following traffic; which is a response for unreachable host.

17:50:11.140992 IP 10.1.1.93 > 72.21.91.29: ICMP host 10.1.1.93 unreachable, length 48
17:50:11.140997 IP 10.1.1.93 > 72.21.91.29: ICMP host 10.1.1.93 unreachable, length 48

I added following rule

[admin@user ~]# iptables -I OUTPUT -p icmp -m icmp --icmp-type 3/1 -s 10.1.1.93 -j DROP
[admin@user ~]# iptables -nL 
Chain INPUT (policy DROP)
...
...
Chain OUTPUT (policy DROP)
target     prot opt source               destination         
DROP       icmp --  10.1.1.93            0.0.0.0/0            icmptype 3 code 1
ACCEPT     all  --  0.0.0.0/0            8.8.8.8              /* COMMENT */

Also tried blocking all icmp type 3 packets but somehow I still see the packets in tcpdump. Can someone help what I am doing wrong here?

[admin@user ~]# iptables -I OUTPUT -p icmp -m icmp --icmp-type 3 -s 10.1.1.93 -j DROP

Edit: Closest question I see is this one which does not have answer yet. https://unix.stackexchange.com/questions/217750/undesired-icmp-destionation-unreachable-message

已采纳解答

原帖链接 · Piotr P. Karwasz · CC BY-SA 4.0

Since 10.1.1.93 is not the address of any interface and you have a SNAT rule, I would guess that the ICMP packet is generated with a different source address, so your iptables rule does not match.

To get rid of those Destination Host Unreachable packets you could add the correct address to the iptables rule or no address at all:

iptables -I OUTPUT -p icmp -m icmp --icmp-type host-unreachable -j DROP

However, I would work on their cause: someone tries to connect to an address that can appear only on outgoing, not incoming connections. A rule like:

iptables -A FORWARD -d 10.1.1.93 -m conntrack --ctstate NEW -j DROP

should solve your problem. Remark: it is in the FORWARD table, since those connections will not reach into INPUT.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。