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:
$ ifconfig | grep mtuThe 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:
$ ip a | grep mtu
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:
$ ifconfigFor instance, to change the MTU size of an interface named ens33 to 1000 bytes, the command would be:
$ ifconfig ens33 mtu 1000 upAfter 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:
$ ifconfig | grep mtu
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:
$ sudo nano /etc/dhcp/dhclient.confThen add the following lines below the “send host-name = gethostname(); line:
default interface-mtusupersede interface-mtu
For instance, to set the MTU size to 1400, we will add:
default interface-mtu 1400;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:
interface "interface_name"default interface-mtu
supersede interface-mtu
Once you have configured the file, save, and close it.
Now restart the networking service using the following command in Terminal:
$ sudo service networking restartAlso, bring up the interface using the following command:
$ sudo ifupMake sure to replace the
In our case, it would be:
$ sudo ifup ens33Now issue the following command in Terminal to verify if the MTU size has changed successfully.
$ sudo ifconfig | grep mtuFrom 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:
$ sudo nano /etc/network/interfacesAppend the below line in the file:
post-up /sbin/ifconfigMake sure to replace
For instance, to change the MTU size of an interface named ens33 to 1300 bytes, the command would be:
post-up /sbin/ifconfig ens33 mtu 1300 up
Once you have configured the file, save, and close it.
Now restart the networking services using the following command in Terminal:
$ sudo service networking restartAlso, bring up the interface using the following command:
$ sudo ifupMake sure to replace the
In our case, it would be:
$ sudo ifup ens33Now issue the following command in Terminal to verify if the MTU size has changed successfully.
$ ip a | grep mtu
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!