Install and Configure DHCP Server on Debian 8/7/6 Linux Systems

undefined

In this post, we will show you how to install and configure a dhcp server on Linux systems (Debian Family “Debian 8 “jessie” /7/6 and earlier – Ubuntu Linux”). As a system administrator you will need to setup a dhcp server to assign IPs to all laptops/machines for employees to work inside your network.

DHCP ( Dynamic Host Configuration Protocol ) is a network protocol used for assigning IP address to network clients dynamically from predefined IP pool. It is useful for LAN network, but not generally used for production servers. This article will help you for Configuring DHCP Server on Debian, Ubuntu Systems.

Our installation and configuration will be in 3 main steps and 2 extra steps. So let’s start.

Step 1: Install the DHCP Server’s Package.

We will use apt-get package manager to install the DHCP package  on  our Debian 8. Only one command for the all releases of Debian/Ubuntu Linux systems.

# apt-get update 
# apt-get -y install isc-dhcp-server 

Step 2: Configure the DHCP Server.

DHCP creates a configuration file located at /etc/dhcp/dhcpd.conf. Also it provides a sample configuration file at /usr/share/doc/isc-dhcp-server/examples/dhcpd.conf.example, which is very useful and you should take a look at it before configuring your dhcp server.

Now, we will edit the dhcpd.conf with our network parameters.

# vim /etc/dhcp/dhcpd.conf

We will change the following parameters. For simplicity, I separated them into three blocks:

2.1 – Parameter Configuration

First configure the basic options which is common to all supported networks.

  option domain-name "mimastech.com";
  option domain-name-servers 8.8.8.8, 8.8.4.4;
  default-lease-time 28800;
  max-lease-time 36000;
  authoritative;
  log-facility local7;

2.2 – IP Subnet Declaration

First edit dhcp configuration file and update subnet details as per your network. For this example we are configuring DHCP for 192.168.1.0/24 LAN network.

subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;
        option domain-search            "mimastech.com";
        range   192.168.1.100   192.168.1.254;
}

2.3 -Assign Static IP Address to Host

In some cases we need to assign a fixed ip to an interface each time it requested from dhcp. We can also assign a fixed ip on basis of MAC address (hardware ethernet) of that interface. Setup host-name is optional to set up.

host vip {
   option host-name "vip.mimastech.com";
   hardware ethernet 00:13:1A:2B:AE:CD;
   fixed-address 192.168.1.99;
}

Step 3: Enable and Start DHCP Service

After making all above changes, let’s enable and start dhcp service using following commands as per your operating system version.

  • For Debian 8 / latest Ubuntu releases
# systemctl enable isc-dhcp-server  
# systemctl restart isc-dhcp-server
  • For Debian 7/6 and Ubuntu 14.04 and earlier
# chkconfig isc-dhcp-server on 
# service isc-dhcp-server restart

Extra Steps:

Step 4: Setup Client System

At this stage we have a running dhcp server which is ready for accepting requests and assign them a proper ip. but to verify I have another Debian machine running on same LAN. Now login to that client machine and edit interfaces configuration file.

# vim /etc/network/interfaces
auto eth0
iface eth0 inet dhcp

Let’s restart network services on client system. You will get that dhcp server assigned an ip address from defined subnet. If you have connected to client pc from remote login, Your session can be disconnect.

  • For Debian 8 / latest Ubuntu releases
# systemctl restart isc-dhcp-server
  • For Debian 7/6 and Ubuntu 14.04 and earlier
# service isc-dhcp-server restart
Hints: 	
1. By default dhcp server is listening to the first NIC card which is eth0 "in most Debian/Ubuntu Linux"
2. To change the dhcp server to listen to another NIC interface you need to edit /etc/default/isc-dhcp-server

Step 5: Updating  /etc/default/isc-dhcp-server File

As I said in the above hint, according to your internal LAN infrastructure, you may want the dhcp server to listen on another NIC interface. To do that, you need to set Ethernet interface name as INTERFACES in /etc/default/isc-dhcp-server file. Edit this configuration file and update the Ethernet name.

 INTERFACES="eth1"

Here’s we changed the dhcp server to listen on connections coming to eth1. We must restart the dhcp service for our changes to take effect.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *