Setting the network MTU size

Though in general it is not necessary there are (rare) occasions when it is necessary to set the MTU size explicitly, generally caused by issues with path MTU discovery.

In general you want to avoid this as using a smaller MTU size that necessary as the overheads associated with each network packet will reduce network throughput.

RedHat/CentOS

To set the MTU size in RedHat or CentOS you need to edit the appropriate network configuration file for you network device and add an entry for the MTU size. The name of the configuration file depends on the name of the network interface so for eth0 the filename is ifcfg-eth0.

Note – On RedHat or CentOS version 7.x you will also need to comment out any IPv6 options and modify the DHCP client configuration unless you are using a static IP address.

# nano /etc/sysconfig/network-scripts/ifcfg-eth0

NAME=eth0
DEVICE=eth0
#BOOTPROTO=dhcp
ONBOOT=yes
IPADDR=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
#USERCTL=no
#NM_CONTROLLED=yes
MTU=1492

For this change to take effect you need to reboot or stop and restart the network.

# reboot

OR

# ifdown eth0
# ifup eth0

Obviously if you are using ssh you will get disconnected when you stop the network!

Debian/Ubuntu

How you achieve the same thing on a Debian based distributions depends on whether or not you are using DHCP

If you have a static address you can specify the MTU size along with the network address and subnet in /etc/network/interfaces, but this won’t work if you are using DHCP as Debian assumes that the MTU size will be supplied by the DHCP server when the client requests a DHCP lease.

# nano /etc/network/interfaces

auto eth0
iface eth0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
    MTU=1492

You can workaround this problem by specifying a command that should be run automatically after the interface comes up at the end of that interface section.

# nano /etc/network/interfaces

iface eth0 inet dhcp
      :
      :
    post-up /sbin/ifconfig eth0 mtu 1500

Then you need to either reboot or stop and restart the network.

Advertisements
This entry was posted in CentOS, Debian, Linux, Networking, Raspbian, RedHat, Ubuntu, Uncategorized. Bookmark the permalink.

2 Responses to Setting the network MTU size

  1. Luis Rueda says:

    If your interface has IPv6 configuration (which is enabled by default), you must also change IPV6_MTU= to new value otherwise it won’t work.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.