Sunday, March 3, 2024

Raspberry Pi fails silently to get IP address if it’s already in use

 An interesting experience while working on some raspberry pi’s around here the other day. After a power failure the network was strangely and randomly hosed up due to what turned out to be a corrupt ARP table in the main switch that had a stroke when the power came back on. After I replaced the switch everything came back to life except a single Raspberry Pi which remained offline. 

I could still reach it via ssh and it seemed to be happy that way. This was using the local network name. Trying to ping it via it’s local network name failed, but succeeded when using just the static IP address.

I then ssh’ed into it via it’s IP address and found myself connected to a totally different Raspberry Pi that is sitting on my workbench getting reloaded as it’s CF card died and needed to be rebuilt. I had obviously confused the machines when looking up what their static IP addresses should be and had assigned this new rebuilt one the wrong IP. 

I returned to the ssh session with the device having a problem and ran ifconfig to see what it thought it’s IP address was. It had a full set of all the IPv6 information necessary, and that is what ssh was using, but it had no IPv4 address assigned at all. 

There was no error message I could find, nothing in dmesg, nothing in the systemctrl status for the dhcpcd service. Just no IPv4 address. 

I fixed the new one to have the proper IP address and rebooted them both and they both came back just fine. I suppose it I had been running the GUI version of the OS on either one of them I’d have gotten a “someone else is using your IP address” type error, but without I did not see why the machine seemed only partially available over the network.

It took far too long to figure out what was going on because no errors seemed to be generated. If I had not figured it out when I did I suppose it would eventually have occurred to me to check the dhcpcd logs, if there are some somewhere. 

No comments:

Post a Comment

.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }