15

Is there a way to show my current (client) DHCP lease?

Or even better - retrieve all options/infos sent with DHCPACK?

5
  • 4
    /var/lib/dhcp/dhclient.leases? – heemayl May 20 '16 at 22:49
  • @heemayl this file is empty in my case (Ubuntu 15.10), maybe because NetworkManager is acquiring dhcp lease (?) – madneon May 20 '16 at 23:03
  • ipconfig getpacket <ifname> or ipconfig getv6packet <ifname> on Mac OS X. – thrig May 20 '16 at 23:21
  • @heemayl, Nope. No such file or directory – Cerin Nov 21 '17 at 21:46
  • @heemayl was correct for the directory. On Debian Stretch I found infos in "/var/lib/dhcp/dhclient.eth0.leases" – Larsen Nov 16 '18 at 11:58
5

I used dhcpdump when I was testing DHCP. It will dump both sides of the DHCP transaction. If you leave it running it will log the options passed.

You may want to restart your DHCP client to see the initial negotiation. The renewal request should contain all the running configuration.

10

I'm not aware of a way to query this information on the client. If you are on the server you can see information on the client leases in /var/lib/dhcp/dhclient.leases. From the client the only way i know is:

sudo grep dhclient /var/log/syslog

Which should give you something like:

May 20 18:34:38 [machine_name] dhclient: DHCPREQUEST on eth0 to [DHCP_SERVER_IP] port 67
May 20 18:34:38 [machine_name] dhclient: DHCPACK from [DHCP_SERVER_IP]
May 20 18:34:38 [machine_name] dhclient: bound to [client_dhcp_ip] -- renewal in 1517 seconds.
4

depending on your distro, it should be located in /var/lib/dhcp under dhclient.{interface}.leases or /var/lib/dhclient.leases. you can also specify the path of your dhclient.leases file by passing -lf when starting dhclient.

1
  • @madeon it should be under /var/lib/dhcp/dhclient.{interface}.leases e.g /var/lib/dhcp/dhclient.eth0.leases – RDCortez May 20 '16 at 23:08
3

With NetworkManager use nmcli to query the DHCP status for your active connection (assuming one) with

nmcli -f ipv4.method con show "`nmcli -t -f NAME connection `"

For full DHCP information use -f DHCP4. Adjust for ipv6 as necessary.

1
  • This prints the DHCP information for the currently active connection: nmcli -f DHCP4 con show "$(nmcli -g NAME con show --active)" – Matthias Braun Sep 9 '20 at 9:41
0

On current Debian you can find the information in /var/lib/dhcp/dhclient.leases which looks like this:

lease {
  interface "eth0";
  fixed-address 10.224.129.116;
  option subnet-mask 255.255.255.0;
  option dhcp-lease-time 3600;
  option routers 10.224.129.1;
  option dhcp-message-type 5;
  option dhcp-server-identifier 10.224.129.1;
  option domain-name-servers 10.224.129.1;
  option dhcp-renewal-time 1800;
  option dhcp-rebinding-time 3150;
  option broadcast-address 10.224.129.255;
  option host-name "tk-otc-client";
  option domain-name "dd.otc";
  renew 4 2020/12/03 09:56:25;
  rebind 4 2020/12/03 10:26:09;
  expire 4 2020/12/03 10:33:39;
}
0

Know your Unix/Linux :-) There are more DHCP client programmes available.

One, fairly frequent option is to use dhclient. It is usually set to write full "PACK" answer decoded into a file. File is usually somewhere in /var.

Something like find /var -name '*leases*' can give you a hint. Mine is /var/db/dhclient.leases.em2 (OpenBSD).

Or give some detail about SW you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.