How to read, calculate and set MTU in Windows, Linux and OSX

After I released the MTU Optimizer, a small tool for determining the optimal MTU, some days ago, let’s look at how to determine the optimal MTU by hand, how to read the currently set MTU and how to set new MTU value now. Of course we will discuss the whole thing for the three major operating systems: Windows, OSX and Linux.

Before we look at the implementation within the individual operating systems, we first briefly clarify what the MTU is and how its optimal value can be calculated.

Theory – Identify ideal MTU

The MTU (Maximum Transfer Unit) describes the maximum packet size of a protocol. It therefore indicates the maximum size of a data packet, so that it can be transmitted via a protocol. If a data packet is larger, it becomes fragmented – i.e. divided into several packages.

For example, let’s assume that we (=PC) would have a factory for sugar packets and our packet size (=configured MTU) would be 1.5kg. Now the bakery has ordered 5 packages (5 x 1.5 kg) of sugar, but our postman (=network interface) can only transfer packets with a maximum size of 1kg (=protocol limit). What is he doing now? He fragments our sugar packets and divides them into 1kg and 0.5kg packs. So he needs two packages for transmission of one of our initial sugar packages. In addition, the postman has more work, because he has to mark which packages belong together. These multi-packets (=overhead) slow down the sending of packets (=data transfer speed).

To solve the problem and speed up the shipping, we would have to dimension our packaging size (=MTU) so that the postman does not have to repackage (=fragment). The ideal MTU is 1kg in our case. In order to determine this value, we would have to ask the postal worker for the size limit, when he starts repackaging. The same story is true for computer systems.

In the IT, we send a data package by ping command and tell ping the size of the package as well as the info that this package should not be fragmented. If the packet size is too large, ping tells us that the package is not ok and that the package had to be fragmented, if it shall be send sucessfully.

ping -f -l 1550 www.google.de

Pinging www.google.de [216.58.213.195] with 1550 bytes of data:
Packet needs to be fragmented but DF set.

Now we reduce the packet size until the error message of the fragmentation is omitted. This gives us the optimal package size. However, since the MTU also includes protocol information, we still have to add 28 bytes (20 bytes = IPv4 header and 8 bytes = ICMP) to the package size value to get the optimal MTU.

MTU in Windows

Read current MTU in Windows

To display the current MTU by console, use the following command, which must be entered into the CMD (Win + R key, “CMD”, “Ok” button):

netsh interface ipv4 show interfaces

This command generates a list that looks like this (or something similar):

Idx     Met         MTU          State                Name
---  ----------  ----------  ------------  ---------------------------
 10          25        1528  connected     Ethernet
  5          55        1528  disconnected  WiFi
 15          55        1528  disconnected  Ethernet 2

The “MTU” column shows the MTU currently set for an interface. In addition, the “Idx” column is interesting since we need the Id from this column to set a new MTU value later.

Determine the optimal MTU in Windows

To determine the optimal MTU in Windows, we use the ping command in the console. By means of the “l” parameter, we set the packet size (this should be larger than the expected MTU for the time being) and use the “f” parameter to indicate that the package should not be fragmented.

ping -f -l 1550 www.google.de

Now we repeat the call and reduce the buffer size (in example 1550) with each call. If the ping could be executed and no longer show “packet needs to be fragmented but DF set” we are almost ready. To get the MTU size we add 28 bytes (header infos).

Set the MTU value in Windows

To set the MTU for a network interface, we need the desired MTU value as well as the ID of the network interface. The Id can be taken from the interface list from the section “Read current MTU in Windows” of this article. We found the MTU in the last paragraph. With the two values we can now set the MTU in the CMD with the following command.

netsh interface ipv4 set subinterface {id}  mtu={mtu} store=persistent

The placeholders {id} as well as {mtu}, must be exchanged by the corresponding values. If the command does not work, please restart the CMD by right-clicking “Run as administrator”.

MTU in OSX

Read current MTU in OSX

To read out the current MTU in OSX, either the network setting dialog or a short terminal command can be used. If the MTU shall be read out via the settings dialog, it can be found in “System Settings -> Network -> Additional Options -> Hardware”. On the hardware tab, set the configuration to “manual” and the MTU to “custom”. The MTU can then be read out. (Important: If the MTU shall be set by the system, the hardware dialog must be closed with “Cancel”!)

MTU in OSX  MTU in OSX Hardware

If the MTU shall be read out via the terminal, this can be done via the following shell command:

networksetup -getMTU {iface}

The value {iface} must be replaced by the name of the interface that is to be read out. A list of all interfaces and their names can be displayed using the ifconfig command.

Determine the optimal MTU in OSX

The determining the best MTU works (as also in Windows and Linux) by use of the ping command. For this purpose the parameters “D” and “s” must be set. The “D” parameter stands for “Do not fragment” and indicates that the package should not be fragmented. The “s” parameter specifies the size of the data packet. This initially hast to be set a little bit too large.

ping -D -s 1550 example.com

Now execute the command until the ping is successful. The “s” parameter must be reduced for each execution. If the ping is successful, add 28 to the “s” parameter value and take this sum as the MTU.

Set MTU value in OSX

To set the MTU in OSX, either the hardware dialog in the network settings (see paragraph “Reading current MTU in OSX”) or a command in the terminal can be used.

networksetup -setMTU {iface} {mtu}

The value {iface} must be replaced by the name of the interface and the value {mtu} by the MTU value. If necessary, the command must be executed via “sudo”.

MTU in Linux

Read current MTU in Linux

To display the current MTUs for network interfaces in Linux, the following command is suitable. (This must be entered in the shell/terminal.):

ifconfig| grep mtu

As a result, you should get a list of interfaces as well as their MTU values. At the beginning of the line is the respective identity, at the end of the line the MTU value.

enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1384
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
vmnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
vmnet8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

If the command does not work, try the following command, which creates a similar list:

ip ad | grep mtu

MTU in KubuntuThose who prefer to click through dialogs instead of writing console commands can find the MTU in most Linux distributions also on the graphical interface. In Kubuntu for example the MTU can also be read out via the connection editor, as shown in the adjacent screenshot. In other distributions, there are similar paths/dialogs.

Determine the optimal MTU in Linux

In order to determine the optimal MTU value in Linux, the ping command is suitable – as is the case with Windows and OSX. However, the individual parameters differ slightly under Linux. The “c” parameter specifies how many pings should be sent. The “M” parameter with the value “do” indicates that the packages should not be fragmented in any case and the parameter “s” parameter specifies the size of the package.

ping -c 2 -M do -s 1550 www.google.de

Again, you start with an obviously too large data packet and gradually reduce the value until the ping is successful. If the packet is still too large, the following (or similar) error message appears: “ping: local error: Message too long”.

If the ideal packet size is found, 28 bytes (20 bytes TCP header, 8 bytes ICMP (Ping) header) must be added to get the MTU value.

Set the MTU value in Linux

To set the MTU in Linux, either GUI dialogs or shell commands can be used. If the MTU is to be set via the graphical interface, the same dialog, which we have used two paragraphs above to read the MTU, can be used.

If the MTU is to be set via the shell, this can be done with Debian/Ubuntu systems via the network interface config file. (Other distros may require other config steps.)

nano /etc/network/interfaces

The individual interface configurations are located within the file. At the end of each interface configuration you can append

mtu {mtu}

to set a fixed MTU value. The value {mtu} of course has to be replaced by the desired MTU value. After the configuration file has been saved and closed, the interfaces should be restarted.

/etc/init.d/networking restart

Leave a comment

Please be polite. We appreciate that. Your email address will not be published and required fields are marked