Forever changing IP!

Hi,

I have my Pi set to DHCP.

Now I know I could set it to a static IP, but as I sometimes take it out of the home, and for other reasons, I want it to stay as a DHCP client.

My box performs a check for updates and reboots everyday, and is always on.

Most days, I receive a brand new IP!

Now I know I could also set this in my router against my MAC address…

My question is, I remember seeing a configuration file somewhere with a setting that made a reference to trying to re-obtain the last known DHCP issued address.

For the life of me I cannot find that now, or has networking somehow fundamentally changed? Im not sure.

Anyway, any help on this issue would be appreciated. Static/MAC Setting from router isnt an option however.

I would set DHCP reservation in your router. Usually based on MAC, but can also be based on hostname. If you try to set it static from the PI, anytime your router reboots, your Pi reboots, or your DHCP lease expires, your router will release that address back to the DHCP pool. Ever try spitting water out of your mouth in a pool and then getting the same water back in you mouth (eww), lolz.

Sorry, can’t help on the other setting you’re asking about, but that would also be like a static, and would eventually give the same issue with IP conflicts. You can only manage DHCP assignment from the DHCP server.

Why is static/MAC not an option? Do you not have access to your router?

Another possible option is to set the lease time to 8000hrs or something similar.

i agree with @Quattrogam3r.

Thanks for the responses. I’m aware I can reserve the MAC address, but for a few reasons this is not practical.

Does anyone know of a persistent setting so the networking manager will automatically re-request it’s last known DHCP issued address?

I’m curious as to why MAC reservation is “impractical” in this situation? I think your choices here have been laid out though.

I think you’re missing the fundamentals of DHCP, you can’t do what your asking from the Pi, it has to be managed from the DHCP server… the Router. Anything you do from the Pi equates to setting static IP on the client end, you need to tell the router to keep the address reserved for the Pi.

A DHCP client may also request its last-known IP address. If the client remains connected to the same network, the server may grant the request. Reboots and taking it out of the home would likely not “remain connected.”

I think THAT’S why… :wink:

Believe me kind Sir, as a 30+ year Cisco engineer I have a perfectly clear grasp of DHCP!

My original question never was relating to preserving an address via my router, or setting a static IP.

My question was concerning a setting I had seen in place, in a configuration file, somewhere, that I can no longer find.

I never wanted answers or solutions relating to those suggested, hence my first post explaining so.

If anyone does know the magic bullet configuration file however, I would be keen to know where this setting may be!

It’s hardly ever taken out of the home, maybe 3/4 times per year, and this issue is occurring daily. It never used to when this other setting was in place, quite likely from a deprecated version of connman or other networking manager. I am trying to retrace the steps back to see if I can implement this again.

DHCP reservation by MAC address at the devices “home” location has nothing to do with taking it from one location to the other. But setting to static would definitely be a problem when moving between networks who may use different sub-netting schemes or may have already provisioned the address it was set to use.

If OP’s entire premise is to maintain the same IP no matter what location/network it was connected to, without DHCP reservation at each site, it’s not possible.

Wish I had an answer on some config file for you but I’m not aware of where you might have seen that. While I don’t know what router or current network config you have in place now, in my setup, using DHCP without MAC address reservation, my OSMC testing Pi has no issues maintaining it’s originally assigned IP address.

Thanks,

I realise I am approaching the problem from the reverse angle, however this setting was somewhere before.

I’ve sort of given up and I am writing some scripts now to do the job anyway, it’s just a few hours work/testing i’d prefer to avoid!

my rpi2 also maintains the same ip address even with repeated usb installs whether with osmc or openelec. i think it’s because the lease on the ip address hasn’t expired.

What DHCP server are you using? Is it Windows Server by any chance?

As you will know, DHCP discover will send the client’s previous lease and most servers will, where possible do their best to accommodate it. There is a bug / feature in Windows Server where this does not always occur.

Sam

A range of DHCP routers. Most are perfect, but some, for example TalkTalk or ZTE routers do not like re-issuing the same address, however if it is statically set, it works. Other routers, Netgear, Cisco, Zyxel work lovely.

I don’t suppose you know about the setting I was talking about in systemD is?

We don’t use systemd’s built in network manager, we use connman.

1 Like

I knew someone would lead my to the right setting, eventually!

So, for anyone elses reference…

In /var/lib/connman/ are ethernet settings files based on MAC adddress.

Within those files is this line:

IPv4.DHCP.LastAddress=192.168.1.4

It appears, in my case, that somehow (possibly due to crash/sudden reboot) I had a number of these files named identically, each with different last known DHCP ip’s within.

My understanding from a little googling is this is the first address it will try to re-requests from the DHCP server.

In my case, because of the duplicate files with different DHCP addresses, it seemed to pick a different file upon each reboot.

My solution was to delete them all, and upon reboot only one file is created, and just for future proofing I have set a script to send me an email if duplicates are detected so I need to look at deleting one or more or all of them.

Thanks for the nudge in the right direction DBMandrake, that is all I needed!

Interesting,

I see similar old copies of the settings file in my ethernet configuration directory:

root@vero:/var/lib/connman/ethernet_d063b4006a03_cable# ls -al
total 28
drwx------ 2 root root 4096 Oct 14 12:22 .
drwxr-xr-x 5 root root 4096 Oct 14 12:22 ..
-rw------- 1 root root 4096 Oct 14 12:22 data
-rw------- 1 root root  184 Oct 14 12:22 settings
-rw------- 1 root root  185 Jul  8 20:55 settings.5MC00X
-rw------- 1 root root  185 Jul 27 22:27 settings.XO581X
-rw------- 1 root root  183 Jul 29 10:58 settings.ZE6F2X

As you say they are most likely caused by an unclean shutdown, (which I frequently am forced to do during certain types of testing) however I have not noticed these being here before.

I wouldn’t have thought that it should be picking one at random though - are you sure that this is the cause of your problem and that they are not harmless ?

cc @sam_nazarko