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