How to change MTU setting permanently

Vor picture Vor · Oct 3, 2014 · Viewed 27k times · Source

I need to permanently change MTU to 1500. By permanently I mean if I reboot the system or will do service network restart it will alway be 1500.

I followed this article http://www.cyberciti.biz/faq/centos-rhel-redhat-fedora-debian-linux-mtu-size/

But unfortunately it doens't work for me.

Here is what I did:

check current MTU :

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000 

Added MTU="1500" to /etc/sysconfig/network-scripts/ifcfg-eth0:

[root@ip-xx-xx-xxx~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
IPV6_MTU="1500"
MTU="1500"

Then check MTU again, ( no luck ):

root@ip-xx-xx-xxx ~]# service network restart 
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  
Determining IP information for eth0... done.
                                                           [  OK  ]
[root@ip-xx-xx-xxx ~]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000

/sbin/ifconfig changed MTU but only temporally

[root@ip-xx-xx-xxx ~]# /sbin/ifconfig eth0 mtu 1500 up
[root@ip-xx-xx-xxx ~]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

If i restart network it is 9001 again:

[root@ip-xx-xx-xxx ~]# service network restart 
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  
Determining IP information for eth0... done.
                                                           [  OK  ]
[root@ip-10-0-1-135 ~]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000

Answer

danpan11 picture danpan11 · Oct 3, 2014

the MTU in your enviroment is being set automatically via the DHCP, in your configuration you have this setting:

DEVICE=eth0

BOOTPROTO=dhcp

So the DHCP is actually setting the MTU size. In Ubuntu, you can edit the following file: /etc/dhcp/dhclient.conf

Just BEFORE the request line set this two commands:

default interface-mtu 1500;

supercede interface-mtu 1500;

I don't know how to set it in Red Hat, but I think the file is called dhcpd.conf

Hope this helps!