In Linux, how to setup the MTU for network interface

MTU (Maximum Transmission Unit) is related to TCP/IP networking in Linux/BSD/UNIX. It refers to the size (in bytes) of the largest datagram that a given layer of a communications protocol can pass at a time.

 

You can see current MTU setting with ifconfig command under Linux:

# /sbin/ifconfig

Output:

eth0      Link encap:Ethernet  HWaddr 00:0F:EA:91:04:07
         inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
         inet6 addr: fe80::20f:eaff:fe91:407/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:141567 errors:0 dropped:0 overruns:0 frame:0
         TX packets:141306 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:101087512 (96.4 MiB)  TX bytes:32695783 (31.1 MiB)
         Interrupt:18 Base address:0xc000

A better way is to use ip command:

$ ip link list

Output:

1: lo:  mtu 16436 qdisc noqueue
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:  mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:0f:ea:91:04:07 brd ff:ff:ff:ff:ff:ff
3: sit0:  mtu 1480 qdisc noop
   link/sit 0.0.0.0 brd 0.0.0.0

As you see, MTU set to 1500 for eth0. Let us say you want this to 1400 then you can use any one of the following command to setup MTU:

# ifconfig eth0 mtu 1400

OR

# ip link set dev eth0 mtu 1400

Verify that new mtu is setup with following command:

$ ip link list

OR

$ /sbin/ifconfig

To make the setting permanent for eth0, edit the configuration file:
/etc/network/interfaces (Debian Linux file)

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
name Ethernet LAN card
address 192.168.1.10
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.254
mtu 1400
post-up /etc/fw.start
post-down /etc/fw.stop

/etc/sysconfig/network-scripts/ifcfg-eth0 (Red Hat Linux )

DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:0F:EA:91:04:07
IPADDR=192.168.1.10
NETMASK=255.255.255.0
NETWORK=192.168.1.0
MTU=1400
ONBOOT=yes
TYPE=Ethernet

Save the file and restart network service

If you are using Redhat:

# service network restart

If you are using Debian:

# /etc/init.d/networking restart