我在 WSL2 中使用 Ubuntu 20.04,无论如何都无法永久设置 MTU。无论我做什么,重新启动后,它又变成了 1500。我在本机运行 Ubuntu 时遇到了同样的问题,并且切换到 Windows,因为 Ubuntu 无法通过 VPN 工作,因为 MTU 错误。
真的没有办法永久设置 MTU 吗?
我尝试了 /etc/dhcp/dhclient.conf
GNU nano 4.8 /etc/dhcp/dhclient.conf # Configuration file for /sbin/dhclient. # # This is a sample configuration file for dhclient. See dhclient.conf's # man page for more information about the syntax of this file # and a more comprehensive list of the parameters understood by # dhclient. # # Normally, if the DHCP server provides reasonable information and does # not leave anything out (like the domain name, for example), then # few changes must be made to this file, if any. # option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; send host-name = gethostname(); default interface-mtu 1340; supersede interface-mtu 1340; request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, domain-search, host-name, dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers, netbios-name-servers, netbios-scope, rfc3442-classless-static-routes, ntp-servers; #send dhcp-client-identifier 1:0:a0:24:ab:fb:9c; #send dhcp-lease-time 3600; #supersede domain-name "fugue.com home.vix.com"; #prepend domain-name-servers 127.0.0.1; #require subnet-mask, domain-name-servers; timeout 300; #retry 60; #reboot 10; #select-timeout 5; #initial-interval 2; #script "/sbin/dhclient-script"; #media "-link0 -link1 -link2", "link0 link1"; #reject 192.33.137.209; #alias { # interface "eth0"; # fixed-address 192.5.5.213; # option subnet-mask 255.255.255.255; #} #lease { # interface "eth0"; # fixed-address 192.33.137.200; # medium "link0 link1"; # option host-name "andare.swiftmedia.com"; # option subnet-mask 255.255.255.0; # option broadcast-address 192.33.137.255; # option routers 192.33.137.250; # option domain-name-servers 127.0.0.1; # renew 2 2000/1/12 00:00:01; # rebind 2 2000/1/12 00:00:01; # expire 2 2000/1/12 00:00:01; #}
我也尝试过使用 netplan,但我认为我的系统不使用它。
还尝试了 /etc/network/interfaces
mtu 1340
答案1
您如何验证您的真实 MTU?
我猜你的 Ubuntu 使用 Netplan 管理器。你问的是 CLI,而不是 GUI。这是我的建议。
MTU 验证
使用带有“不分段”选项和指定数据包大小的数据包 ping 您的默认网关或 LAN 中另一个最近的活动节点。更改数据包大小并找到对等节点响应的限制大小:
ping 192.168.1.1 -c 2 -M do -s 2000
ping 192.168.1.1 -c 2 -M do -s 1500
ping 192.168.1.1 -c 2 -M do -s 1400
ping 192.168.1.1 -c 2 -M do -s 1472
ping 192.168.1.1 -c 2 -M do -s 1473
如果数据包大小大于 MTU,则 ping 响应如下:
ping: local error: message too long, mtu=1500
请注意,在 ping 命令(-s 选项)中使用的数据包大小必须是 MTU 减去 28 字节(IP 头和 ICMP 头长度),例如 1500-28=1472。
如果没有超出 MTU,则响应如下
2 packets transmitted, 2 received, 0% packet loss, time 1014ms
环境
我假设您的接口名称是 eth1。
cd /etc/netplan
ls -l
sudo cp 01-network-manager-all.yaml 02-eth1-mtu.yaml
sudo vi 02-eth1-mtu.yaml
新建文件02-eth1-mtu.yaml内容示例:
network:
version: 2
renderer: NetworkManager
ethernets:
eth1:
dhcp4: true
mtu: 1000
新设置将通过命令应用netplan try
。如果在执行命令时按 Enter,则等待时间将少于 120 秒。
sudo netplan try
现在是时候通过上面描述的方法验证新的 MTU 大小了。
禁用新设置而不删除
sudo mv /etc/netplan/02-eth1-mtu.yaml /etc/netplan/02-eth1-mtu.yaml.bak
sudo netplan try