15.6 C
Jaipur
Thursday, December 2, 2021

How to Renew DHCP IP on Debian 11

Must read

What Is DHCP?

The DHCP or Dynamic Host Configuration Protocol is used to assign devices random IP addresses automatically. When using a server or router with a DHCP server, clients don’t have to set their IP addresses manually. They need to request it from the DHCP. The IP addresses provided by DHCP are known as Dynamic IP addresses, while IP addresses set manually are known as Static IP addresses.

Renew the IP Address on Debian 11 Using DHCP (All Network Cards):

The dhclient tool is the main Linux method to deal with DHCP or dynamic IP addresses. When our system boots, dhclient tries to configure a dynamic IP address for each network device in our system. However, dhclient can be invoked by the user at any time to renew an interface IP address.

In the first example of this tutorial, we will execute dhclient followed by the -r flag to release the current IP address. It is important to note that the dhclient command will release all IP addresses when a network device isn’t specified.

Note: After running this command, you’ll lose your network connection. You will recover it by following the next steps of this tutorial:

Now, your system released its IP address, and your internet connection is gone.

You also can implement the -v (verbosity) option to get the whole releasing IP process detailed in the output as shown in the example below:

Once your IP address is released, you can request a new one using the dhclient command without additional parameters, as shown in the screenshot below:

And you also can implement the -v flag to get a detailed output, as shown in the following example:

As you can see, the IP address 192.168.1.103 was assigned to the wlp3s0 device.

Renew the IP Address on Debian 11 Using DHCP (Specific Network Card):

As mentioned previously, if you don’t specify a device when running the dhclient command, all network card IP addresses will be affected.

Specifying a network card when running dhclient is pretty simple. Just add the network card name at the end of the command.

The following example shows how to release the IP address of the wlp3s0 Wi-Fi card specifically. As mentioned in the first steps of this tutorial, the -v option was added just to get a detailed output. You can skip it.

sudo dhclient -v -r wlp3s0

Then, to get a new dynamic IP address for the wlp3s0 Wi-Fi card specifically, run the following command:

As you can see, the IP address was properly assigned to the wlp3s0 network device.

How Does DHCP Work?

When you run the dhclient command, or when you boot your computer, dhclient sends broadcast messages (DHCP Discover) to the subnets in order to discover available DHCP servers. The DHCP Discover packet includes the physical computer MAC address for the client to be identified by the server. Then, the DHCP server sends a response (DHCP OFFER) offering to send an IP address. The client replies back with a request packet or DHCP Request accepting the offer. Then, the DHCP server assigns an IP address to the client, integrating it to the network. This process is known as DHCP negotiation.

In terms of packets, we can summarize this process as DHCPDISCOVER>DHCPOFFER>DHCPREQUEST>DHCPACK where:

DHCPDISCOVER: A packet is sent from the client to subnets looking for available DHCP servers to obtain the IP address.

DHCPOFFER: When the packet is received by a DHCP server, the server sends a DHCPOFFER message back to the client as identified by its MAC address, then offering to assign it a free or unused IP address.

DHCPREQUEST: The client sends a packet to the DHCP server accepting the offer. If more than one DHCP server offered the IP address, the client would accept the first received, and other DHCP servers would be notified the initial request was already satisfied.

DHCPACK: Finally, after the DHCP server got the final request packet from the client. It will reply with a DHCPACK packet completing the IP assignment.

How to Check the DHCP Lease History?

In some cases you may want to see your dynamic IP addresses history. This can be achieved by checking the system logs located at /var/log/syslog. The following command allows you to see all negotiation processes which involve the dhclient command:

sudo grep dhclient /var/log/syslog

As you can see, we can see the whole negotiation process and previously assigned IP addresses.

Note: If this article was interesting for you, you may want to read Advanced Linux Network Commands.

Conclusion:

As you can see, renewing an IP address on Debian 11 using DHCP is pretty easy. Understanding how DHCP servers and clients work is a basic knowledge any Linux user must learn to understand how many devices acquire their IP address. While dynamic IP addresses do not make sense in planned networks, they are a great way to manage public IP addresses since two devices can’t have the same address. As you can see, requesting a dynamic IP address from a Linux device can be done by any Linux user level if there is privileged access. In many cases, when you connect to a public network but don’t receive internet access, you may want to try to request a dynamic IP address using the method explained. This was helpful for me in some situations.

For additional information on the dhclient command, you can visit the man page at https://linux.die.net/man/8/dhclient.

Thank you for reading this tutorial explaining how to renew DHCP IP addresses on Debian 11. Keep following Linux Hint for additional Linux tips and tutorials.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -

Latest article