Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Automatically start vpn on boot up ?
Automatically start vpn on boot up ?
Hi
I have the Network Manager set on my Debian 10 and a couple of VPN connections configured.
Is there a way I can have the VPN start-up automatically on login - I could not see a setting listed anywhere for this
I have the Network Manager set on my Debian 10 and a couple of VPN connections configured.
Is there a way I can have the VPN start-up automatically on login - I could not see a setting listed anywhere for this
Re: Automatically start vpn on boot up ?
Take a look at 'DISPATCHER SCRIPTS':
https://manpages.debian.org/stretch/net ... .8.en.html
An example for VPN can be found here:
https://wiki.archlinux.org/index.php/Ne ... stablished
https://manpages.debian.org/stretch/net ... .8.en.html
An example for VPN can be found here:
https://wiki.archlinux.org/index.php/Ne ... stablished
Re: Automatically start vpn on boot up ?
Thanks - ok - I’m still learning Linux - and while I have a rough idea what it’s trying to do - is there any chance you could help to make this relevant for a wired connection (not wireless)
Code: Select all
# file to be called /etc/NetworkManager/dispatcher.d/vpn-up
#!/bin/sh
VPN_NAME="name of VPN connection defined in NetworkManager"
ESSID="Wi-Fi network ESSID (not connection name)"
interface=$1 status=$2
case $status in
up|vpn-down)
if iwgetid | grep -qs ":\"$ESSID\""; then
nmcli connection up id "$VPN_NAME"
fi
;;
down)
if iwgetid | grep -qs ":\"$ESSID\""; then
if nmcli connection show --active | grep "$VPN_NAME"; then
nmcli connection down id "$VPN_NAME"
fi
fi
;;
esac
Re: Automatically start vpn on boot up ?
are you connecting with ethernet or wirelesss...
What's the name of your configured VPN
What's the name of your configured VPN
Re: Automatically start vpn on boot up ?
Hi, I’m connecting via Ethernet and looking in network manager , the vpn name is called uk-nodecentral-udpChrisdb wrote:are you connecting with ethernet or wirelesss...
What's the name of your configured VPN
Re: Automatically start vpn on boot up ?
Are you familiar with shell scripting...
If not, online are many tutorials to get you started.
If not, online are many tutorials to get you started.
Re: Automatically start vpn on boot up ?
I’ve read various online resources - but I don’t know whether it’s my age but anything programming language seems to be difficult for me - hence I have such admiration for those that just get it
I’d like to set up a Debian device as a sort of Kiosk mode - so that it only connects via a VPN, which I’ve been able to do (via ufw rules) - now the only hurdle left is the auto-connect - I naively thought that would be a simple setting in the UI (either enforce VPN or just to have VPN start on start up)
If you or anyone else could direct me in the changes required to the script above or event share a working example for wired connections that would be great
I’d like to set up a Debian device as a sort of Kiosk mode - so that it only connects via a VPN, which I’ve been able to do (via ufw rules) - now the only hurdle left is the auto-connect - I naively thought that would be a simple setting in the UI (either enforce VPN or just to have VPN start on start up)
If you or anyone else could direct me in the changes required to the script above or event share a working example for wired connections that would be great
Re: Automatically start vpn on boot up ?
I'm using my android phone here (typing not always correct ), but it should be something like this after a quick look:
Also to enable dispatcher, run:
Code: Select all
#!/bin/sh
VPN_NAME="uk-nodecentral-udp"
interface=$1 status=$2
case $status in
up|vpn-down)
nmcli connection up id "$VPN_NAME"
;;
down)
if nmcli connection show --active | grep "$VPN_NAME"; then
nmcli connection down id "$VPN_NAME"
fi
;;
esac
Code: Select all
sudo systemctl enable NetworkManager-dispatcher.service
Re: Automatically start vpn on boot up ?
Many thanks @chrisDB
I had been looking at the original script over the past couple of days to see what would need to change - and was getting confused if I needed to confirm eth0 first; before the VPN - but logically now I guess that’s an irrelevant call - because if the wired/Ethernet interface is down ; not much is going to happen
I had been looking at the original script over the past couple of days to see what would need to change - and was getting confused if I needed to confirm eth0 first; before the VPN - but logically now I guess that’s an irrelevant call - because if the wired/Ethernet interface is down ; not much is going to happen
Re: Automatically start vpn on boot up ?
Thinking about the associated Cron job
How frequently should something like this run?
* * * * * /etc/NetworkManager/dispatcher.d/vpn-up.sh
How frequently should something like this run?
* * * * * /etc/NetworkManager/dispatcher.d/vpn-up.sh
Re: Automatically start vpn on boot up ?
It shouldn't be scheduled because it is event triggered.
F.e. UP = when the interface has been activated.
F.e. UP = when the interface has been activated.
Re: Automatically start vpn on boot up ?
Ok, that’s cool to know.
A few follow on questions
As it’s an event / does that mean within the above script if the vpn goes down - can I explore adding additional lines to notify me via e.g an email or some other messaging facility ?
In situations where the VPN does go down - but the failure is on the provider/server side - will it keep trying every x seconds or x minutes to restart the connection - will it try indefinitely ?
Is the enabling of dispatcher a one time thing or does it need to be done every time?
A few follow on questions
As it’s an event / does that mean within the above script if the vpn goes down - can I explore adding additional lines to notify me via e.g an email or some other messaging facility ?
In situations where the VPN does go down - but the failure is on the provider/server side - will it keep trying every x seconds or x minutes to restart the connection - will it try indefinitely ?
Is the enabling of dispatcher a one time thing or does it need to be done every time?
Re: Automatically start vpn on boot up ?
- yes you can add extra functionality in your script within the if block
- restart depends on options used with nmcli, there is a 'wait' option, but I would advice against it
- systemctl enable command is required only once
- restart depends on options used with nmcli, there is a 'wait' option, but I would advice against it
- systemctl enable command is required only once
Re: Automatically start vpn on boot up ?
Hi @chrisDB
Before I try to enhance it - I’m sadly still unable to get the script to work Here’s what I’ve done so far..
1) Created a .sh file and called it up-vpn.sh - and is stored in /home/me/Documents/
2) Made it an executable by running this command
3) And then finally I run this command ?
What am I missing to have this start automatically; does something not need to be set up to call it ?
Before I try to enhance it - I’m sadly still unable to get the script to work Here’s what I’ve done so far..
1) Created a .sh file and called it up-vpn.sh - and is stored in /home/me/Documents/
Code: Select all
# http://forums.debian.net/viewtopic.php?f=10&t=145355
#!/bin/sh
VPN_NAME="nl2-nodecentral-udp-udp"
interface=$1 status=$2
case $status in
up|vpn-down)
nmcli connection up id "$VPN_NAME"
;;
down)
if nmcli connection show --active | grep "$VPN_NAME"; then
nmcli connection down id "$VPN_NAME"
fi
;;
esac
# Also to enable dispatcher, run:
# sudo systemctl enable NetworkManager-dispatcher.service
Code: Select all
sudo chmod +x up-vpn.sh
Code: Select all
sudo systemctl enable NetworkManager-dispatcher.service
Re: Automatically start vpn on boot up ?
Also I had tried to place the up-vpn.sh file into /etc/NetworkManager/dispatcher.d/ but it said I couldn’t as I didn’t have permission or something?
Re: Automatically start vpn on boot up ?
The script should indeed be located at:parkerc wrote:Also I had tried to place the up-vpn.sh file into /etc/NetworkManager/dispatcher.d/ but it said I couldn’t as I didn’t have permission or something?
Code: Select all
etc/NetworkManager/dispatcher.d
What's the exact command and error you got?
Re: Automatically start vpn on boot up ?
I was using the UI and right click ‘copy to’ command option to move it over into that folder, but it wouldn’t let me
The message is along the lines that I do not have the permissions necessary to save the file there .
How do you ‘sudo’ via the UI ?
The message is along the lines that I do not have the permissions necessary to save the file there .
How do you ‘sudo’ via the UI ?
Re: Automatically start vpn on boot up ?
What desktop environment are you using? Gnome, xfce, ...
Anyway, the easiest way is to use the terminal and copy the file with 'sudo'.
Anyway, the easiest way is to use the terminal and copy the file with 'sudo'.
Re: Automatically start vpn on boot up ?
I’m just using the standard (out of the box) desktop, sorry not sure what that is called..
I have now managed to copy the file over via the command line using..
However after a few reboots, it’s still not auto firing the VPN?
Any ideas? Is there anything else I need to do ?
I have now managed to copy the file over via the command line using..
Code: Select all
sudo cp /home/me/Documents/up-vpn.sh /etc/NetworkManager/dispatcher.d/
Any ideas? Is there anything else I need to do ?
Last edited by parkerc on 2020-03-01 10:21, edited 1 time in total.
Re: Automatically start vpn on boot up ?
What is the output of:
And:
What does the following command say if you run it from the terminal:
Code: Select all
ls -l /etc/NetworkManager/dispatcher.d/up-vpn.sh
Code: Select all
systemctl status NetworkManager-dispatcher.service
Code: Select all
sudo nmcli connection up id nl2-nodecentral-udp-udp