Linux 中的 MTU (IPv4) 测试

Rui*_*iro 7 debian tcpdump nmap icmp

我注意到我有几个网络在防火墙级别阻止了所有 ICMP 消息,除了 ICMP 回显和回复。

我知道至少需要允许 IPv4 中的 ICMP 消息类型 3 才能进行 MTU 协商。

可以使用以下命令嗅探数据包:

sudo tcpdump icmp
Run Code Online (Sandbox Code Playgroud)

但是,如何在一个远程点上生成 ICMP 数据包类型 3 以进行全局测试?

Rui*_*iro 9

您需要 ICMP 类型 3“目标不可达”数据包来提供健康的IP 连接。

生成用于测试的 ICMP 数据包类型 3 的最简单方法是使用该nping程序。

nping程序是nmap包的一部分,因此需要安装它。为此,您必须执行以下操作:

sudo apt install nmap
Run Code Online (Sandbox Code Playgroud)

安装后,要测试远程 Linux 系统,开始在远程端运行,侦听 ICMP 类型 3 和 4 数据包:

sudo tcpdump  'icmp[0] = 3'
Run Code Online (Sandbox Code Playgroud)

或者

sudo tcpdump  '(icmp[0] = 3) and (host ip_or_dns_of_nping_sender)'     
Run Code Online (Sandbox Code Playgroud)

然后做另一个系统/端发送ICMP类型3数据包:

sudo nping --icmp-type 3 ip_or_dns_of_remote
Run Code Online (Sandbox Code Playgroud)

一定要在两个方向上测试它们。

举个例子,使用loopback接口在本地机器上显示测试:

在第一个终端 - 侦听 ICMP 类型 3 消息:

$sudo tcpdump  -i lo 'icmp[0] = 3'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
21:37:44.089420 IP localhost > localhost: [|icmp]
21:37:45.090092 IP localhost > localhost: [|icmp]
21:37:46.091289 IP localhost > localhost: [|icmp]
21:37:47.093095 IP localhost > localhost: [|icmp]
21:37:48.095019 IP localhost > localhost: [|icmp]
^C
5 packets captured
10 packets received by filter
0 packets dropped by kernel
Run Code Online (Sandbox Code Playgroud)

在第二个终端 - 发送 ICMP 类型 3 消息:

$sudo nping --icmp-type 3 localhost
Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2017-03-06 21:37 WET
SENT (0.0221s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable     (type=3/code=0) ttl=64 id=40477 iplen=28 
RCVD (0.2088s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable  (type=3/code=0) ttl=64 id=40477 iplen=28 
SENT (1.0228s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
RCVD (1.2088s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
SENT (2.0240s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
RCVD (2.2088s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
SENT (3.0258s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
RCVD (3.2088s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
SENT (4.0277s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 
RCVD (4.2088s) ICMP 127.0.0.1 > 127.0.0.1 Destination unreachable (type=3/code=0) ttl=64 id=40477 iplen=28 

Max rtt: 186.715ms | Min rtt: 181.081ms | Avg rtt: 184.307ms
Raw packets sent: 5 (140B) | Rcvd: 5 (140B) | Lost: 0 (0.00%)
Nping done: 1 IP address pinged in 4.24 seconds
Run Code Online (Sandbox Code Playgroud)

遥不可及