Before marking as a duplicate: this is not about dynamic DNS or similar things.
I know how to run a script every time my networks goes up; it is a simple matter of adding a script in the directory
/etc/NetworkManager/dispatcher.d like this one:
#!/bin/bash IF=$1 STATUS=$2 case "$2" in up) logger -s "NM Script up $IF triggered" su rmano -c /home/romano/bin/myscript ;; down) logger -s "NM Script down $IF triggered" ;; *) ;; esac
In my case,
myscript is a very simple
ifconfig -a > ~/Dropbox/myifconfig.txt --- I use it because I need to know my local IP from everywhere in the University, and it will change often.
So far so good, the system works ok. But unfortunately the DHCP here is configured so that the IP sometime is changed without a down/up of the interface. In that case the script is (logically) not run, and the file is not updated.
I cannot use a DynDNS approach because the change is in the local IP, not the externally visible one.
I could poll, by simply putting the script in cron and execute it every minute or write a slightly more complex one (...if the IP is changed write the file otherwise do nothing) and putting it again as a background task, but it is not elegant. So the question is:
Is there any way to trigger a script when my local IP changes?
I tried to put a script in
/etc/dhcp/dhclient-enter-hooks.d/ , based on the existing
/etc/dhcp/dhclient-enter-hooks.d/resolvconf, but it will not be triggered. I suspect (confirmation needed) that NM (network manager) is doing the dhcp negotiation by itself, without calling the dhcp command...