×


Find DHCP Server IP Address in Linux Using CLI - Step by Step guide ?

A DHCP server automatically provides and allocates IP addresses and other information like subnet mask, default gateway, DNS address, etc, to client devices on the network. It enables the systems on the network to communicate with other systems effectively. Without a DHCP server, an administrator has to manually configure the IP address and other information on all devices which is not only tedious but also increases the chance of errors like IP address conflict, typographical errors, etc. DHCP assigns each device a unique IP address and it also defines how long a device can keep this IP address.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related DHCP queries on Linux systems.

In this context, we shall look into how to find your DHCP server IP address in a Linux OS using the command line.


How to Find IP address of DHCP Server ?

You can find your DHCP server's IP address from different locations. You can apply the following methods to find the IP address of a DHCP server.


1.  Via the /var/log

Mostly the Linux logs are located in the /var/log file. When a DHCP server offers an IP address to a client, it sends a DHCPOFFER message which contains its own IP address and the IP address that is offered to the client. This message is also logged in the log file. The log files contain so much information. So in order to find only the specific information (DHCPOFFER), we will filter it out using the grep command.

Here is the command you can use for finding the IP Address of your DHCP server using the /var/log:

 $ sudo grep -IR "DHCPOFFER" /var/log/*


2.  Via the Journalctl

Journalctl is used for viewing and querying logs collected by systemd. Using the journalctl command with grep, we can also find out the IP address of the DHCP server. The DHCPACK message is sent by the DHCP server to the client which contains the IP address of the DHCP server and the configuration information which the client may have requested.

Here is the command you can use for finding the IP Address of your DHCP server using the journalctl:

$ sudo journalctl | grep -m1 DHCPACK


3. Via the dhclient.leases file

The dhclient keeps a record of leases it has been assigned in the dhclient.leases file. This file also contains information about the DHCP server address.

Here is the command you can use for finding the IP Address of your DHCP server using the dhclient.leases file:

$ sudo grep -m1 "dhcp-server" /var/lib/dhcp/dhclient.leases


4.  Via the dhclient utility

The dhclient utility is used to configure a network interface using the DHCP protocol. Using the dhclient utility, you can release an allocated IP address and request a new one from your DHCP server. You can also use it to find your DHCP IP address; however, this will make the dhclient to go through the entire DORA process (Discover; Offer; Request; Acknowledge).

Here is the command you can use for finding the IP Address of your DHCP server using the dhclient utility:

$ sudo dhclient -d -nw <interface_name>

Replace <interface_name> with your network interface name:

$ sudo dhclient -d -nw ens33


[Need assistance in configuring DHCP on your Linux System ? We can help you. ]


Conclusion

This article covers the different ways of finding the IP address of your DHCP server in a Linux system. We have already dealth with how to install and configure DHCP server on Linux.


Linux System IP Scanning commands:

Scanning for IP address lets you have better control over your network. With a few commands, you can quickly map out the devices in your network and the IP addresses that they are using.

  • ipconfig: This command displays all network settings assigned to one or all adapters in the computer. You can find information such as your own IP, subnet, and Gateway. For Linux and MacOS is "ifconfig".
  • arp -a: When you issue the "arp -a", you’ll get IP-address-to-mac conversion and the allocation type (whether dynamic or static) of all devices in your network.
  • Ping: It helps determine connectivity between two hosts and find the IP address of a hostname.