How to Find The IP Address Of A DHCP server

by
Share this Article: Facebook0Google+0Twitter14LinkedIn2Reddit0StumbleUpon1

As you may know, The Dynamic Host Configuration Protocol (DHCP) is a standardized networking protocol used on Internet Protocol (IP) networks for dynamically distributing network configuration parameters, such as IP addresses for interfaces and services. With DHCP computers request IP addresses and networking parameters automatically from a DHCP server, reducing the need for a network administrator or a user from having to configure these settings manually.

So in essence when you enable DHCP on your machine, it sends a message to the network to discover DHCP servers on it. Once it gets confirmation from an available one, it finalizes a request for the lease of an IP address. If you want to find the IP address of a DHCP server used for configuring a particular interface on your Linux machine there are two ways.

First way

The easy way is to simply check the DHCP lease information from a file in:

/var/lib/dhcp/dhclient.eth0.leases.

To do that, simply type:

$ cat /var/lib/dhcp/dhclient.eth0.leases

The output should be something like:

lease {

  interface "eth0";

  fixed-address 192.168.1.8;

  option subnet-mask 255.255.255.0;

  option time-offset 0;

  option routers 192.168.1.1;

  option dhcp-lease-time 86399;

  option dhcp-message-type 5;

  option domain-name-servers 192.168.1.1,71.250.0.12;

  option dhcp-server-identifier 192.168.1.1;

  option broadcast-address 192.168.1.255;

  option host-name "new-host-3";

  option domain-name "home";

  renew 5 2014/03/17 13:06:24;

  rebind 6 2014/03/18 00:22:01;

  expire 6 2014/03/18 03:22:01;

}

The lease file contains a lot of information as you can see, such as DHCP lease time and expiration time. The IP address of a DHCP server is shown in the “dhcp-server-identifier” field.

You should be aware that depending on your Linux distribution the file may be located elsewhere:

/var/lib/dhclient/dhclient-eth0.leases

/var/lib/dhcp3/dhclient.leases

Second way

Examine the log files in /var/log/ by typing:

sudo grep -R "DHCPOFFER" /var/log/*

The output:

/var/log/syslog:Mar 17 23:22:02 debian dhclient: DHCPOFFER from 192.168.1.1

The IP is clearly visible.

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook0Google+0Twitter14LinkedIn2Reddit0StumbleUpon1