As a system administrator in a large environment, setting up new client systems and manually assigning IP addresses and network-related information can be a time-consuming process. This is where DHCP, or “Dynamic Host Configuration Protocol,” comes into play. DHCP is a service that dynamically assigns unique IP addresses and other information to client systems, making the process of network configuration more efficient. In this article, we will guide you through the installation and configuration of a DHCP Server and Client on Ubuntu 20.04, empowering you with the knowledge to streamline your network setup process.
Prerequisites
Before we dive into the installation and configuration process, let’s ensure that you have everything you need. Here are the prerequisites for setting up a DHCP Server on Ubuntu 20.04:
- Two systems running Ubuntu 20.04.
- A root password configured on the server.
Install DHCP Server
To get started, we need to install the DHCP server package. Fortunately, it is included in the default Ubuntu repository. Open your terminal and enter the following command to install the DHCP server:
apt-get install isc-dhcp-server -y
Once the installation is complete, start the DHCP service and enable it to start at system reboot by executing the following command:
systemctl start isc-dhcp-server systemctl enable isc-dhcp-server
Configure DHCP Service
Now that the DHCP server is installed, we need to configure it to define your network interface. The default configuration file for the DHCP server is located at /etc/default/isc-dhcp-server
. Open the file using your preferred text editor:
nano /etc/default/isc-dhcp-server
In this file, you will need to define your network interface. Locate the line that begins with INTERFACESv4
and modify it to reflect your network interface. For example, if your network interface is eth0
, the line should look like this:
INTERFACESv4="eth0"
Save and close the file. Next, we will edit the DHCP server configuration file located at /etc/dhcp/dhcpd.conf
:
nano /etc/dhcp/dhcpd.conf
In this file, you can define various DHCP lease options such as default lease time, maximum lease time, subnet range, gateway address, and DNS server address. Uncomment the line that says authoritative;
to make this DHCP server authoritative for the specified subnet.
authoritative;
Modify the following lines according to your network configuration:
default-lease-time 660;
max-lease-time 6300;
range 192.168.0.2 192.168.0.20;
option routers 192.168.0.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
Save and close the file.
Configure DHCP Server to Assign Static IP to Client
By default, the DHCP server assigns dynamic IP addresses to all clients. However, in some cases, you may want to assign a fixed IP address to a specific client based on its MAC address. To do so, follow these steps:
- Open the DHCP server configuration file:
nano /etc/dhcp/dhcpd.conf
- Add the following lines to assign a static IP address to the client with the specified MAC address:
host client1 { hardware ethernet 4c:bb:58:9c:f5:55; fixed-address 192.168.0.5; }
Make sure to replace 4c:bb:58:9c:f5:55
with the MAC address and 192.168.0.5
with the desired static IP address.
- Save and close the file.
- Restart the DHCP service to apply the changes:
systemctl restart isc-dhcp-server
Configure DHCP Client to Obtain Static IP address
To configure a client machine to obtain a static IP address from the DHCP server, follow these steps:
- Access the client machine with the specified MAC address:
nano /etc/network/interfaces
- Remove the default lines and add the following lines:
auto eth0 iface ens33 inet static address 192.168.0.5 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 8.8.8.8 8.8.4.4
Make sure to replace 192.168.0.5
with the desired static IP address, 255.255.255.0
with the appropriate netmask, 192.168.0.1
with the gateway address, and 8.8.8.8 8.8.4.4
with the DNS server addresses.
- Save and close the file.
- Restart the Network Manager service to apply the changes:
systemctl restart network-manager
- Verify the IP address of the client machine:
ifconfig
You should see the configured static IP address in the output.
Configure DHCP Client to Obtain Dynamic IP address
If you want a client machine to obtain its IP address automatically from the DHCP server, follow these steps:
- Access the client machine:
nano /etc/network/interfaces
- Add the following lines:
auto eth0 iface eth0 inet dhcp
- Save and close the file.
- Restart the Network Manager service to apply the changes:
systemctl restart network-manager
- Verify the IP address assigned by the DHCP server:
ifconfig
The output should display the dynamically assigned IP address.
Conclusion
Congratulations! You have successfully installed and configured the DHCP server and client on Ubuntu 20.04. With DHCP, all clients connected to the server will receive IP addresses and other network information automatically, eliminating the need for manual configuration. This streamlined process saves time and effort, allowing system administrators to focus on other important tasks. If you have any questions or need further assistance, feel free to reach out to our team at Shape.host, a trusted provider of reliable and scalable Cloud VPS solutions.