Score:0

How to set MTU PERMANENTLY in CLI

br flag

I'm using Ubuntu 20.04 in WSL2, and cannot for the life of me permanently set the MTU. No matter what I do, after rebooting, it's 1500 again. I had the same problem running Ubuntu natively, and switched to windows because Ubuntu doesn't work over VPN because the MTU is wrong.

Is there really no way to permanently set the MTU?

I tried /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;                                                                                                                                                                                                              #}       

I also tried messing with netplan, but I don't think my system uses that.

Also tried /etc/network/interfaces

mtu 1340
br flag
My memory is a little hazy at this point. I eventually switched to MacOS and haven't had any issues since. I was doing my dev work on Ubuntu Desktop, but the MTU issue drove me to use Windows, only to eventually run into similar issues using Ubuntu through WSL2 when I switched to T-Mobile Home Internet.
in flag
[Does this answer your question](https://askubuntu.com/a/1283819/1222991)? This appears to be something you need to control though Windows rather than the client OS
br flag
Yes, kind of? This seems to solve the underlying problem. git pull no longer hangs, but Ubuntu still reports an MTU of 1500. I'm no longer using Ubuntu desktop because of this issue.
WU-TANG avatar
cn flag
are you just using network-manager???? if so, the MTU is set in the GUI.. and all that does is edit /etc/NetworkManager/system-connections/yourconnectionname.nmconnection with mtu=1340.... btw, I haven't had any problems running my ubuntu desktop over a VPN... native ubuntu client software or the cisco anyconnect my job forced us to use...
Score:0
br flag

How did you verify your real MTU?

I suppose your Ubuntu uses Netplan manager. You have asked CLI, not GUI. Here is my suggestion.

MTU verifying

Ping your default GW or another live closest node in your LAN by packets with "do not fragment" option and with specified packet size. Change packet size and find the limit size which is responded by the peer node:

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

If packet size is bigger than MTU then ping response is e.g.:

ping: local error: message too long, mtu=1500

Please note that packet size you use in the ping command (-s option) must be MTU minus 18 bytes, i.e. for instance 1500-18=1472.

The response if the MTU is not exceeded is e.g.

2 packets transmitted, 2 received, 0% packet loss, time 1014ms

Setting

I will suppose your interface name is eth1.

cd /etc/netplan
ls -l
sudo cp 01-network-manager-all.yaml  02-eth1-mtu.yaml
sudo vi 02-eth1-mtu.yaml

The content example of new file 02-eth1-mtu.yaml:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth1:
      dhcp4: true
      mtu: 1000

New setting will be applied by command netplan try. If you press Enter while executing a command, the wait will be less than 120 s.

sudo netplan try

Now it is time to verify new MTU size by method described above.

Disable new setting without deleting

sudo mv /etc/netplan/02-eth1-mtu.yaml /etc/netplan/02-eth1-mtu.yaml.bak
sudo netplan try
in flag
AFAIK most Ubuntu distros use NetworkManager, I'd be worried that setting mtu via netplan would mean that updating mtu in the NM gui wouldn't survive reboot but would keep getting reverted? Anyway `sudo nano /etc/NetworkManager/system-connections/*.nmconnection` (don't use "") will open each of your NM connections config files in turn and allow you to alter the mtu.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.