Score:2

Send notification when the network route changes

sd flag

I have 2 network interfaces:

  • ethernet enp2s0 with default metric 1
  • mobile enx0 with default metric 2

When Ethernet goes down, the metric changes and vice versa. I am getting in systems notifications something like this:

systemd-resolved[628]: enp2s0: Bus client set default route setting: no
systemd-resolved[628]: enx0: Bus client set default route setting: yes

When the Ethernet connection is restored, it changes back:

systemd-resolved[628]: enp2s0: Bus client set default route setting: yes
systemd-resolved[628]: enx0: Bus client set default route setting: no

I have Ubuntu SystemD, and I have self-written script to send any notifications via one of public messengers, so in my case there will be 2 scenarios:

  1. send_messenger.sh "me" "the traffic is routed through 4g connection from now, please, be patient" when Ethernet is down and the modem enabled

  2. send_messenger.sh "me" "ethernet is back, the normal bandwidth is available" when Ethernet goes back.

What may be a systemd service which may trigger that script when the default route changes? Or one of the network interfaces is disconnected?

vn flag
Did you try [monitoring DBus](https://stackoverflow.com/a/2261815/4970442)? [This example](https://unix.stackexchange.com/a/28183/209677) might be useful
Oleksa avatar
sd flag
Thanks! A bit complicated... I thought about unit services, but need more help in configuring...
waltinator avatar
it flag
I've written a bash script to help with this: `https://github.com/waltinator/net-o-matic` It watches the connection, and when the connection drops, does a user-specified thing to try to reconnect. You're welcome to adapt as needed.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.