How to run a systemd oneshot service whenever the system gets a new IPv6 address

d-busdhcpipv6networkingsystemd

I would like to run a systemd oneshot service whenever my system gets a new IPv6 address assigned to it from the network router (this would be on boot, and periodically throughout its uptime).

Ideally, this event would be only for IPv6 address updates, and not include potential IPv4 address changes.

Is it possible to monitor networkd dbus activity for this kind of event with systemd?

My ultimate goal is to hit a dynamic DNS endpoint whenever this happens, so that this system's IPv6 DNS record avoids going stale.

Best Answer

I wrote something like this many years ago, called (unimaginatively) autoddns.

It doesn't call a systemd service (I don't think systemd existed at the time!) but it does call an external process to perform the DNS update (nsupdate). It does however monitor IP address additions and deletions directly at the netlink level, which means it will pick them up no matter how they happen (manual administrative configuration, SLAAC, DHCP, Network Manager). It reacts instantaneously when changes occur. It does support filters (designed for automatically excluding things like link-local addresses), so you can get it to respect IPv6 address changes and ignore IPv4 ones, as you wish to do.

Perhaps you can use it or modify it to meet your needs. Most of the magic for detecting and reacting to IP address changes is in watchip.c, I think.

Related Question