[RPi4] How to change DHCP IP lease time?

  • Hi,

    I'm running 12.0.2 on an RPI4B and so far everything seems to work fine apart from DHCP.

    I disabled both bluetooth and wifi. I'm using a network cable to connect to the lan.

    Problem is,when DHCP is selected, it always defaults to 192.168.1.126, even when I setup my router to assign 192.168.1.5 to the MAC used by the RPI.

    I noticed that when I use the command ip address, it outputs:


    What I want to try is to change the value for "valid_lft" and "preferred_lft" which seems to be set to forever.

    How do I change these two settings?

  • Problem is,when DHCP is selected, it always defaults to 192.168.1.126

    The output of ip a that you shared disagrees with that statement as it clearly shows eth0 is assigned 192.168.1.5/24 as configured in the router. What makes you think it has the address 192.168.1.126 ?

    The lifetime values can be manually changed with:

    Code
    ip a change <ip> dev eth0 valid_lft <value> preferred_lft <value>
  • The output of ip a that you shared disagrees with that statement as it clearly shows eth0 is assigned 192.168.1.5/24 as configured in the router. What makes you think it has the address 192.168.1.126 ?

    Oops, sorry for the confusion, that was after I changed the network settings from DHCP to a manually assigned address...

    If I changed the network settings back to DHCP, it magically selects 192.168.1.126, despite my router telling it should assign 192.168.1.5.

    With my old RPI3B with Libreelec 9.2.6 it worked fine.

    The lifetime values can be manually changed with:

    Code
    ip a change <ip> dev eth0 valid_lft <value> preferred_lft <value>

    Does that survive a reboot?

    Thanks for trying to help.

  • The “ip a” command won’t survive a reboot but it’s trivial to put into an autostart.sh script or systemd service that’s executed on each boot.

    Have you tested whether it’s something simple like the router not matching the MAC due to uppercase or lowercase letters. Some routers are crap like that. What’s logged on the router?

  • The “ip a” command won’t survive a reboot but it’s trivial to put into an autostart.sh script or systemd service that’s executed on each boot.

    I tested with the ip a change command using a time of 15 minutes (for testing) and after 15 minutes it renews and it sets the

    "valid_lft" and "preferred_lft" again to "forever"...

    Have you tested whether it’s something simple like the router not matching the MAC due to uppercase or lowercase letters. Some routers are crap like that. What’s logged on the router?

    The mac adresses set in the router are all lowercase and they all work except for the RPI (it does work for my older RPI with an older version of Libreelec).

    Unfortunately, the FW of the router is adapted for my ISP and can only be configured using a webbrowser.

    For the moment I can work around it and it's not a showstopper. When I have time I'll use wireshark to see what's going on between the RPI and the router regarding DHCP.

    It's just that I'm a bit stubborn and curious about how these things work and I really want to know where I can find these lowlevel networksettings.

  • I did some research and, if I'm not mistaken, Libreelec uses Connman for network management which is very lightweight and simple to use but also lacks many options like configuring the dhcp lease time.

  • Yup, ConnMan is lightweight and perfect for our 'embedded' distro needs. If you're building a minimalist distro you don't look to include all the full-fat binaries of a general purpose OS. As long as it works for 99.99999% of users (and it does) we're good. You're the only person I can recall ever reporting this issue; and that means it's probably something environmental, i.e. something specific to do with your network or equipment (the router).

    NB: The DHCP lease time is defined by config/policy on the DHCP server (router) not the client device that makes DHCP requests. So even if we did have a full-fat DHCP client tool it will work the same way. ConnMan did allow you to change lifetime values; but this is a dynamic protocol so when you send a renewal request and the server responds with a valid lease value, the values are overwritten.

  • connman dhcp is always requesting the recent "IPv4.DHCP.LastAddress" first.

    As long the dhcp server accept this request the address will not change.

  • What router do you have ? If its a Fritzbox you find the setting under "Heimnetz>Netzwerk>Netzwerkeinstellungen scroll that page down to the bottom, there you will find "weitere Einstellungen" click that and it expands, then choose "IPV4 Einstellungen" on that page you find the DHCP Server settings including "Gültigkeit" (lease time) thats the setting you are looking for. The leasetime is always set by the server not the client.