Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
DHCP Protocol 
3.
Setting Up a DHCP Server in Linux
3.1.
Step 1: Install DHCP Server
3.1.1.
For Ubuntu/Debian:
3.1.2.
For CentOS:
3.2.
Step 2: Configuration of DHCP Server
3.3.
Step 3: Configure Network Interfaces
3.4.
Step 4: Start and Enable DHCP Server
3.5.
Step 5: Firewall Configuration
3.6.
Step 6: Verify DHCP Server
4.
Frequently Asked Questions
4.1.
Is DHCP Secure?
4.2.
What is a DHCP Superscope?
4.3.
Can I Use DHCP in Conjunction with DNS?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

DHCP Server in Linux

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

A Dynamic Host Configuration Protocol (DHCP) server is a vital component of network infrastructure that automates the process of assigning IP addresses, subnet masks, gateway addresses, and other network parameters to devices on a local network. 

Dynamic host configuration protocol (DHCP) is a protocol used for providing Internet Protocol (IP) address and other necessary host configuration parameters such as network address, subnet mask, and default router dynamically to network devices correctly. 

IP address and other network parameters are needed to communicate with other devices and network services in the network. 

DHCP Server in Linux

Without DHCP in the network for providing the following network parameter, the situation can become time-consuming and inconvenient for completing a task. Network users must manually configure the IP address and other network parameters to their devices. 

Moreover, incorrect configuration will deny the device from accessing the network and services. That’s the reason why the DHCP server is one of the most important network infrastructures. In this article, we will learn about DHCP server setup in Linux.

DHCP Protocol 

DHCP has mostly been used as an implemented mechanism for automating assigned network configuration parameters of TCP/IP implementation systems. Network configuration parameters must be required for each device to communicate with other hosts in the network. General parameters include IP Address, Subnet Mask, IP Address of default gateway, IP Address of DNS Server, etc. 

Without using DHCP, a network administrator must manually assign those parameters to client devices, which becomes more time-consuming and causes inconvenience. Moreover, an incorrect configuration may cause network problems for each device and other technical aspects.

DHCP service for providing an IP address and other network configuration parameters to the client. Before accessing the internet, the client must authenticate via a webpage using credentials stored in the radius server.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Setting Up a DHCP Server in Linux

Step 1: Install DHCP Server

For Ubuntu/Debian:

Update the package

sudo apt update


Install the ISC DHCP server package

sudo apt install isc-dhcp-server


For CentOS:

Update the package

sudo yum update


Install the DHCP server package

sudo yum install dhcp

Step 2: Configuration of DHCP Server

After successful installation, the next step is to configure the DHCP server according to our requirements.

sudo nano /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.200;
    option routers 192.168.1.1;
    option domain-name "mydomain.local";
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    default-lease-time 600;
    max-lease-time 7200;
}

 

  • subnet: Specifies the subnet and netmask of your network.
  • range: Defines the range of IP addresses available for lease.
  • option routers: Sets the default gateway IP address.
  • option domain-name: Specifies the domain name for the network.
  • option domain-name-servers: Configures DNS server addresses.
  • default-lease-time and max-lease-time: Set the lease durations in seconds.


Save changes and close the text editor.

Step 3: Configure Network Interfaces

You must specify which network interface the DHCP server should listen on before allocating IP addresses. To list available interfaces, use the ifconfig or ip add commands.

sudo nano /etc/network/interfaces


The DHCP server interface can be configured by adding the following lines. Change eth0 to the name of your actual network interface, and change 192.168.1.1 to the IP address you want for your server:

# DHCP Server Interface Configuration
auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0


Save changes and close the text editor.

Step 4: Start and Enable DHCP Server

Start the DHCP server

sudo systemctl start isc-dhcp-server


Enable the DHCP server to start at boot

sudo systemctl enable isc-dhcp-server

Step 5: Firewall Configuration

sudo ufw allow in on eth0 to any port 67 proto udp
sudo ufw allow out on eth0 to any port 68 proto udp

Step 6: Verify DHCP Server

Check the status of the DHCP server service to ensure it's running

sudo systemctl status isc-dhcp-serve


Monitor the DHCP server logs

tail -f /var/log/syslog

Frequently Asked Questions

Is DHCP Secure?

There are no robust security mechanisms built into DHCP itself. To reduce security risks, best practices call for securing the DHCP server, employing DHCP relay agents, and putting DHCP snooping into practice.

What is a DHCP Superscope?

When a single DHCP server is responsible for providing services to several logical subnets, a DHCP superscope is employed. It enables the server to control IP allocations for various subnets.

Can I Use DHCP in Conjunction with DNS?

Yes, DHCP and DNS (Domain Name System) frequently cooperate. Client devices can resolve domain names to IP addresses by using DNS server addresses that DHCP can supply to them.

Conclusion

In this article, we learn about DHCP servers in Linux. We also learn about the DHCP protocol. We concluded the article by setting up DHCP Server in Linux.

To better understand the topic, refer to 

For more information, refer to our Guided Path on CodeStudio to upskill yourself in PythonData Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more! 

Head over to our practice platform, CodeStudio, to practice top problems, attempt mock tests, read interview experiences and interview bundles, follow guided paths for placement preparations, and much more!
Happy Learning!

Previous article
Linux - Server Administration
Next article
Linux - Error Codes
Live masterclass