Tutorials

Override DHCP Settings on CentOS

Table of Contents

Introduction

Using ProfitBricks' DHCP is a comfortable way to configure your VM's network interfaces. But sometimes there are situations where you don't want to use the provided values. A common use case is to override the current default MTU of 64000 for the public network interface. In this article we will see how this goal can be achieved on CentOS VMs that are set up with ProfitBricks default images.

Throughout this tutorial the public interface always is eth0. The VMs have an additional interface (eth1) which should be left untouched.

CentOS Configuration

On CentOS the procedure depends on the OS version. While the configuration on CentOS 6 is similar to Debian based systems, it is completely different on CentOS 7 due to the NetworkManager.

CentOS 6

Log in as root to the VM. Keep in mind, that you may get disconnected if you are logged in via SSH, so you may prefer using the remote console.

First, we look at the current configuration:

[root@centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 64000 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:01:6b:20:d7:e1 brd ff:ff:ff:ff:ff:ff
    inet 85.184.251.99/32 brd 85.184.251.99 scope global eth0
    inet6 fe80::1:6bff:fe20:d7e1/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 64000 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:01:92:b2:c3:0d brd ff:ff:ff:ff:ff:ff
    inet 10.10.240.11/24 brd 10.10.240.255 scope global eth1
    inet6 fe80::1:92ff:feb2:c30d/64 scope link
       valid_lft forever preferred_lft forever

On CentOS 6 the DHCP client configuration is located in interface specific files. For the public interface eth0 the configuration file is /etc/dhcp/dhclient-eth0.conf. Since this is valid for eth0only, we can simply add the line

supersede interface-mtu 1500;

to this file.

To activate the changed configuration you only need to restart the interface:

[root@centos ~]# ifdown eth0; ifup eth0

Remember that this may disconnect you if you are logged in via SSH.

If you are using service network reload like you would do for Debian, you will encounter some oddities. Besides our configured interfaces eth0and eth1 the image also contains network scripts for eth2 to eth7. Reloading the network service will also execute these scripts and result in errors like

Bringing up interface eth2:  Device eth2 does not seem to be present, delaying initialization.
                                                           [FAILED]

Finally, we can verify that the change is applied:

[root@centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:01:6b:20:d7:e1 brd ff:ff:ff:ff:ff:ff
    inet 85.184.251.99/32 brd 85.184.251.99 scope global eth0
    inet6 fe80::1:6bff:fe20:d7e1/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 64000 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:01:92:b2:c3:0d brd ff:ff:ff:ff:ff:ff
    inet 10.10.240.11/24 brd 10.10.240.255 scope global eth1
    inet6 fe80::1:92ff:feb2:c30d/64 scope link
       valid_lft forever preferred_lft forever

CentOS 7

Log in as root to the VM via SSH or the remote console.

Due to the NetworkManager the configuration on CentOS 7 is completely different from the procedure we have used before.

The configuration is based on connection profiles. You can list these profiles as follows:

[root@centos ~]# nmcli connection show
NAME         UUID                                  TYPE            DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  eth0
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  eth1
System eth2  3a73717e-65ab-93e8-b518-24f5af32dc0d  802-3-ethernet  --
System eth3  c5ca8081-6db2-4602-4b46-d771f4330a6d  802-3-ethernet  --
System eth4  84d43311-57c8-8986-f205-9c78cd6ef5d2  802-3-ethernet  --
System eth5  d9ced338-a402-60eb-c131-0fd3ab4b5ab7  802-3-ethernet  --
System eth6  9c7edaaf-a235-841d-64a7-66502d9706e9  802-3-ethernet  --
System eth7  1e690eec-2d2c-007e-535f-a873a2b375d5  802-3-ethernet  --

The profiles "System eth0" and "System eth1" are related to our existing interfaces and active. The properties of our connection for eth0 can be examined by running:

[root@centos ~]# nmcli connection show "System eth0"
connection.id:                          System eth0
connection.uuid:                        5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
connection.stable-id:                   --
connection.interface-name:              eth0
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
  [..snip..]
802-3-ethernet.mtu:                     auto
  [..snip..]
ipv4.method:                            auto
  [..snip..]
GENERAL.STATE:                          activated
  [..snip..]
IP4.ADDRESS[1]:                         85.184.251.99/32
  [..snip..]
DHCP4.OPTION[25]:                       interface_mtu = 64000
  [..snip..]

You can directly modify the MTU for eth0 by invoking:

 [root@centos ~]# nmcli connection modify "System eth0" ethernet.mtu 1500

In this command, ethernet.mtu is an alias for the property 802-3-ethernet.mtu you can see in the abridged output above.

If you are trying to restart the network service by running systemctl restart network you will encounter an error. The reason is the same as mentioned for CentOS 6: Interfaces eth2 to eth7 are defined in the networking scripts but do not really exist.

Instead, you can simply execute:

 [root@centos ~]# ifdown eth0; ifup eth0

or use nmcli:

    [root@centos ~]# nmcli connection down "System eth0"
    [root@centos ~]# nmcli connection up "System eth0" ifname eth0

Again, remember that this may disconnect you if you are logged in via SSH.

 
Log In, Add a Comment