How to set MTU size in RHEL 7 and CentOS 7

Dear Friends in this tutorial we will how to set MTU size in Linux and we will also know what is MTU and why it MTU size is must for Linux? So, let’s start and see steps by steps this process.

What is MTU in Linux?

MTU stand for (Maximum Transmission Unit) it’s a size of largest protocol data unit that can communicated in single network layer transaction. MTU depends on underlying network capabilities and must be adjusted manually or automatically to not exceed these capabilities.

For more details about MTU you can Click Here

Why MTU size is must in Linux?

Large packets occupy a slow link for more time than a smaller packet, causing greater delays to subsequent packets, and increasing network delay and delay variation. For example, a 1500-byte packet, the largest allowed by Ethernet at the network layer, ties up a 14.4k modem for about one second.

How to set MTU size in Linux with ficonfig command?

We can set MTU using ifconfig command or ip command. If we don’t have ifconfig command and our Linux is base Operating System, then we can us ip command. Like below: –

First of we can check current MTU size with ifconfig commands.

[cloud-user@deploy-vm ~]$ sudo ifconfig -a
 docker0: flags=4099  mtu 1500
         inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
         ether 02:42:b8:9a:bd:62  txqueuelen 0  (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
 eth0: flags=4163  mtu 1600
         inet 10.10.10.13  netmask 255.255.255.0  broadcast 10.10.10.255
         inet6 fe80::f816:3eff:fea1:7bd9  prefixlen 64  scopeid 0x20

         ether fa:16:3e:a1:7b:d9  txqueuelen 1000  (Ethernet)
         RX packets 2  bytes 456 (456.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 20  bytes 2308 (2.2 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 eth1: flags=4163  mtu 1600
         inet 10.166.58.16  netmask 255.255.255.0  broadcast 10.166.58.255
         inet6 fe80::f816:3eff:fe96:cd52  prefixlen 64  scopeid 0x20

         ether fa:16:3e:96:cd:52  txqueuelen 1000  (Ethernet)
         RX packets 633  bytes 48331 (47.1 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 568  bytes 59074 (57.6 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 lo: flags=73  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 912  bytes 75951 (74.1 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 912  bytes 75951 (74.1 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 [cloud-user@deploy-vm ~]$

In above output you can see MTU size is 1600 on eth0 and eth1 interface. Now we need to set 1500 MTU on eth0 and eth1. So, we can use below commands.

[cloud-user@deploy-vm ~]$ sudo ifconfig eth0 mtu 1500
[cloud-user@deploy-vm ~]$ sudo ifconfig eth1 mtu 1500

Now we can verify with ifconfig command our changes is completed or not?

Set MTU size

You can see in above output we have successfully changed MTU size of eth0 and eth1 from 1600 to 1500 MTU.

How to set MTU with ip command?

If don’t have ifconfig tools, then we can use ip command to change MTU size like below.

First, we can verify current MTU size with IP command.

[cloud-user@deploy-vm ~]$ ip a
 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
 2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether fa:16:3e:a1:7b:d9 brd ff:ff:ff:ff:ff:ff
     inet 10.10.10.13/24 brd 10.10.10.255 scope global dynamic eth0
        valid_lft 84910sec preferred_lft 84910sec
     inet6 fe80::f816:3eff:fea1:7bd9/64 scope link
        valid_lft forever preferred_lft forever
 3: eth1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether fa:16:3e:96:cd:52 brd ff:ff:ff:ff:ff:ff
     inet 10.166.58.16/24 brd 10.166.58.255 scope global dynamic eth1
        valid_lft 84973sec preferred_lft 84973sec
     inet6 fe80::f816:3eff:fe96:cd52/64 scope link
        valid_lft forever preferred_lft forever
 4: docker0:  mtu 1500 qdisc noqueue state DOWN group default
     link/ether 02:42:b8:9a:bd:62 brd ff:ff:ff:ff:ff:ff
     inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
        valid_lft forever preferred_lft forever
 [cloud-user@deploy-vm ~]$

You can see in above output we have 1500 MTU in eth0 and eth1 interface.

Now I am going to change is from 1500 MTU to 1600 MTU with ip command like below: –

[cloud-user@deploy-vm ~]$
[cloud-user@deploy-vm ~]$ sudo ip link set mtu 1600 eth0
[cloud-user@deploy-vm ~]$ sudo ip link set mtu 1600 eth1
[cloud-user@deploy-vm ~]$

Now we can verify our MTU size is changed or not with ip a command like below: –

set MTU

You can see in above output we have successfully changed MTU size with ip command.

Now verify the MTU packet size with ping commands.

[root@urcloud ~]# ping -M do -s 8980 10.167.30.3
PING 10.167.30.3 (10.167.30.3) 8980(9008) bytes of data.
ping: local error: Message too long, mtu=9000
ping: local error: Message too long, mtu=9000
ping: local error: Message too long, mtu=9000
^C
--- 10.167.30.3 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 1999ms
[root@urcloud ~]# ping -M do -s 8960 10.167.30.3
PING 10.167.30.3 (10.167.30.3) 8960(8988) bytes of data.
8968 bytes from 10.167.30.3: icmp_seq=1 ttl=64 time=0.259 ms
8968 bytes from 10.167.30.3: icmp_seq=2 ttl=64 time=0.269 ms
8968 bytes from 10.167.30.3: icmp_seq=3 ttl=64 time=0.209 ms
^C
--- 10.167.30.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.209/0.245/0.269/0.031 ms
[root@urcloud ~]#

That’s all, in this tutorial we have seen how to set MTU in Linux.

Network configuration after CentOS 7 minimal installation

Leave a Reply