linux mtu查看&&设置
人气:0
大部分网络设备都是1500。如果本机的MTU比网关的MTU大,大的数据包就会被拆开来传送,这样会产生很多数据包碎片,增加丢包率,降低网络速度。把本机的MTU设成比网关的MTU小或相同,就可以减少丢包
测试 (1472 + 8(ICMP回显示请求和回显应答报文格式长度) + 20(IP首部) = 1500)
$ ping -c 2 -M do -s 1472 192.168.0.6输出
PING 192.168.0.6 (192.168.0.6) 1472(1500) bytes of data.
bytes from 192.168.0.6: icmp_seq=1 ttl=127 time=1.06 ms
bytes from 192.168.0.6: icmp_seq=2 ttl=127 time=1.06 ms
--- 192.168.0.6 ping statistics ---
packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 1.060/1.062/1.064/0.002 ms
查看本机的mtu
$ netstat -i输出
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 82879 0 0 0 69000 0 0 0 BMRU
lo 16436 0 84 0 0 0 84 0 0 0 LRU
设置
# 设置本机的mtu
sudo ifconfig eth0 mtu 1472
# 查看设置后的结果
$ netstat -i
测试 (1472 + 8(ICMP回显示请求和回显应答报文格式长度) + 20(IP首部) = 1500)
$ ping -c 2 -M do -s 1472 192.168.0.6输出
PING 192.168.0.6 (192.168.0.6) 1472(1500) bytes of data.
bytes from 192.168.0.6: icmp_seq=1 ttl=127 time=1.06 ms
bytes from 192.168.0.6: icmp_seq=2 ttl=127 time=1.06 ms
--- 192.168.0.6 ping statistics ---
packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 1.060/1.062/1.064/0.002 ms
查看本机的mtu
$ netstat -i输出
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 82879 0 0 0 69000 0 0 0 BMRU
lo 16436 0 84 0 0 0 84 0 0 0 LRU
设置
# 设置本机的mtu
sudo ifconfig eth0 mtu 1472
# 查看设置后的结果
$ netstat -i
加载全部内容