How to install and configure DHCP server on Ubuntu
Table of Contents
Introduction
This tutorial provides a step-by-step guide on how to install and configure a DHCP server on an Ubuntu machine. Setting up a DHCP server allows your network devices to automatically receive IP addresses and other network configuration parameters, simplifying network administration.
Step 1: Search for DHCP Software
Before installation, ensure you have access to the DHCP server software. The DHCP server for Ubuntu is called isc-dhcp-server
.
- Open the terminal on your Ubuntu machine.
- Update your package list with the following command:
sudo apt update
- Search for the DHCP server package to confirm it's available:
apt search isc-dhcp-server
Step 2: Install DHCP Server
Once you've confirmed the availability of the DHCP server software, you can proceed with the installation.
- Install the DHCP server by running:
sudo apt install isc-dhcp-server
Step 3: Confirm that DHCP is Up and Running
After installation, verify that the DHCP server is functioning correctly.
- Check the status of the DHCP server with:
sudo systemctl status isc-dhcp-server
- If it is running, you should see an "active (running)" status. If not, you may need to start it with:
sudo systemctl start isc-dhcp-server
Step 4: Change the Default Configuration
The DHCP server comes with a default configuration that may not meet your needs. You will need to modify it.
- Open the DHCP configuration file in a text editor:
sudo nano /etc/dhcp/dhcpd.conf
- Configure the following parameters as needed:
- Define the subnet and netmask.
- Specify the range of IP addresses to be assigned.
- Set the default gateway and DNS servers.
Example configuration:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
- Save the changes and exit the editor.
Step 5: Stop and Start the DHCP Server
To apply the new configuration, restart the DHCP server.
- Stop the DHCP service:
sudo systemctl stop isc-dhcp-server
- Then, start it again:
sudo systemctl start isc-dhcp-server
Step 6: Test the DHCP Server
Finally, test the DHCP server to ensure that it is assigning IP addresses correctly.
- Connect a device to the network that should receive an IP address from the DHCP server.
- Verify that the device receives an IP address within the specified range using:
ip addr show
- Check the DHCP leases file on your server for confirmation:
cat /var/lib/dhcp/dhcpd.leases
Conclusion
You have successfully installed and configured a DHCP server on Ubuntu. By following these steps, your network devices should now be able to automatically obtain their IP configurations. For further networking tasks, consider exploring additional configurations or integrating other services to enhance your network management capabilities.