OS 11.3 with NetworkManager - script on network up?

Hi, I have a fresh install of OS 11.3 on a notebook with Gnome and need to run a script when the network comes up. In earlier versions I would have used if-up.local. Where can I put this with NetworkManager?

Additionally I would like in the script to distinguish between wired/wireless network & mobile/bluetooth connect. Any advice on where I can find the connection type?


This is not a definite answer, buta bit of brainstorming.
When you use network manager, the network only starts when a user (which one?, the first one after there is nobody loged in?) logs in into the GUI (in your case probably Gnome). Thus a script should be at a complete dfiiferent place, may be triggered somewhere from the users start-up (KDE has an Autostart feature).

Yes, I agree. It should be part of the user config. It also starts (for the first user) after the user has logged in - there’s a time until the keychain is unlocked. For the second user it starts as the user logs in because of network link sharing. Also it needs to run when the network comes back up after suspend …

Maybe a udev rule?

How would a udev rule work? Can you point me at docs (preferably a starter guide)?

Explain please.

I thought udev worked on events of devices (dev = device) (dis)connecting.

Based on some earlier research I did,
It really depends on what you’re trying to do and exactly when… Depending on how your system is configured, network configuration may not happen until long after the network service starts and your network device(s) enabled.

In any case, if you search in these forums or threads I’ve participated in and usually started, you’ll find some discussions on the merits of configuring rc.d scripts and sysctrl.

On the topic of udev, IMO it’s generally not appropriate unless whatever you’re doing has to do with device recognition and the most basic of device configuration… not higher level configurations.

You might find useful the page I wrote for an article “Optimizing TCP/IP” where I describe using sysctrl to modify and configure non-default TCP/IP resources and configuration, as I note it might not be the absolutely most efficient way to do it but is absolutely the most universal cross-distro way incorporating script error-checking at the same time (invalid commands won’t mung your system).

Optimize and Fix your Network Connection - Su Networking Technical


I need to establish a VPN and then run a synchronise job when there’s a suitable network connection. I do it manually for now, but computers are all about automating and making simple repetitive tasks :wink:

I’ll check out your answers and page … thanks.

My post mainly applies to “primary network connections,” a VPN is what I call a “secondary network connection” which is possible only after the initial primary network connection is established.

Sorry I haven’t investigated exactly what you’re asking, typically in the past various network managers have included options for scripts but I don’t see that in knetworkmanager.

Sorry I couldn’t be more help without some research,

It’s actions after the primary network connection is established that I’m interested in …

Yes, I remember it from the past, and I also remember it from ip-up.local …

It seems to be missing from gnome networkmanager also. Maybe it’s missing in the base networkmanager implementation?

I think I’ll write a little background script that, every waits an minute and checks for the connection, then does the VPN & synchronisation. I thought I could be smart, but it seems the hooks aren’t there.

Thanks for the advice,

Without looking at the files involved at all, I’d still recommend a different approach…

First, I don’t see that polling should be necessary… I can see you’re thinking of your script as entirely independent which requires a mechanism for knowing when to activate.

Instead, I highly suspect that your script should be callable as a property of the VPN, it’s just not exposed by the GUI.
So, I’d instead recommend you setup your VPN first, then look for the configuration file that is probably created that describes the VPN properties… From there I’d guess there should either be some documentation on the Internet available on how you can further modify the configuration file manually or you can experiment.

Am assuming of course that whatever you want to happen in your custom script only executes once, and immediately after establishing a VPN connection.

Good Luck,

There’s the first step - knowing when to establish the VPN. I want it to come up just after the internet connect, or just after the notebook resumes from suspend (assuming the internet connect comes back up).

The second bit - triggering the synchronise from the VPN coming up is good - I’ll check it out.

The first bit I can probably do simply by either checking routing or the interface states.

Then there’s the other messing around (don’t do it too often - especially if the connect is unstable) :frowning: