Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 11528  / 3 Years ago, tue, july 20, 2021, 1:37:40

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?



UPDATE 1



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...


More From » networking

 Answers
1

According to the man page for NetworkManager-dispatcher, one of the events is


dhcp4-change

The DHCPv4 lease has changed (renewed, rebound, etc).

I think you can simply change


up) 

to


dhcp4-change|up)   

[#26414] Wednesday, July 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
poefor

Total Points: 379
Total Questions: 95
Total Answers: 115

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;