How to change MTU size in Ubuntu 22.04

Share this article

In computer networking, MTU stands for Maximum Transmission Unit. As the name suggests it is the unit that tells the largest data packet a device can accept or transfer via an internet connection. It is typically measured in bytes. In our previous article, we explained what is MTU size and why it is important and how we can choose the right MTU size for our network interface.

In this article, we will show what is the current MTU size, change the MTU size through CLI which is not permanent, and then change the MTU size in the configuration file.

How to get the current MTU size

Finding the MTU size of the interface is simple and straightforward, you can do it through ifconfig or ip a command.

If you run ifconfig command, it shows all the interfaces in your system and all the information related to the interface but you can also use the command with the grep option or with the particular interface as shown in below code section.

ifconfig <interface name>
ifconfig|grep mtu
ip a|grep mtu

Examples:

foofunc@test:~$ ifconfig enp0s31f6
enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:2b:67:2c:72:48  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xd9300000-d9320000  
foofunc@test:~$ ifconfig|grep mtu
enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
enxf4a80d2b8bc9: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

Similarly you can run ip a command with the grep command

foofunc@test:~$ ip a|grep mtu
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
3: wlp0s20f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
4: enxf4a80d2b8bc9: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
5: wwan0: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000

How to change MTU size

There are many ways to change the MTU size. Here we will discuss 3 different options, in which two of which are through the command line, and one we will change in the network configuration file.

Changing MTU size through CLI

We can use ifconfig and ip a commands to change the MTU size. Commands are shown in the below code section

sudo ifconfig <interface_name> mtu <size in bytes>
sudo ip link set mtu <size in bytes> <interface_name> 

Example:

foofunc@test:~$ sudo ifconfig enp0s31f6  mtu 1400
foofunc@test:~$ ifconfig|grep mtu
enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1400
foofunc@test:~$ sudo ip link set mtu 1500 enp0s31f6
foofunc@test:~$ ifconfig|grep mtu
enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

Changing MTU size in the configuration file

In the previous subsection, we have seen setting up MTU size through CLI but it is not persistent. When we reboot our system, the MTU size set through CLI won’t be there, system revert back to its default MTU size. To make MTU size we will set in network configuration files or in DHCP server.

Changing on DHCP server

If you are using DHCP server to get the IP address in your system, open /etc/dhcp/dhclient.conf file.

sudo vi /etc/dhcp/dhclient.conf

If you want to change the MTU size for all the interfaces which take IP addresses from the DHCP server add the following line in the dhclient.conf file.

default interface-mtu <mtu_size bytes>;
supersede interface-mtu <mtu_size in bytes>;

if you want to add MTU size for the particular interface use the following information for that interface.

interface "interface_name" {
default interface-mtu <mtu_size in bytes>
supersede interface-mtu <mtu_size in bytes>
}

After adding your changes restart the networking service by using the following command.

service network restart 
or 
service NetworkManager restart 

Using /etc/sysconfig/network-scripts/ifcfg-<int_name>

If you are using network.service or NetworkManager for the interface configuration you can use /etc/sysconfig/network-scripts/ifcfg-interface name. In the file, you can mention the MTU size as shown in the below-mentioned code section.

sudo  vi /etc/sysconfig/network-scripts/ifcfg-ens3 
PHYSDEV="ens3"
BOOTPROTO="none"
PROXY_METHOD="none"
IPADDR="192.168.122.23"
NETMASK="255.255.255.0"
MTU="9000"
UUID=
ONBOOT="yes"

After changing the configuration restart the networking service by the following command

service network restart 
or 
service NetworkManager restart 

Summary

We have found that most routers in computer networks set the standard MTU size to 1500 bytes but if your internal company has a high bandwidth machine interface you may find that they increase the MTU size to 9000 bytes (jumbo frames) and get faster transmission. Changing the MTU size in such occurrence is important. In this article, we have learned how we can change the MTU size through the CLI and through configuration.

Leave a Comment

Your email address will not be published. Required fields are marked *