If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines. Show
1. OverviewThere are several occasions when we need to renew the DHCP-assigned system IP address, for example:
Besides these reasons, when a computer switches to a different network, its IP also changes. In this tutorial, we’ll discuss renewing the DHCP-assigned IP address on a Ubuntu 22.04 system. Let’s first see an overview of the DHCP protocol. 2. Dynamic Host Configuration Protocol (DHCP)To identify a computer/host on a network, we use IP addresses. Using these IP addresses, computers communicate with each other on a network. Basically, there are two ways of configuring IP addresses on a client machine:
A DHCP server automatically assigns IP addresses to connected hosts on a network. The client cannot interfere with the DHCP settings they receive. However, these settings are transparent to the client side. An IP address set using the above way is not a permanent one, and we refer to it as a DHCP lease. If we do not renew it, the DHCP lease may be allotted to another computer. Therefore, to renew the lease, the client has to periodically check back with the DHCP server. 3. DHCP ClientsBroadly speaking, there are three DHCP clients that are common on Ubuntu:
However, not all versions of Ubuntu support all three clients. This is true for other Linux-based distributions too. For example, some of them come shipped with only one of the three clients, whereas others may come shipped with two or all of the three. However, dhclient is a commonly available DHCP client on Ubuntu systems. Ideally, every system has a default DHCP client. On Ubuntu 22.04, the dhclient is the default DHCP client. At the time of writing this article, the other clients pump and dhcpcd are not available on Ubuntu 22.04. Since we are working on Ubuntu 22.04 system, we’ll have to use dhclient as the DHCP client. 4. Process of DHCP Client-Server InteractionThere are several messages that pass between the DHCP server and the client, as described below:
After the last DHCPACK message, the client can use the leased IP address and other settings till the end of the lease time. When half the lease time is over, the client can request IP renewal. For this, the client sends a DHCPREQUEST message to the DHCP server. If the current DHCP server says yes to the request, it responds with a DHCPACK message. However, if the client does not get a response, the client might go on with the current DHCP settings. It can continue using them until the lease time is over. Once the lease time is over, it is mandatory for the client to again restart with the DHCPDISCOVER procedure. 5. Renewing DHCP IP Using dhclientLet’s first check if the dhclient service is running on our Ubuntu 22.04 system:
The ps command shows the information corresponding to different services running on the system. Let’s now check our current leased DHCP IP address on our target interface wlo1:
As we can see, the current assigned IP is 192.168.35.150. Let’s release our leased DHCP IP using the -r flag of the dhclient command:
The -r flag releases the current DHCP lease and halts the running DHCP client. Note that releasing an IP address can result in loss of connection, so carefully perform this step on remote systems. Next, we will now request a new DHCP IP from the server:
Let’s again check back our IP on the wlo1 interface:
As we can see, the IP address has now changed to 192.168.35.151. The syslog file stores the logs generated by the DHCP server. We can search through these logs for DHCP logs:
These logs are very helpful while troubleshooting DHCP issues. 6. ConclusionIn this article, we have learned how we can acquire a new IP address on the Ubuntu system. Specifically, we have used the dhclient utility to renew our IP configuration. If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines. How does a DHCP server respond to an IP request that can be renewed?During the renewal process, a DHCP client sends a renewal request, which is passed through a BIG-IP Forwarding IP type of virtual server directly to the specific DHCP server that issued the initial client IP address. The DHCP server then sends a response to renew the lease for the client's IP address.
What is the DHCP decline message?A DHCP Decline message is sent by a DHCP client to notify the DHCP server that the assigned IP address conflicts with another IP address. Then the DHCP client applies to the DHCP server for another IP address. A DHCP Release message is sent by a DHCP client to release its IP address.
What is type of message that the client sends the DHCP server if the client lease is about to expire?The client ends the lease by sending a DHCPRELEASE message to the DHCP server. The server will then return the client's IP address to the available address pool.
What are the five DHCP messages?DHCP Messages, DHCPDiscover, DHCPOffer, DHCPRequest, DHCPAcknowledgment, DHCPNak, DHCPDecline, DHCPRelease, DHCPInform. Following are the important messages exchanged between a Dynamic Host Configuration Protocol (DHCP) client and a DHCP Server.
|