Automate connections in NetworkManager...


Recommended Posts

Im using a GUI version compatible with NetworkManager for connection to a OpenVPN server....

Actions are these:

1: eth2 goes up

2: As soon as eth2 goes up, it must connect to the VPN

3: As soon as it connects to the VPN, it must run a script as root.

How do I automate steps 2 and 3? Im trying using /etc/NetworkManager/dispatcher.d but I cant get it to work.

Thank you

You can probably use /etc/NetworkManager/dispatcher.d/01ifupdown (which was installed on my system by default) as reference. Using ifup to detect the status of eth2 seems like the right way to do it. You can then inform NetworkManager to connect to your VPN through the command-line client, nmcli. Is that enough to get you started?

You can probably use /etc/NetworkManager/dispatcher.d/01ifupdown (which was installed on my system by default) as reference. Using ifup to detect the status of eth2 seems like the right way to do it. You can then inform NetworkManager to connect to your VPN through the command-line client, nmcli. Is that enough to get you started?

Somewhat....

nmcli dev doesnt show my openvpn BUT nmcli con does.....What should I use?

Somewhat....

nmcli dev doesnt show my openvpn BUT nmcli con does.....What should I use?

Your OpenVPN connection is not a device; that's why it doesn't show up using nmcli dev. Try something like this: nmcli con up c9373060-1fc6-40af-8788-e74ecf2d44c1 iface eth2

I'm not sure how much this will help, but it is somewhat related. The following is an excerpt from a Perl script I wrote to automate a task with NetworkManager:


# Bring our Network Manager connection up.
sub nm_con_up
{
my $myiface; # Interface from $conf to bring up.
my $mytimeout; # Timeout from $conf to pass to nmcli.

$myiface = $conf->iface;
$mytimeout = $conf->timeout;

@towt = qx[nmcli con up uuid ${NM_UUID} iface ${myiface} --timeout ${mytimeout} 2>&1];
$towt[0] =~ /Error: Unknown connection: ${NM_UUID}/i and die "Our profile is not registered with Network Manager!\n";
$towt[0] =~ /[E|e]rror[.]*[T|t]imeout[.]*[E|e]xpired[.]*/ and return 0;
return 1;
}
# Take our Network Manager connection down.
sub nm_con_down
{
my $myiface; # Interface from $conf to bring up.
my @status; # Network Manager status output.
my $is_down; # Is the interface down?

$myiface = $conf->iface;
@status = qx[nmcli con status 2>&1];
$is_down = 0;
for my $elem (@status)
{
if ($elem =~ /${NM_UUID}/)
{
@towt = qx[nmcli con down uuid ${NM_UUID} 2>&1];
$is_down = 1;
}
elsif ($elem =~ /${myiface}/)
{
my @tokens; # Tokenized version of the element.
my $myuuid; # UUID associated with $myiface.

@tokens = split(/[ ]+/, $elem);
foreach my $token (@tokens)
{
if ($token =~ /[a-f0-9]{8}[-]([a-f0-9]{4}[-]){3}[a-f0-9]{12}/)
{
$myuuid = $token;
last;
}
}

@towt = qx[nmcli con down uuid ${myuuid} 2>&1];
$is_down = 1;
}
}

die "Network connection could not be taken down!\n" unless $is_down == 1;
}
[/CODE]

Your OpenVPN connection is not a device; that's why it doesn't show up using nmcli dev. Try something like this: nmcli con up c9373060-1fc6-40af-8788-e74ecf2d44c1 iface eth2

Will the UUID always be the same??? If so, I think I may be able to do it with what you said before...

Im seeing a file in etc/network/if-up.d where there is a file called openvpn.

Can I put code in there? Will it run as root?

The UUID will not change unless you delete and recreate the connection in NetworkManager. You can use nmcli con list to view the UUIDs of the connections you have created.

From what I can tell I think you had the right idea before. Don't modify your OpenVPN config in if-up.d; create a new file in dispatcher.d instead.

The UUID will not change unless you delete and recreate the connection in NetworkManager. You can use nmcli con list to view the UUIDs of the connections you have created.

From what I can tell I think you had the right idea before. Don't modify your OpenVPN config in if-up.d; create a new file in dispatcher.d instead.

This might be a stupid questions but is UUID sensitive? I know MAC addresses should not be posted just like public IPs.....but I have no idea what this UUID is....

I ask because I want to put the potentional script here and see what you think :)

The UUID is generated by NetworkManager. If you create a connection, delete it, then recreate it, NetworkManager will assign it a different UUID. The UUID is merely a way for NetworkManager to uniquely identify the network connections it has stored. It is not sensitive information like your MAC address, which is permanently embedded into your network card.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Those people that come over here on boats are already in a safe country, if they want to come over here then do so correctly though the right channels. I was born in the U.K, my family that came over here came so via the proper means. My partner came here via the correct channels, she also became a British citizen, she knows more about this country than most of them that was born here, including myself, she worked hard to do what she does. She will stick up for this country and have done a few times, when people from her own part of world have put the U.K down. We are not going to agree, all I said to start with is that maybe Trump has the right idea with this America first thing and maybe we should start doing the same. Maybe not as drastic as what he is doing, but we do need to sort this country out, we need to sort out tech instead of relying on the U.S and others. Again you have not shown why you are so annoyed that we have left the E.U and this is what it is all about? If you don't live in the U.K and live in the E.U are you annoyed that we left your little club? If you live in the U.K and is pro-E.U, then fair enough then I can see how it annoys you. Are you one of these people who lives in the U.K and have a holiday chalet in the E.U and can now only stay there for so long? If so, then that is bad luck. As I have posted before, I have no problem with people coming here to work, as long as they do if via the proper channels. We are out of the E.U, people voted out, and maybe if more people had voted instead of sitting on their backsides the results would have been different. But they like the E.U and our government thought no we would not vote to leave. How wrong they were, surprised me. I expected to wake up in the morning and hear on the radio that we voted to stay. As I said, we are out and have been for 10 years, we are not going to go back in anytime soon if we ever do, so we all need to make the best of how things are. Anyway, this is supposed to be a tech site.
    • Tim Cook: "The US over time began to stop having as many vocational kinds of skills." What's the point of wasting time getting those skills if you can't get a job with them? Good Lord, maybe he and his cohort of CEO's who exported all these jobs to China should just shut the f**k up :D
    • I made a new Cinematic/Trailer for the game, this will be the intro, still a work in progress!  I also updated the Steam page with a ton of new screenshots! 👀 https://store.steampowered.com/app/3925340/Incoherence_Dark_Rooms/  
    • Closed-loop cooling and a custom 800G network protocol let the $7.3B campus run as one AI training machine. Microsoft confirmed June 23, 2026, that its Fairwater campus in Mount Pleasant, Wisconsin, is fully operational — and the engineering behind it makes the facility something fundamentally different from every data center that came before it. Where conventional cloud infrastructure racks up general-purpose servers and parcels out workloads to each one independently, Fairwater links hundreds of thousands of NVIDIA GB200 Blackwell GPUs into a single, coherent cluster using a two-story building design, 800-gigabit-per-second Ethernet fabric, and a proprietary networking protocol co-developed with OpenAI and NVIDIA. The result, according to Microsoft, is the closest thing to a purpose-built AI supercomputer that any company has ever placed in commercial operation. https://www.techtimes.com/articles/319205/20260627/microsoft-opens-fairwater-wisconsin-ai-campus-runs-one-supercomputer-via-800g-ethernet.htm  
  • Recent Achievements

    • Conversation Starter
      jessse3334 earned a badge
      Conversation Starter
    • Reacting Well
      JuvenileDelinquent earned a badge
      Reacting Well
    • One Month Later
      Excellence2025 earned a badge
      One Month Later
    • Week One Done
      Excellence2025 earned a badge
      Week One Done
    • Week One Done
      flexorcist earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      501
    2. 2
      +Edouard
      211
    3. 3
      PsYcHoKiLLa
      150
    4. 4
      Steven P.
      73
    5. 5
      macoman
      62
  • Tell a friend

    Love Neowin? Tell a friend!