I want to be certain this will work before I try it, since I'm dealing with a headless Pi (Zero W if it matters) that is only ever accessed via SSH.
I've set up an address reservation in my router for the Pi, this is more or less essential, both to simplify access via Putty, and for accessing the custom server running on the Pi.
The problem is that originally there wasn't a reservation, so it's at some other random address in the pool, rather than the fixed address in the "non-pool" area I've set aside for it. And patience hasn't fixed the issue: it's been steadfastly holding onto that address for several days now, rather than changing. I'm assuming a reasonable lease length e.g. 12 or 24 hours on the part of the DHCP server in the router here.
Obviously, if I just use dhclient -r
to release the lease, my current SSH session will abort, leaving things is a less than useful state. I also note that if you dhclient -r
there is a risk that it'll bring down the WiFi connection as well: see the warning at the bottom of this page for details.
So what is the likelihood that nohup (dhclient -r -d && dhclient) &
typed into a root bash session will (a) terminate the current lease, and then (b) attempt to turn WiFi back on if needed, and finally (c) obtain a new lease, hopefully with the correct address.
My reasoning is that using nohup
means it won't receive a SIGHUP
when the SSH session goes south, and putting it in a sub-shell in background means it has the highest chance of getting both commands executed.
Another option I've considered is nohup (dhclient -r && reboot) &
in a root bash session, the logic there is that rebooting the system should re-establish the WiFi connection, and then ping the DHCP server for an address. Hopefully the reserved one.
Failing both of these, what other options do I have to release and renew the lease, and finish with a running system connected to WiFi at the preferred address? As a last resort, I can see if I can figure how to attach a screen and keyboard, but I really don't want to have to do that, it'd be a fairly major pain.
dhclient
? RPi OS (née Raspbian) has long useddhcpcd
as the default DHCP client app. I wonder if all of your problems were due to usingdhclient
without telling the system you were making this change?