The DHCP protocol allows a host to contact a central server that maintains a list of IP addresses that may be assigned on one or more subnets. A DHCP client may request an address from this pool and then use it temporarily for communication on network.
Linux find DHCP server IP address command line options
The procedure to find out your DHCP IP address in Linux is as follows:
- Open the terminal application
- Run less /var/lib/dhcp/dhclient.leases command to list your DHCP server IP address
- Another option is to type grep dhcp-server-identifier /var/lib/dhcp/dhclient.leases command to find the IP address of a DHCP server
- One can use ip r Linux command to list default route which act as the DHCP Server on most home networks
Let us see all commands and examples in details.
The dhclient.leases file
Under Linux, you need to use dhclient command to obtain and managing dhcp tasks. In order to keep track of leases across system reboots and server restarts, dhclient keeps a list of leases it has been assigned in the dhclient.leases file. On startup, after reading the dhclient.conf file, dhclient reads the dhclient.leases file to refresh its memory about what leases it has been assigned.
When a new lease is acquired, it is appended to the end of the dhclient.leases file. In order to prevent the file from becoming arbitrarily large, from time to time dhclient creates a new dhclient.leases file from its in-core lease database. The old version of the dhclient.leases file is retained under the name dhclient.leases~ until the next time dhclient rewrites the database.
Find out DHCP server IP address on Linux
Usually dhclient.leases file is located at /var/lib/dhcp3/ or /var/lib/dhcp/ directory, type the following less command/cat command/more command to view it on screen:
$ more /var/lib/dhcp/dhclient.leases
Sample outputs:
lease { interface "ra0"; fixed-address 192.168.1.106; option subnet-mask 255.255.255.0; option dhcp-lease-time 86400; option routers 192.168.1.1; option dhcp-message-type 5; <span style='color: rgb(255, 0, 0);'>option dhcp-server-identifier <span style='color: rgb(102, 102, 204);'>192.168.1.1;</span></span> option domain-name-servers 208.67.222.222,208.67.220.220; option dhcp-renewal-time 43200; option dhcp-rebinding-time 75600; option host-name "vivek-desktop"; renew 0 2007/12/9 05:17:36; rebind 0 2007/12/9 15:06:37; expire 0 2007/12/9 18:06:37; } lease { interface "ra0"; fixed-address 192.168.1.106; option subnet-mask 255.255.255.0; option routers 192.168.1.1; option dhcp-lease-time 86400; option dhcp-message-type 5; option domain-name-servers 208.67.222.222,208.67.220.220; option dhcp-server-identifier 192.168.1.1; option dhcp-renewal-time 43200; option dhcp-rebinding-time 75600; option host-name "vivek-desktop"; renew 0 2007/12/9 06:11:22; rebind 0 2007/12/9 16:13:50; expire 0 2007/12/9 19:13:50; } |
Look for dhcp-server-identifier. In this example, my DHCP server IP address is 192.168.1.1. Alternatively, you can just use grep command to get DHCP server address, enter:
grep dhcp-server-identifier /var/lib/dhcp/dhclient.leases
A note about RHEL / CentOS / Fedora Linux user
Redhat and friends uses /var/lib/dhcp/dhclient.leases file:
less /var/lib/dhcp/dhclient.leases
Using the ip command or route command
Typically, on most home or small business networks, your Internet WI-FI or router acts as the DHCP server too. Hence, it is possible to type the following command to obtain default routes on Linux:
ip r
roue -n r
ip r | grep default
Sample outputs:
default via 192.168.2.254 dev wlp82s0 proto dhcp metric 600
You can find your default router IP address in GUI network config tool as follows:
Conclusion
You learned how to find the DHCP server IP address on Linux using various command-line methods. The dhclient.leases file act as a DHCP client log file.
read the file /etc/relsolv.conf:
cat /etc/resolv.conf
It syhould be enough