Check my DHCP lease?

76,935

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

There is one other aspect to this answer to consider to show your DHCP lease time and other DHCP information in the offer. If using Linux systemd-networkd, none of the options above work as they relate to network manager (the Linux solutions at least)

There is a similar question with answer explaining this at How do I check DHCP lease time in systemd-networkd?

Quoting from that answer:

Depending on the OS; Enabling debug isn't always necessary.

systemd-networkd should store the lease info under /run/systemd/netif/leases/

i.e.

cat /run/systemd/netif/leases/2
Share:
76,935

Related videos on Youtube

madneon
Author by

madneon

Updated on September 18, 2022

Comments

  • madneon
    madneon over 1 year

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

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

    • heemayl
      heemayl almost 8 years
      /var/lib/dhcp/dhclient.leases?
    • madneon
      madneon almost 8 years
      @heemayl this file is empty in my case (Ubuntu 15.10), maybe because NetworkManager is acquiring dhcp lease (?)
    • thrig
      thrig almost 8 years
      ipconfig getpacket <ifname> or ipconfig getv6packet <ifname> on Mac OS X.
    • Cerin
      Cerin over 6 years
      @heemayl, Nope. No such file or directory
  • RDCortez
    RDCortez almost 8 years
    @madeon it should be under /var/lib/dhcp/dhclient.{interface}.leases e.g /var/lib/dhcp/dhclient.eth0.leases
  • Matthias Braun
    Matthias Braun over 3 years
    This prints the DHCP information for the currently active connection: nmcli -f DHCP4 con show "$(nmcli -g NAME con show --active)"
  • Old Markus
    Old Markus almost 3 years
    Can you tell me what does the number 4 after renew mean ?
  • TNT
    TNT almost 3 years
    4 means Thursday (0-6 -> Sunday-Saturday) as explained in linux.die.net/man/5/dhclient.conf .