Tutorials

Override DHCP Settings on Debian

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 Debian based 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.

Debian Configuration

On all Debian based systems the configuration follows the same procedure. This was tested with Debian 9, Debian 8, and Ubuntu 16.04.

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@debian:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 64000 qdisc pfifo_fast state UP group default 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
       valid_lft forever preferred_lft forever
    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 group default 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
       valid_lft forever preferred_lft forever
    inet6 fe80::1:92ff:feb2:c30d/64 scope link
       valid_lft forever preferred_lft forever

To override the MTU of eth0 we only need to add the following lines to /etc/dhcp/dhclient.conf:

interface "eth0" {
 supersede interface-mtu 1500;
}

The supersede statement overrides the value provided by DHCP. To restrict this to only the public interface eth0 the statement must be enclosed in an interface declaration.

To activate the changed setting you just reload the network:

root@debian:~# service networking reload

That is the only command required. The network configuration is now changed for eth0 while eth1is left as is:

root@debian:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default 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
       valid_lft forever preferred_lft forever
    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 group default 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
       valid_lft forever preferred_lft forever
    inet6 fe80::1:92ff:feb2:c30d/64 scope link
       valid_lft forever preferred_lft forever

If you are curious about the DHCP properties that are processed by dhclient you could dump these out by adding the following lines at the beginning of /sbin/dhclient-script:

mylog=/tmp/dhc-log
echo "## START ##" >> $mylog
date >> $mylog
env|sort >> $mylog
echo "## END ##" >> $mylog

This will write the old and the new values into /tmp/dhc-log like this:

## START ##
Mon May  7 11:57:32 UTC 2018
PATH=/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin
PWD=/
interface=eth0
  [..snip..]
new_interface_mtu=1500
  [..snip..]
old_interface_mtu=64000
  [..snip..]
pid=1035
reason=BOUND
  [..snip..]

 
Log In, Add a Comment