Table of Contents
In this article we will discuss about how to change mtu size on Mac, Linux and Windows. People are used to just plugging in their router and being connected to the Internet right away. This can work, but you might not be getting the most out of your Internet connection or speeds.
The maximum size of a packet that can be sent over your network is the MTU size. If your network is slowing down, lagging, or even dropping out completely, you should find the best MTU size and change it if you can. MTU stands for Maximum Transmission Unit.
In general, a larger MTU size makes a network connection more efficient because each packet can carry more data. However, the default MTU size (often 1500) can cause problems with some networks and needs to be changed. On a Mac, you can change the MTU size both through the command line and through the System Preferences panel.
How to change mtu size on Linux
Read current MTU
- 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.
- If the command does not work, try the following command, which creates a similar list:
ip ad | grep mtu
- Most Linux distributions also have a graphical interface where the MTU can be found. This is for people who would rather click through dialogues than type commands into the console. In Kubuntu, for example, you can also use the connection editor to find out the MTU, as shown in the screenshot below. There are similar paths and dialogues in other distributions as well.
Set the MTU value
Either GUI dialogues or shell commands can be used in Linux to set the MTU. If the MTU is to be set through the graphical user interface, the same dialogue can be used that we used to read the MTU two paragraphs ago.
- On Debian and Ubuntu systems, the network interface config file can be used to set the MTU from the shell. (Other distributions may need different configuration 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” needs to be changed to the MTU value you want. After saving and closing the configuration file, the interfaces should be started up again.
/etc/init.d/networking
restart
Determine the optimal MTU
- The ping command works in Linux, just like it does in Windows and OSX, to find the best MTU value. But under Linux, the parameters are a little different. The number of pings to send is set by the “c” parameter. The “M” parameter with the value “do” means that the packages should not be broken up under any circumstances, and the “s” parameter tells what size the package should be.
ping -c 2 -M do -s 1550 www.google.de
- Again, you start with a data packet that is obviously too big and keep lowering it until the ping works. If the packet is still too big, an error message like “ping: local error: Message too long” will show up.
- To get the MTU value, add 28 bytes to the ideal packet size (20 bytes for the TCP header and 8 bytes for the ICMP (Ping) header).
How to change mtu size on Windows
Determine the optimal MTU in Windows
- In Windows, we use the ping command in the console to find the best MTU. With the “l” parameter, we set the size of the packet, which should be larger than the expected MTU for now. The “f” parameter says that the package should not be broken up.
ping -f -l 1550 www.google.de
- Now, we make the call again and each time, the buffer size (in this case, 1550) gets smaller. If we could run ping and it didn’t say “packet needs to be broken up but DF set,” we’d be almost done. We add 28 bytes to get the MTU size (header infos).
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
- The MTU set for an interface is shown in the “MTU” column. Also, the “Idx” column is interesting because we need the Id from this column to set a new MTU value later.netsh interface ipv4 show interfaces
Set the MTU value
- To change a network interface’s MTU, we need both the desired MTU value and the ID of the network interface. You can get the Id from the list of interfaces in the “Read current MTU in Windows” section of this article. In the last sentence, we found the MTU. With these two numbers, we can use the following command in the CMD to set the MTU.
netsh interface ipv4 set subinterface {id} mtu={mtu} store=persistent
- The values for “id” and “mtu” must be put in place of “id” and “mtu,” respectively. If the command doesn’t work, right-click “Run as administrator” and click “Restart.”
How to change mtu size on Mac
Set MTU value
- 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”.
Determine the optimal MTU
- As with Windows and Linux, the ping command is used to figure out the best MTU. In order to do this, the “D” and “s” parameters must be set. The “D” parameter, which means “Do not fragment,” says that the package shouldn’t be broken up into pieces. The size of the data packet is set by the “s” parameter. At first, this had to be set a little too high.
ping -D -s 1550 example.com
- Now run the command over and over until the ping works. Each time the code is run, the “s” parameter must be decreased. If the ping works, add 28 to the value of the “s” parameter and use this total as the MTU.
Read current MTU
In OSX, you can use either the network settings dialogue or a short terminal command to see what the current MTU is. If you want to find the MTU through the settings dialogue, go to “System Settings > Network > Additional Options > Hardware.” Set the configuration to “manual” and the MTU to “custom” on the hardware tab. Then the MTU can be read. (Important: If you want the system to set the MTU, you must close the hardware dialogue with “Cancel.”)
- If the MTU shall be read out via the terminal, this can be done via the following shell command:
networksetup -getMTU {iface}
- The name of the interface to be read out must be put in place of “iface.” With the ifconfig command, you can see a list of all interfaces and their names.
FAQ
How do I change the MTU size in Mac terminal?
Open system preferences, click on network, and unlock the padlock by entering the admin name and password. Click on “Advanced,” then “Hardware,” then “Configure,” and then choose “Manually” from the drop-down menu. Click the drop-down arrows next to MTU again and choose either standard 1500 or custom.
What is the MTU size for Linux?
The standard value is set to 1500 bytes by default. But you can change the size of the packet’s payload, which lets you send more data and speed up the data transfer. You can make the value bigger by setting your MTU to 9000. This will let you use Jumbo Frames.
How do I set the correct MTU?
Add 28 (IP/ICMP headers) to that number to get the best MTU setting. For example, if ping tests show that the largest packet size is 1462 bytes, add 28 to 1462 to get 1490, which is the best MTU setting.