12

How do I find the DHCP lease time when I am using systemd-networkd?

My network is defined in /etc/systemd/network/eth0.network:

[Match]
Name=eth0

[Network]
DHCP=yes

There are other question on this site asking for the same information but they weren't using systemd-networkd but dhclient or some other method.

I've tried looking in journalctl to no avail. I’m using ArchLinux.

2
  • Try grep lease /var/log/syslog.
    – user147505
    Commented Mar 11, 2018 at 15:36
  • @tomasz forgot to mention that I’m using ArchLinux which uses journald not syslog. I’ve updated the question
    – user14755
    Commented Mar 11, 2018 at 23:02

3 Answers 3

14

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

1
  • 1
    At least in my version, /run/systemd/netif/leases/ does NOT include the lease time. - which is the question.
    – A. Richard
    Commented Aug 1, 2023 at 13:20
6

Per Lennart's post here, you have to change systemd-networkd log level to debug.
If you wanted to have it on all the time you could use a drop-in unit:

mkdir -p /etc/systemd/system/systemd-networkd.service.d
cat << IN > /etc/systemd/system/systemd-networkd.service.d/10-debug.conf
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
IN
systemctl daemon-reload
systemctl restart systemd-networkd
5

I can't find authoritative documentation for this, but I think networkd's DHCP client uses the received DHCP lease duration to set valid_lft and preferred_lft on the address in kernel, and thus the remaining lease duration is simply shown with ip address show:

$ ip -4 a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 192.168.2.7/24 brd 192.168.2.255 scope global dynamic eth0
       valid_lft 59397sec preferred_lft 59397sec

You must log in to answer this question.