MTU(Maximum Transmission Unit)是网络传输中单个数据包的最大尺寸。适当调整MTU值可以:
# 查看所有网卡的MTU值
ip link show
# 或针对特定网卡(如eth0)
ip link show eth0 | grep mtu
# 使用ifconfig查看(较旧系统)
ifconfig | grep MTU
# 临时修改eth0的MTU值为9000(需root权限)
sudo ip link set eth0 mtu 9000
sudo nmcli connection modify eth0 ethernet.mtu 9000
sudo nmcli connection up eth0
对于Debian/Ubuntu系统:
sudo nano /etc/network/interfaces
在相应网卡配置中添加:
mtu 9000
对于CentOS/RHEL系统:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
添加:
MTU=9000
# 检查是否生效
ip link show eth0 | grep mtu
# 测试MTU是否正常工作(替换为目标IP)
ping -M do -s 8972 192.168.1.1
# 8972 = 9000(MTU) - 20(IP头) - 8(ICMP头)
修改MTU后,监控CPU使用率和网络性能:
# 查看CPU使用率
top
htop
# 网络性能监控
iftop -i eth0
nload eth0
# 更详细的网络统计
sar -n DEV 1
通过合理设置MTU值,可以显著降低网络协议处理对CPU的负担,特别是在高流量服务器上。