On Fri, 2022-06-24 at 17:39 -0700, Jim Garrison via networkmanager-list wrote: > When using dhclient, the current lease info, including expiration > time, is in /var/lib/dhclient/dhclient.leases, and contains > something similar to > > lease { > interface "enp3s0"; > fixed-address [redacted]; > option subnet-mask 255.255.254.0; > option dhcp-lease-time 3523; > option routers [redacted]; > option dhcp-message-type 5; > option dhcp-server-identifier 96.113.84.141; > option domain-name-servers 127.0.0.1,75.75.75.75,75.75.76.76; > option domain-search "[redacted]"; > option dhcp-renewal-time 2016; > option broadcast-address 255.255.255.255; > option dhcp-rebinding-time 3073; > option domain-name "hsd1.or.comcast.net."; > renew 3 2022/06/22 23:59:57; > rebind 4 2022/06/23 00:23:15; > expire 4 2022/06/23 00:30:45; > } > > However, my system (Centos 8 Stream) uses NetworkManager which, based > on > my research, uses its own internal DHCP client. Looking in > /var/lib/NetworkManager I see > > $ sudo ls -1 /var/lib/NetworkManager/ > internal-79cbd87e-9d65-4aa4-8768-88b460fd372c-enp3s0.lease > internal-79cbd87e-9d65-4aa4-8768-88b460fd372c-ens1.lease > internal-bdaf2eb0-de2e-4573-a415-214629c7b757-enp3s0.lease > NetworkManager-intern.conf > NetworkManager.state > secret_key > seen-bssids > timestamps > > which looks promising. However, the lease files contain only the IP > address. For example, the first file listed above contains only > > # This is private data. Do not parse. > ADDRESS=[redacted] > > Simple question: Where does NetworkManager keep the lease data so it > knows when it needs to renew the lease?
Hi, the files in /var/lib/NetworkManager are internal not public API. That of course does not prevent you from accessing it, but use with care. That is also the case for the dhclient lease files. These files are not supposed to give information about the lease. You can see the current lease information on the D-Bus API, for example via `nmcli -f ALL device show ens1` or `nmcli -f DHCP4 device show ens1`. In recent NM versions, you can also find the same information in `/run/NetworkManager/devices/$IFINDEX` (if you prefer reading files). This *is* public API. A lease only makes sense to NetworkManager while it's running and connected. It just knows in memory how long the lease is valid. I don't think that works different when you use dhclient alone (not as NetworkManager plugin). Well, maybe you could restart dhclient, and it would have remembered that it had a lease. NM doesn't do that. If you re-activate the device (or reboot or restart NM), it will try to get a new lease and start the DHCP state machine again. It only uses the previous ADDRESS= to give a hint to the DHCP server which address it would like to have. If the device is currently not active, then there is no public API for past leases. Yes, you could parse the /var/lib/NetworkManager/*.lease to get some some of the information, but this only contains information which NetworkManger cares about (the `ADDRESS=`), not most of the interesting data. It's anyway not clear what you would like to know about past leases. Thomas _______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list