Ubuntu

How to change MTU size in Linux

How to change MTU size in Linux
MTU (Stands for Maximum Transmission Unit) is the maximum size of the packet that can be transmitted from a network interface. All the devices including servers and switches/routers involved in communication should have the same MTU size. Large MTU size has less overhead associated with it while the smaller MTU has less delay.

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

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 mtu

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:

$ 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:

$ ifconfig mtu up

For instance, to change the MTU size of an interface named ens33 to 1000 bytes, the command would be:

$ ifconfig ens33 mtu 1000 up

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:

$ 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.conf

Then add the following lines below the “send host-name = gethostname(); line:

default interface-mtu ;
supersede 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 restart

Also, bring up the interface using the following command:

$ sudo ifup

Make sure to replace the with the actual network interface on your system e.g ens33, eth0, eth1, etc.

In our case, it would be:

$ sudo ifup ens33

Now issue the following command in Terminal to verify if the MTU size has changed successfully.

$ sudo ifconfig | grep mtu

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:

$ sudo nano /etc/network/interfaces

Append the below line in the file:

post-up /sbin/ifconfig mtu

Make sure to replace with the actual interface name and 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:

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 restart

Also, bring up the interface using the following command:

$ sudo ifup

Make sure to replace the with the actual network interface on your system e.g. ens33, eth0, eth1, etc.

In our case, it would be:

$ sudo ifup ens33

Now 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!

Middle mouse button not working in Windows 10
The middle mouse button helps you scroll through long webpages and screens with a lot of data. If that stops, well you will end up using the keyboard ...
How to change Left & Right mouse buttons on Windows 10 PC
It's quite a norm that all computer mouse devices are ergonomically designed for right-handed users. But there are mouse devices available which are s...
Emulate Mouse clicks by hovering using Clickless Mouse in Windows 10
Using a mouse or keyboard in the wrong posture of excessive usage can result in a lot of health issues, including strain, carpal tunnel syndrome, and ...