什么是 MTU?
In networking, maximum transmission unit (MTU) is a measurement representing the largest data packet that a network-connected device will accept. Imagine it as being like a height limit for freeway underpasses or tunnels: Cars and trucks that exceed the height limit cannot fit through, just as packets that exceed the MTU of a network cannot pass through that network.

mtu: 最大传输单元,即网络上传输最大的数据包,mtu的单位是字节,大部分的网络设备的mtu值是1400-1500。

  • 如果本机的mtu值大于网关的mtu值,大的数据包就会被拆开来传送,这样会产生数据包的碎片,增加丢包率,降低网络速度
  • 把mtu设置比网关小或者相同,可以减少丢包
  • 设置合适的mtu值,可以减少部分网站打不开,上网速度慢等问题
  • 一般情况,可以把路由器、交换机和服务器的mtu值统一设置

如何修改Linux系统的MTU值?

Debian/Ubuntu系统更改mtu的方法:

查看服务器的mtu值:

cat /sys/class/net/eth0/mtu

临时修改mtu值:(重启服务器后失效)

ifconfig  eth0 mtu 1400

永久修改mtu值的方法:

修改 /etc/network/interfaces 文件,添加一行mtu的配置,示例如下:

nano  /etc/network/interfaces

# The primary network interface
#allow-hotplug eth0
auto eth0
iface eth0 inet static
        address 10.10.10.20
        netmask 255.255.255.0
        gateway 10.10.10.1
        mtu 1400
eth1……

随后重启网卡(service network restart)或者服务器生效

CentOS系统更改MTU的方法
Centos6和Centos7系统一键修改MTU值:

echo "1400" > /sys/class/net/eth0/mtu && echo "echo \""1400"\" > /sys/class/net/eth0/mtu">> /etc/rc.d/rc.local && chmod +x /etc/rc.d/rc.local

相关内容参考自网络

Last modification:March 21, 2023
If you think my article is useful to you, please feel free to appreciate