How to install DHCP server on Ubuntu Server 18.04 LTS

Post Reply
User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

How to install DHCP server on Ubuntu Server 18.04 LTS

Post: # 682Post LHammonds
Tue Aug 07, 2018 8:45 am

WORK-IN-PROGRESS ------------------- WORK-IN-PROGRESS
WORK-IN-PROGRESS ------------------- WORK-IN-PROGRESS

Greetings and salutations,

I hope this thread will be helpful to those who follow in my foot steps as well as getting any advice based on what I have done / documented.

To discuss this thread, please participate here: Ubuntu Forums >>need to create thread<<

High-level overview

Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a server to automatically assign an IP address to a computer from a defined range of numbers (i.e., a scope) configured for a given network.

This tutorial will cover how to install the DHCP service and configure it for a single network with various options.

The server will be installed inside a virtual machine in vSphere running on ESXi servers. Notes will also be supplied for doing the same thing for VirtualBox on a Windows 10 PC. Although there are some VMware-specific and VirtualBox-specific steps, they are very few and the majority of this documentation will work for other Virtual Machines or even directly installed onto a physical machine (e.g. bare-metal install). If you have any advice on doing things better, please let me know by replying to the Ubuntu forums thread above.

Tools utilized in this process
Helpful links

The list below are sources of information that was helpful in the creation of this document.
Assumptions

This documentation will need to make use of some very-specific information that will most-likely be different for each person / location. And as such, this information will be noted in this section. They will be highlighted in red throughout the document as a reminder that you should plug-in your own value rather than actually using these "place-holder" values.

Under no circumstance should you use the actual values listed below. They are place-holders for the real thing. This is just a checklist template you need to have answered before you start the install process.

Wherever you see the below variables in this document (typically in RED), you need to substitute it for you will use in your environment.
  • Ubuntu Server name: srv-dhcp
  • Ubuntu Server IP address: 192.168.107.13
  • Ubuntu Admin ID: administrator
  • Ubuntu Admin Password: myadminpass
  • Local Domain: mydomain.local
  • DHCP Range: 192.168.107.50 to 192.168.107.100
  • Default Gateway: 192.168.107.1
  • Internal DNS Server: 192.168.107.1
  • External DNS Server #1: 1.1.1.1 (CloudFare)
  • External DNS Server #2: 8.8.8.8 (Google)
Ubuntu Server - Setup an Ubuntu server for use as the DHCP server. This tutorial assumes the server was configured according to this tutorial: How to install and configure Ubuntu Server

It is also assumed the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Install DHCP Server

Post: # 683Post LHammonds
Tue Aug 07, 2018 9:40 am

