In Linux, DHCP (Dynamic Host Configuration Protocol) has a key role, just like a system/network administrator. Its functionality refers to assigning the IP address and the network parameters to all the network interfaces.
The computing machines request the IP address, which is generated dynamically with the help of DHCP, thus nullifying the purpose of the IP address assignment manually. This automatic assignment of the IP addresses is quite effective as there would be no duplication.
In this Linux tutorial, we are here with a list of ways that can be adopted to check the IP address.
How to Find the IP Address of the DHCP Server in Linux?
There are several ways to get the IP address of the DHCP server; these are practically implemented in this section.
Approach #1: By Accessing the /var/log/ File
The “/var/log” directory contains the log files of the system. The log files contain information about system processes, system errors, and other important events. Logs can be useful for troubleshooting system problems, providing valuable clues about what went wrong and why.
Inside that directory, there is a file named “syslog” (in Debian/Ubuntu-based systems) which contains the system logs, and we can apply the “cat” command on it to get the IP address of the DHCP server.
$ cat /var/log/syslog | grep -i 'dhcp' <<- For Debian/Ubuntu based Systems- >>
If you want to get the IP address on Fedora/RHEL-based Linux systems, the file name is “messages” and can be checked by the command.
$ cat /var/log/messages | grep -i 'dhcp' <<- For Fedora/RHEL based Systems->>
Approach #2: By Accessing the /var/lib/dhcp/ File
In Linux, the “/var/lib/dhcp” file stores the status of the DHCP lease information. As in 1st method, we will use the “cat” command here also to get the content of the file.
$ cat /var/lib/dhcp/dhclient.leases
From the output, trace out the “DHCP-server-identifier” as seen above.
Approach #3: journalctl Command
In Linux, the journalctl command is used to view and manage the system logs that use the systemd initialization system. It also allows the users to view the logs generated by various services running on the system. To get the IP address of the DHCP server, the journalctl utility is utilized in the following manner (using this command as a root user).
# journalctl -r | grep -m1 DHCPACK
The IP address is directed in the above image.
Approach #4: dhclient Command
A dhclient command is a command-line tool used to configure a network interface on a Linux or Unix-like operating system using the Dynamic Host Configuration Protocol (DHCP). The “dhclient” command can be implemented in the following manner to get the IP address of the DHCP server.
# dhclient -v
Note: It is recommended to use the “journalctl” and the “dhclient” command as root users.
As stated earlier, the DHCP is responsible for assigning an IP address; a Linux user can get the IP address of the DHCP server using the “var/log/syslog”(Debian-based) and “var/log/messages”(RHEL-based). Apart from that, the users can use the “journalctl” and the “dhclient” command to get the IP address of the DHCP server.
Want to know about the IP address of the Linux system? Read our detailed article here.