Is there a way to show my current (client) DHCP lease?
Or even better - retrieve all options/infos sent with DHCPACK
?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs there a way to show my current (client) DHCP lease?
Or even better - retrieve all options/infos sent with DHCPACK
?
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.
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.
/var/lib/dhcp/dhclient.{interface}.leases e.g /var/lib/dhcp/dhclient.eth0.leases
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.
nmcli -f DHCP4 con show "$(nmcli -g NAME con show --active)"
Sep 9, 2020 at 9:41
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.
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
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;
}
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.
/var/lib/dhcp/dhclient.leases
?ipconfig getpacket <ifname>
oripconfig getv6packet <ifname>
on Mac OS X.No such file or directory