Install DHCP Server
  1. Start PuTTY and connect to your server with your administrator account and type the following:

    Code: Select all

    sudo apt update
    sudo apt install isc-dhcp-server
  2. Here is the default configuration file at /etc/dhcp/dhcpd.conf (most of it is commented out with the # character at the beginning of the line)

    Code: Select all

    # dhcpd.conf
    #
    # Sample configuration file for ISC dhcpd
    #
    
    # option definitions common to all supported networks...
    option domain-name "example.org";
    option domain-name-servers ns1.example.org, ns2.example.org;
    
    default-lease-time 600;
    max-lease-time 7200;
    
    # The ddns-updates-style parameter controls whether or not the server will
    # attempt to do a DNS update when a lease is confirmed. We default to the
    # behavior of the version 2 packages ('none', since DHCP v2 didn't
    # have support for DDNS.)
    ddns-update-style none;
    
    # If this DHCP server is the official DHCP server for the local
    # network, the authoritative directive should be uncommented.
    #authoritative;
    
    # Use this to send dhcp log messages to a different log file (you also
    # have to hack syslog.conf to complete the redirection).
    #log-facility local7;
    
    # No service will be given on this subnet, but declaring it helps the
    # DHCP server to understand the network topology.
    
    #subnet 10.152.187.0 netmask 255.255.255.0 {
    #}
    
    # This is a very basic subnet declaration.
    
    #subnet 10.254.239.0 netmask 255.255.255.224 {
    #  range 10.254.239.10 10.254.239.20;
    #  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
    #}
    
    # This declaration allows BOOTP clients to get dynamic addresses,
    # which we don't really recommend.
    
    #subnet 10.254.239.32 netmask 255.255.255.224 {
    #  range dynamic-bootp 10.254.239.40 10.254.239.60;
    #  option broadcast-address 10.254.239.31;
    #  option routers rtr-239-32-1.example.org;
    #}
    
    # A slightly different configuration for an internal subnet.
    #subnet 10.5.5.0 netmask 255.255.255.224 {
    #  range 10.5.5.26 10.5.5.30;
    #  option domain-name-servers ns1.internal.example.org;
    #  option domain-name "internal.example.org";
    #  option routers 10.5.5.1;
    #  option broadcast-address 10.5.5.31;
    #  default-lease-time 600;
    #  max-lease-time 7200;
    #}
    
    # Hosts which require special configuration options can be listed in
    # host statements.   If no address is specified, the address will be
    # allocated dynamically (if possible), but the host-specific information
    # will still come from the host declaration.
    
    #host passacaglia {
    #  hardware ethernet 0:0:c0:5d:bd:95;
    #  filename "vmunix.passacaglia";
    #  server-name "toccata.example.com";
    #}
    
    # Fixed IP addresses can also be specified for hosts.   These addresses
    # should not also be listed as being available for dynamic assignment.
    # Hosts for which fixed IP addresses have been specified can boot using
    # BOOTP or DHCP.   Hosts for which no fixed address is specified can only
    # be booted with DHCP, unless there is an address range on the subnet
    # to which a BOOTP client is connected which has the dynamic-bootp flag
    # set.
    #host fantasia {
    #  hardware ethernet 08:00:07:26:c0:a5;
    #  fixed-address fantasia.example.com;
    #}
    
    # You can declare a class of clients and then do address allocation
    # based on that.   The example below shows a case where all clients
    # in a certain class get addresses on the 10.17.224/24 subnet, and all
    # other clients get addresses on the 10.0.29/24 subnet.
    
    #class "foo" {
    #  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
    #}
    
    #shared-network 224-29 {
    #  subnet 10.17.224.0 netmask 255.255.255.0 {
    #    option routers rtr-224.example.org;
    #  }
    #  subnet 10.0.29.0 netmask 255.255.255.0 {
    #    option routers rtr-29.example.org;
    #  }
    #  pool {
    #    allow members of "foo";
    #    range 10.17.224.10 10.17.224.250;
    #  }
    #  pool {
    #    deny members of "foo";
    #    range 10.0.29.10 10.0.29.230;
    #  }
    #}
    

User avatar
LHammonds
Site Admin
Site Admin
Posts: 679
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Configure DHCP Server

Post: # 684Post LHammonds
Tue Aug 07, 2018 10:04 am

Configure DHCP Settings
  1. Backup the default config file:

    Code: Select all

    sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.bak
  2. Edit the DHCP configuration file:

    Code: Select all

    sudo vi /etc/dhcp/dhcpd.conf
  3. Set the following, save and close:

    Code: Select all

    # dhcpd.conf
    
    authoritative;
    default-lease-time 600;
    max-lease-time 7200;
    ddns-update-style none;
    option domain-name "mydomain.local";
    option domain-name-servers 192.168.107.1, 1.1.1.1, 8.8.8.8;
    
    subnet 192.168.107.0 netmask 255.255.255.0 {
      range 192.168.107.50 192.168.107.100;
      option routers 192.168.107.1;
      option broadcast-address 192.168.107.255;
    }
    ## Define reserved IP assignments. e.g. Static IP
    host srv-dc1 {
      hardware ethernet 08:00:07:26:c0:a5;
      fixed-address 192.168.107.99;
    }
    host srv-dc2 {
      hardware ethernet 08:00:07:26:c0:a6;
      fixed-address 192.168.107.98;
    }
    
Enable DHCP for the correct interface
  1. Look for the "Iface" name that matches the interface you want to use for DHCP (eth0 in this example):

    Code: Select all

    # ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.107.13  netmask 255.255.255.0  broadcast 192.168.107.255
            ether b8:27:eb:fc:8a:33  txqueuelen 1000  (Ethernet)
            RX packets 15757  bytes 14331651 (13.6 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 9441  bytes 1146596 (1.0 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.108.2  netmask 255.255.255.0  broadcast 192.168.108.255
            ether b8:27:eb:fc:8a:33  txqueuelen 1000  (Ethernet)
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 10  bytes 440 (440.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 10  bytes 440 (440.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
  2. Enable DHCP for the correct interface by editing the default isc-dhcp-server file:

    Code: Select all

    sudo vi /etc/default/isc-dhcp-server
    change:

    Code: Select all

    INTERFACESv4=""
    to:

    Code: Select all

    INTERFACESv4="eth0"
  3. Restart the DHCP service:

    Code: Select all

    sudo systemctl restart isc-dhcp-server

Post Reply