The default MTU size in most of the Ethernet networks is 1500 bytes. However, you can change it as per the requirements. In this tutorial, we will explain how to change MTU size in Linux.
Prerequisites
- Ubuntu 20.04 system
- User with sudo privileges
Note: The commands discussed in this article have been tested on Ubuntu 20.04 LTS (Focal Fossa). The same commands are also valid for Debian distribution.
View Current MTU Size
In order to view the current MTU size of your ethernet interface, use the ifconfig command as follows:
The output below shows the current MTU size of interface ens33 is 1500.
Alternatively, you can also use the “ip a” command to view the current MTU size:
Temporarily changing the MTU Size – Using ifconfig command
We can use the ifconfig command to change the MTU size of a system’s network interface. However, remember that this change does survive a reboot and returns to the default value i.e. 1500.
To change the MTU size of an interface, use the following syntax:
For instance, to change the MTU size of an interface named ens33 to 1000 bytes, the command would be:
After running the above command, the MTU size changes instantaneously. This change even does not require a service restart.
You can verify the new MTU size by running the following command in Terminal:
From the above output, you can verify that MTU size has now changed to 1000 bytes. However, as mentioned before, this change will not survive a reboot. The MTU size will return to its default value of 1500 after a reboot.
Permanently changing the MTU Size
The ifconfig command instantaneously changes the MTU size but this change does not survive a system reboot. In the following section, we will see how to permanently change the MTU size.
In dynamic IP addressing, the MTU size is set by DHCP. So will need to configure the DHCP configuration file located at /etc/dhcp/dhclient.conf. For static IP address, we will make changes in the network interface configuration file located at /etc/network/interfaces.
Using /etc/dhcp/dhclient.conf file
If the DHCP server is running on your system and the network interfaces are configured to receive the IP addresses from it, then use /etc/dhcp/dhclient.conf file to change the MTU size.
Edit the nano /etc/dhcp/dhclient.conf using the following command:
Then add the following lines below the “send host-name = gethostname(); line:
supersede interface-mtu <mtu_size>;
For instance, to set the MTU size to 1400, we will add:
supersede interface-mtu 1400;
If you have multiple interfaces and you want to change the MTU size of just one interface, then enclose it in the braces as follows:
default interface-mtu <mtu_size>;
supersede interface-mtu <mtu_size>;
}
Once you have configured the file, save, and close it.
Now restart the networking service using the following command in Terminal:
Also, bring up the interface using the following command:
Make sure to replace the <interface_name> with the actual network interface on your system e.g ens33, eth0, eth1, etc.
In our case, it would be:
Now issue the following command in Terminal to verify if the MTU size has changed successfully.
From the output, you can see the MTU size has been changed to 1400.
Using /etc/network/interfaces file
If your network interface is configured to obtain a static IP address, then you can change the MTU size by configuring the /etc/network/interfaces file.
Edit the /etc/network/interfaces file using the following command in Terminal:
Append the below line in the file:
Make sure to replace <interface-name> with the actual interface name and <mtu_size> with the MTU size you want to set on the network interface.
For instance, to change the MTU size of an interface named ens33 to 1300 bytes, the command would be:
Once you have configured the file, save, and close it.
Now restart the networking services using the following command in Terminal:
Also, bring up the interface using the following command:
Make sure to replace the <interface_name> with the actual network interface on your system e.g. ens33, eth0, eth1, etc.
In our case, it would be:
Now issue the following command in Terminal to verify if the MTU size has changed successfully.
From the output, you can see that the MTU size has been changed to 1300. This change will be kept persistent and will not be affected even after a reboot.
That is all there is to it! By following the above procedures, you can change the MTU size of a network interface either temporarily or permanently in your Linux system. Hope this helps!