DHCP CONFIGURATION
SANGAY CHHOPHEY (05230128)
Setting Up a DHCP Server:
A DHCP server is a network service that automatically assigns IP addresses, gateway
information, DNS addresses, and other network settings to client devices. When a device
connects, it requests an IP address from the server, which responds through the DORA
process (Discovery, Offer, Request, Acknowledge), enabling network communication.
Manually configuring network clients is time-consuming and prone to errors, especially
in large networks. A DHCP server streamlines this process by automatically assigning
and renewing IP addresses, which are leased to clients for a specific period rather than
being permanently assigned.
Static and Dynamic Hosts:
If a computer is using a static IP address, it means that the IP has been manually set by
an administrator or user. This manual configuration can sometimes lead to accidental IP
conflicts, where two devices are assigned the same IP address. To avoid such issues, a
DHCP server is typically implemented. However, there are situations where using a static
IP address is essential.
Static IP addresses are typically reserved for network devices that require a consistent
address, such as servers, routers, and switches, where the IP must remain unchanged for
reliable operation.
1
Network Details:
We will now use our virtual network to implement the DHCP server. The server will be
assigned an IP address of 172.168.30.2/24. We will configure our server so that it assigns
client devices IP addresses ranging from 172.168.30.11 to 172.168.30.20.
Considering the DHCP server information given in the figure above, start the devices in
the GNS3. After the devices are started, log in to your CentOS-DHCP-Srv.
2
Installing the DHCP Package:
Before assigning a static IP address to the DHCP server, it's important to connect the
system to the internet to download necessary packages. Ensure that your CentOS DHCP
server is connected to the internet. If it's not, you can use the dhclient command to
obtain an IP address.
Once the system is connected, you can proceed to install the DHCP package using the
YUM (Yellow Dog Updater, Modified) package manager. The following command will
install the DHCP package along with all its dependencies:
# yum install dhcp –y
# dnf install dhcp-server
Configuring DHCP Server:
After successfully installing, DHCP creates an empty configuration file
/etc/dhcp/dhcpd.conf. In addition, it also creates a sample configuration file in
/usr/share/doc/dhcp4.2.5/dhcpd.conf.example which can be used to configure the
DHCP service. So, if you want to copy the contents from this file to the empty file, you
can do the following command but this step is optional.
# vim /etc/dhcp/dhcpd.conf
The interface as shown in the figure below should welcome you after executing the
command.
3
Parameters:
After opening the file, first configure the basic options which is common to all
supported networks
as shown below. The lease time for IP address is in minutes.
option domain-name “csn.local”;
option domain-name-servers 172.268.30.3, 192.168.255.227;
default-lease-time 600;
max-lease-time 7200;
authoritative;
IP Subnet:
After that, we will specify the subnet details as per our network requirement. For this
session, we are configuring the DHCP for 172.168.30.0/24 network (LAN) to assign IP
addresses ranging from
172.168.30.11 to 172.168.30.20 to the clients.
subnet 172.168.30.0 netmask 255.255.255.0 {
option routers 172.168.30.1;
option subnet-mask 255.255.255.0;
option domain-search “csn.local”;
option domain-name-servers 172.168.30.3, 192.168.255.227;
range 172.168.30.11 172.168.30.20;
4
Static IP address to Host:
There are some cases where we have to assign a fixed IP address to an interface every
time it is requested from the DHCP. We can do this on the basis of MAC address
(hardware Ethernet) of that interface. In this session we will assign fixed IP address to the
interface (Windows10) with
08:00:27:C5:E2:32 MAC address. We have to add the following details to the file.
host Windows10 {
hardware Ethernet 08:00:27:C5:E2:32;
fixed-address 172.168.30.12:
Considering that every detail is being configured, the file must contain the following
parameters.
5
Assigning Static IP address to the server: Before we start the DHCP service on the server,
we have to assign static IP address because we have dynamic IP address for now. To
assign static, we will make use to nmtui utility. We will set the hostname as shown in the
figure below. You have to use the arrow keys to navigate through the interface.
We will now configure the IP address details of the server and make sure to tick
Automatically connect button as shown in the figure below.
6
Once the IP address is being configured, make sure that you can connect to the routers
IP address (172.168.30.2).
Start and Enable DHCP service:
7
Now that all the required packages are installed and all the IP details are configured, it is
now
time to start the DHCP service on the server.
# systemctl enable dhcpd
# systemctl start dhcpd
If everything is configured correctly, the service should start without any error as shown
in the figure below. If it is configured correctly there won’t be any message on the
terminal but in case of error, message will be displayed on the terminal. Make sure the
spellings are correct in the configuration file. Rectify the error and run the DHCP service.
Client Device:
It is finally time to add client to the network and test the functionality of the service. As
per our configuration, the server must assign IP address anywhere between
172.168.30.11 to 172.168.30.20. In my case the client device is Windows 10 and let’s
verify whether the IP address is assigned correctly. Make sure you client device is not
assigned IP address statically.
We saw that the IP address is assigned correctly from the range we specified in the
configuration file. We will now take our verification to the next level by connecting both
router and DHCP server from the client device.
8
9