How do I find out my DHCP server address?
Q. In Windows XP / 2000 / Vista ipconfig /all command will show me DNS server and DHCP server ip address. But, how to know DHCP server address in Linux?
A. The DHCP protocol allows a host to contact a central server which maintains a list of IP addresses which may be assigned on one or more subnets. A DHCP client may request an address from this pool, and then use it on a temporary basis for communication on network.
dhclient.leases file
Under Linux you use command dhclient 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 address
Usually dhclient.leases file is located at /var/lib/dhcp3/dhclient.leases, type the following command:
less /var/lib/dhcp3/dhclient.leases
OR
cat /var/lib/dhcp3/dhclient.leases
Alternatively, you can just use grep command to get DHCP server address, enter:
grep dhcp-server-identifier /var/lib/dhcp3/dhclient.leases
Output:
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;
option dhcp-server-identifier 192.168.1.1;
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;
}
A note about RHEL / CentOS / Fedora Linux user
Redhat and friends uses /var/lib/dhcp/dhclient.leases file:
less /var/lib/dhcp/dhclient.leases
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Linux / UNIX FAQ:
- Setting Up a CentOS / Red Hat Linux DHCP Client
- Linux Force DHCP client (dhclient) to renew ip address
- Configuring Linux Static DHCP Clients by Sending Host Name
- Configure Linux DHCP client ( dhclient ) to persistently look for an IP address lease
- /etc/network/interfaces Ubuntu Linux networking example
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!
Tags: central server, debian find dhcp server ip, dhclient, dhcp client, dhcp protocol, dhcp server ip address, domain name, find dhcp server ip, lease database, leases, message type, new lease, renewal time, server address, server ip address, servers, ubuntu find dhcp server ip, windows xp ~ Last updated on: December 8, 2007



December 10th, 2007 at 3:29 pm
In case you don’t have a lease, you could (but it’s more work) request a lease with dhclient(8) and use tcpdump(8) to see what server answered. Use something like this in one terminal:
# tcpdump -i eth0 port 67 or port 68
And something like this in a second terminal:
# dhclient eth0
If you are lucky, dhclient will even tell you what the DHCP server is.
Regards, Robert.
December 11th, 2007 at 7:54 am
Robert,
When you run dhclient eth0, it always show DHCP address on screen, just look for DHCPACK (no need to run tcpdump)
March 17th, 2008 at 3:04 pm
How can I get just DHCPACK value from code(C,C++) ?
March 17th, 2008 at 3:13 pm
I need to know just my DHCP server address value from code, so if there is some script or a neath way to do it, without parsing the dhclient.leasing file?