DHCP client info (lease time etc...)

Hi!
I configured OpenWrt with a DHCP client on the WAN interface. My ISP provides me with a 'static IP' which is obtained via DHCP (don't ask me the details).

Basically, I 'think' I have a 7 days lease, after that I just get the same IP from my ISP.

The problem is that I can't find a way to get the length of the lease from Luci or from the command line, I just see on the home page the 'expires time' and the current up time, and I can do some math.

I can't also check when the renewal has been attempted: in the system logs, I can't see any udhcpc log right now. I verified at least at 75% of the lease time.

The udhcpc is running with the WAN interface (eth1), I can see that with 'ps -w' but I can't really get the lease time from it :slight_smile:

Is there something I'm missing?

Thank you!

root@OpenWrt:~# logread |  grep -i "wan"
Thu Jun 27 21:28:04 2024 daemon.notice netifd: wan (2157): udhcpc: sending renew to server 192.168.10.254
Thu Jun 27 21:28:04 2024 daemon.notice netifd: wan (2157): udhcpc: lease of 192.168.10.66 obtained from 192.168.10.254, lease time 43200
Fri Jun 28 03:28:04 2024 daemon.notice netifd: wan (2157): udhcpc: sending renew to server 192.168.10.254
Fri Jun 28 03:28:04 2024 daemon.notice netifd: wan (2157): udhcpc: lease of 192.168.10.66 obtained from 192.168.10.254, lease time 43200
Fri Jun 28 09:28:05 2024 daemon.notice netifd: wan (2157): udhcpc: sending renew to server 192.168.10.254
Fri Jun 28 09:28:05 2024 daemon.notice netifd: wan (2157): udhcpc: lease of 192.168.10.66 obtained from 192.168.10.254, lease time 43200
1 Like

Or:
ifstatus wan | grep leasetime

2 Likes

ifstatus reports the leasetime, thanks! It is indeed 7 days, but I don't see any udhcpc log.

It was my understanding that udhcpc should try to renew the IP after 50% of the leasetime, and then after 75%, is this correct?

it does for me, as you can see, cannot verify the 75% of cos.

It may have fallen off the edge of the limited log space, especially if the lease is 7 days (a lot of other stuff will be logged).

Close... 50%... if unsuccessful, it tries again, first at 87.5%, and finally again at 100% (when it must release the lease if it does not get a renewal).

2 Likes

It may have fallen off the edge of the limited log space, especially if the lease is 7 days (a lot of other stuff will be logged).

75% was some hours ago and I didn't saw anything logged (and no renewal happened), I also enlarged the log space...

Close... 50%... if unsuccessful, it tries again, first at 87.5%, and finally again at 100% (when it must release the lease if it does not get a renewal).

But this may explain it, if the second attempt is at 87.5% I have to wait a bit more.

How much time is currently remaining (or when was the last renewal)?

Right now ~1d 3h are remaining to the current lease, so I expect the 87.5% in 6 hours or so.

I may have missed the 50% as it was some days ago, now I have a larger system log if it happens again.

I was just interested in the reason which led the renewal to fail at 50%, if an attempt was made. Let's see in a few hours :slight_smile:

The DHCP client will keep trying to contact the DHCP server many times between T1 (50%) and T2 (87,5%), then it will start broadcasting to find other DHCP servers which can prolong the lease.

Well I don't think this is happening :slight_smile:
T2 just passed (now the 'expires' time is less than 21 hours) but I still don't see any log from udhcpc.
I see however the process running:

# ps -w |grep -i udhcpc
 3301 root      1144 S    udhcpc -p /var/run/udhcpc-eth1.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth1 -x hostname:OpenWrt -C -R -

Easy to verify:
opkg update; opkg install tcpdump; tcpdump -i eth1 -vnn udp port 67

1 Like

Thanks!
I guess I need to leave that running, correct?

Yes, correct.

So, 10 hours have passed, no log from tcpdump on port 67 or from udhcpc in general.

Not sure what should happen after the T2 though.

A question that may or may not be related: what does happen if I just set the interface WAN with a static IP instead of DHCP client?

What happened now is that the lease expired and I got a renewal, because the interface went down and udhcpc restarted:

udhcpc: started, v1.36.1
udhcpc: broadcasting discover

While this works, it is not ideal because I have some seconds of down time (some apps for example stopped working for some seconds).

So now that I'm not waiting anymore I can do some experiments: I switched to a static IP instead of DHCP client (knowing that my IP is always the same) and things are working: internet connectivity works and no udhcpc process is running of course.

What could happen in this case? On LAN side usually this works fine, so I guess this may work and simply remove the need of a DHCP renewal in my case.

Please run the following commands (copy-paste the whole block) and paste the output here, using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have

ubus call system board; \
uci export network; uci export dhcp; uci export firewall

It depends on how the ISP treats customers who don't ask for DHCP. It may work, or they may block you because you didn't use the DHCP.

Just an update: more than 2 weeks have passed and I did set the static IP. It seems to work fine, no disconnections, interface is up since more than 2 weeks so I guess my ISP is fine with this.

While solving the issue would have been good, I think the static IP solution is even better in my case :slight_smile:

1 Like

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Thanks! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.