How To Install A DHCP Server in Ubuntu and Debian

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

How to Install a DHCP Server in

Ubuntu and Debian


Source :
https://www.tecmint.com/install-dhcp-server-in-ubuntu-debian/

Dynamic Host Configuration Protocol (DHCP) is a network protocol that is used to


enable host computers to be automatically assigned IP addresses and related network
configurations from a server.
The IP address assigned by a DHCP server to DHCP client is on a “lease”, the lease
time normally varies depending on how long a client computer is likely to require the
connection or DHCP configuration.

How Does DHCP Work?


The following is a quick description of how DHCP actually works:

 Once a client (that is configured to use DHCP) and connected to a network boots
up, it sends a DHCPDISCOVER packet to the DHCP server.
 When the DHCP server receives the DHCPDISCOVER request packet, it replies
with a DHCPOFFER packet.
 Then the client gets the DHCPOFFER packet, and it sends
a DHCPREQUEST packet to the server showing it is ready to receive the network
configuration information provided in the DHCPOFFER packet.
 Finally, after the DHCP server receives the DHCPREQUEST packet from the
client, it sends the DHCPACK packet showing that the client is now permitted to
use the IP address assigned to it.

In this article, we will show you how to setup a DHCP server in Ubuntu/Debian
Linux, and we will run all the commands with the sudo command to gain root user
privileges.
Step 1: Installing DHCP Server in Ubuntu
1. Run the command below to install the DCHP server package, which was formerly
known as dhcp3-server.

$ sudo apt install isc-dhcp-server

2. When the installation completes, edit the file /etc/default/isc-dhcp-server to define


the interfaces DHCPD should use to serve DHCP requests, with the INTERFACES
option.
For example, if you want the DHCPD daemon to listen on eth0 , set it like so:

INTERFACES="eth0"

And also remember to configure a static IP address for the interface above.

Step 2: Configuring DHCP Server in Ubuntu


3. The main DHCP configuration file is /etc/dhcp/dhcpd.conf , you must add all
your network information to be sent to clients here.
And, there are two types of statements defined in the DHCP configuration file, these
are:

 parameters – specify how to perform a task, whether to carry out a task, or what
network configuration options to send to the DHCP client.
 declarations – define the network topology, state the clients, offer addresses for
the clients, or apply a group of parameters to a group of declarations.
4. Now, open and modify the main configuration file, define your DHCP server
options:
$ sudo nano /etc/dhcp/dhcpd.conf

Set the following global parameters at the top of the file, they will apply to all the
declarations below (do specify values that apply to your scenario):

option domain-name "labjarkom.pens.ac.id";


default-lease-time 3600;
max-lease-time 7200;
authoritative;

5. Now, define a subnetwork; here, we’ll setup DHCP for 192.168.10.0/24 LAN
network (use parameters that apply to your scenario).

subnet 10.252.108.0 netmask 255.255.255.0 {

option routers 10.252.108.1;


option subnet-mask 255.255.255.0;
option domain-search "pens.ac.id";
option domain-name-servers 202.9.85.3;
range 10.252.108.100 10.252.108.200;
}

Step 3: Configure Static IP on DHCP Client Machine


6. To assign a fixed (static) IP address to a particular client computer, add the section
below where you need to explicitly specify it’s MAC addresses and the IP to be
statically assigned:

host komputerku {

hardware ethernet 00:f0:m4:6y:89:0g;

fixed-address 10.252.108.123;

host komputermu {

hardware ethernet 00:4g:8h:13:8h:3a;


fixed-address 10.252.108.124;

Save the file and close it.

7. Next, start the DHCP service for the time being, and enable it to start automatically
from the next system boot, like so:
------------ SystemD ------------
$ sudo systemctl start isc-dhcp-server.service
$ sudo systemctl enable isc-dhcp-server.service
------------ SysVinit ------------
$ sudo service isc-dhcp-server.service start
$ sudo service isc-dhcp-server.service enable

8. Next, do not forget to permit DHCP service (DHCPD daemon listens on port
67/UDP) on firewall as below:

$ sudo ufw allow 67/udp

$ sudo ufw reload

$ sudo ufw show

Step 4: Configuring DHCP Client Machines


9. At this point, you can configure your clients computers on the network to
automatically receive IP addresses from the DHCP server.
Login to the client computers and edit the Ethernet interface configuration file as
follows (take note of the interface name/number):

$ sudo vi /etc/network/interfaces

And define the options below:

auto eth0

iface eth0 inet dhcp

Save the file and exit. And restart network services like so (or reboot the system):
------------ SystemD ------------
$ sudo systemctl restart networking
------------ SysVinit ------------
$ sudo service networking restart

You might also like