How to change MTU size in Linux

MTU (short for Maximum Transmission Unit) is the maximum packet size that can be transmitted over a network interface. All devices, including servers and switches / routers, participating in the communication must have the same MTU size. A large MTU has less overhead, while a smaller MTU has less latency.

The default MTU size on most Ethernet networks is 1500 bytes. However, you can change it as required. In this article, 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 valid for the Debian distribution as well.

View current MTU size

To view the current MTU size of your Ethernet interface, use the ifconfig command as follows:

$ ifconfig | grep mtu

The output below shows that the current MTU size of ens33 interface is 1500.

Alternatively, you can also use the ip command with the a parameter to view the current MTU size:

$ ip a | grep mtu

Temporarily resizing the MTU – using the ifconfig command

We can use the ifconfig command to change the MTU size of the system’s network interface. However, remember that this change persists across reboots and reverts to the default, which is 1500.

To change the MTU size of an interface, use the following syntax:

$ ifconfig <Interface_name> mtu <mtu_size> up

For example, to change the MTU size of an interface named ens33 to 1000 bytes, the command would look like this:

$ ifconfig ens33 mtu 1000 up

After executing the above command, the MTU size is instantly resized. This change does not even require a service restart.

You can check the new MTU size by running the following command in Terminal:

$ ifconfig | grep mtu

From the above output, you can see that the MTU size has now changed to 1000 bytes. However, as previously mentioned, this change will not persist across reboots. The MTU size will return to its default value of 1500 upon reboot.

Constant MTU resizing

The ifconfig command instantly changes the MTU size, but this change does not persist across a system reboot. In the next section, we’ll see how to permanently change the MTU size.

With dynamic IP addressing, the MTU size is set by DHCP. Therefore, you will need to configure the DHCP configuration file located at /etc/dhcp/dhclient.conf. For the static IP, we will make changes to the network interface configuration file located in / etc / network / interfaces.

Using the /etc/dhcp/dhclient.conf file

If your system is running a DHCP server and network interfaces are configured to receive IP addresses from it, use the /etc/dhcp/dhclient.conf file to change the MTU size.

Edit nano /etc/dhcp/dhclient.conf using the following command:

$ sudo nano /etc/dhcp/dhclient.conf

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

default interface-mtu <mtu_size>;

supersede interface-mtu <mtu_size>;

For example, to set the MTU size to 1400, we add:

default interface-mtu 1400;

supersede interface-mtu 1400;

If you have multiple interfaces and want to change the MTU size for only one interface, enclose it in curly braces as follows:

interface "interface_name" {

default interface-mtu <mtu_size>;

supersede interface-mtu <mtu_size>;

}

Once you have customized the file, save and close it. Now restart the network service using the following command in the terminal:

$ sudo service networking restart

Also invoke the interface using the following command:

$ sudo ifup <interface_name>

Be sure to replace with the actual network interface on your system like ens33, eth0, eth1, etc.

In our case, it will be:

$ sudo ifup ens33

Now enter the following command in Terminal to check if the MTU size has changed successfully.

$ sudo ifconfig | grep mtu

You can see from the output that the MTU size has been changed to 1400.

Using the / etc / network / interfaces file

If your network interface is configured to receive a static IP, you can change the MTU size by configuring the / etc / network / interfaces file.

Edit the / etc / network / interfaces file with the following command in Terminal:

$ sudo nano /etc/network/interfaces

Add the following line to the file:

post-up /sbin/ifconfig <interface-name> mtu <mtu_size>

Be sure to replace with the actual interface name and with the MTU size you want to set on the network interface.

For example, to change the MTU size of an interface named ens33 to 1300 bytes, the command would look like this:

post-up /sbin/ifconfig ens33 mtu 1300 up

Once you have customized the file, save and close it.

Now restart network services using the following command in Terminal:

$ sudo service networking restart

Also invoke the interface using the following command:

$ sudo ifup <interface_name>

Be sure to replace with the actual network interface on your system like ens33, eth0, eth1, etc.

In our case, it will be:

$ sudo ifup ens33

Now enter the following command in Terminal to check if the MTU size has changed successfully.

$ ip a | grep mtu

You can see from the output that the MTU was changed to 1300. This change will remain constant and will not change even after a reboot.

That’s all! By following the above procedures, you can temporarily or permanently change the MTU size of the network interface on your Linux system. Hope this helps!

Sidebar