How do I find out my DHCP server address?

by on December 8, 2007 · 13 comments· LAST UPDATED December 8, 2007

in , ,

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 13 comments… read them below or add one }

1 Robert de Bock December 10, 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.

Reply

2 nixCraft December 11, 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)

dhclient ra0
There is already a pid file /var/run/dhclient.pid with pid 134519120
Internet Systems Consortium DHCP Client V3.0.5
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/ra0/00:17:9a:0a:f6:44
Sending on   LPF/ra0/00:17:9a:0a:f6:44
Sending on   Socket/fallback
DHCPDISCOVER on ra0 to 255.255.255.255 port 67 interval 6
DHCPOFFER from 192.168.1.1
DHCPREQUEST on ra0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.106 -- renewal in 39175 seconds.

Reply

3 Marko March 17, 2008 at 3:04 pm

How can I get just DHCPACK value from code(C,C++) ?

Reply

4 Marko March 17, 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?

Reply

5 Ryan August 5, 2008 at 3:29 pm

Run this to get just your DHCP Server name:

cat dhclient.leases | grep dhcp-server | uniq | cut -d” ” -f5 | cut -d”;” -f1

Reply

6 Shylesh August 26, 2008 at 6:17 am

Mine is at
/var/lib/dhclient/dhclient-eth0.leases

so the server would be
grep dhcp-server /var/lib/dhclient/dhclient-eth0.leases

Reply

7 Saurabh November 22, 2008 at 5:00 pm

Thanks for the good post admin
and thanks to robert for telling how to get to know the dhcp server ip when their is no leases

my case was also same as robert explain
thanks

Reply

8 KoteswaraRao August 10, 2009 at 6:27 am

sir

iam kotesh pleces data to dhcp and dns server

Reply

9 me myself and i August 30, 2010 at 4:09 pm

ho to findmy dhcp in windows there is a command which i use it for configuremy ps3

Reply

10 Dude January 26, 2011 at 12:29 pm

“ipconfig /all” do NOT show dhcp ip, it will only show if client is dhcp enabled or not.

Reply

11 shuhaib April 1, 2011 at 3:27 pm

hi
i have one divice i need that divice reset DHCP show ip

Reply

12 Gsm January 14, 2013 at 6:32 pm

I have a Mac OS X 10.8.2 and want to install 3G, K4510-Z, USB vmb modem. I just cannot uninstall the Microsoft software, for starters.
Also what Mac software shall l need to install and proper procedure.

Reply

13 niko November 6, 2014 at 8:44 am

I have been given a desktop and this question:Configure a new domain with DNS an DHCP join the client machine to the new domain.Where do I start?its urgent.your help will be much appreciated

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: