CentOS Debian Mint openSUSE Red Hat Ubuntu

How to Find DHCP Server IP Address in Linux Using CLI

How to Find DHCP Server IP Address in Linux Using CLI

What is DHCP Server?

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.

So, that was the quick overview of the DHCP server. But do you know who your DHCP server is? Today’s in this guide, we will show you how to find your DHCP server IP address in a Linux OS using the command line.

Finding IP address of DHCP Server

You can find your DHCP server’s IP address from different locations. Following are some methods for finding the IP address of a DHCP server.

Method #1 Using 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/*

The output below showing our DHCP server IP address that is 192.168.72.254.

Method #2 Using 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

The output below showing our DHCP server IP address that is 192.168.72.254.

Method #3 Using 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

The output below showing our DHCP server IP address that is 192.168.72.254.

Method #4 Using 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

The output below showing our DHCP server IP address that is 192.168.72.254.

In this post, we described four different methods using which you can find the IP address of your DHCP server in a Linux system. You can also visit our post on installing and configuring a DHCP server on Linux.

Similar Posts