On 12 December 2017 at 21:53, steve-ALUG@hst.me.uk wrote:
OK, so you're headless, so I'm assuming connection via ssh (or telnet).
Actually what I'm trying to achieve is that it happens via a script (new settings put onto a USB key, which is read automatically and settings updated accordingly). The update process works fine except that a reboot is often needed to take effect.
During testing I frequently connect the Pi to a TV and keyboard if needed, although the reality is that I often do it via SSH and don't lose the connection because it doesn't work.
Anecdotally, what seems to be the case is that new addresses get picked up but old ones don't die. So if I have a DHCP connection via Ethernet and set a static IP then restart dhcpcd, I get a new static IP but remain connected on the old DHCP address. If I change to a different static IP then the new one gets added but the old one remains too. (ifconfig doesn't reflect this accurately.)
Similarly, if I have wifi settings and an active connection, then remove the wifi settings and do wpa_cli reconfigure, then I remain connected until after a reboot.
Then I what springs to mind is ifup and ifdown which bring up and take down the network interface respectively, similar to what was discussed here: https://askubuntu.com/questions/441619/how-to-successfully-restart-a-network...
$sudo ifdown eth0 ifdown: Unknown interface eth0
(ifconfig lists my interfaces as eth0, lo and wlan0. ifdown wlan0 has same effect.)
However, Googling that suggests that "sudo ifconfig eth0 down" is a better alternative and that does seem to work better (subject to a bit more testing!)
Also, if you have a dhcp server, even though the client is releasing the IP address, it could be that the dhcp server sees the same machine reconnecting to it, and says "I'll give you the same ip address as you're already in my lease table", [...]
That bit I'm fine with. It's when switching from DHCP to static and I end up with both addresses or something else inconsistent happens that I have a problem with!
I think really what I'm trying to find out is how I'm supposed to restart networking to take new settings into account, then I can see what isn't working and debug it accordingly. Back in the day I used to use "sudo /etc/init.d/networking restart" but that (and the systemd equivalents) no longer seem to achieve anything useful.