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 ?

If none of the specific sub-forums seem right for your thread, ask here.
Message
Author
Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#16 Post by Chrisdb »

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?
The script should indeed be located at:

Code: Select all

etc/NetworkManager/dispatcher.d
Did you try with sudo?
What's the exact command and error you got?

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#17 Post by parkerc »

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 ?

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#18 Post by Chrisdb »

What desktop environment are you using? Gnome, xfce, ...

Anyway, the easiest way is to use the terminal and copy the file with 'sudo'.

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#19 Post by parkerc »

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

Code: Select all

 sudo cp /home/me/Documents/up-vpn.sh /etc/NetworkManager/dispatcher.d/
However after a few reboots, it’s still not auto firing the VPN?

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.

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#20 Post by Chrisdb »

What is the output of:

Code: Select all

ls -l /etc/NetworkManager/dispatcher.d/up-vpn.sh
And:

Code: Select all

systemctl status NetworkManager-dispatcher.service
What does the following command say if you run it from the terminal:

Code: Select all

sudo nmcli connection up id nl2-nodecentral-udp-udp

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#21 Post by parkerc »

Chrisdb wrote:What is the output of:

Code: Select all

ls -l /etc/NetworkManager/dispatcher.d/up-vpn.sh
-rwxr-xr-x 1 root root 430 Feb 29 20:25 /etc/NetworkManager/dispatcher.d/up-vpn.sh
Chrisdb wrote:What is the output of:
And:

Code: Select all

systemctl status NetworkManager-dispatcher.service
● NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service
Loaded: loaded (/lib/systemd/system/NetworkManager-dispatcher.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Chrisdb wrote:What is the output of:
What does the following command say if you run it from the terminal:

Code: Select all

sudo nmcli connection up id nl2-nodecentral-udp-udp
Error: Connection activation failed: Connection 'nl2-nodecentral-udp-udp' is already active

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#22 Post by parkerc »

I’ve just turned the vpn off and run the last command again

Code: Select all

 sudo nmcli connection up id nl2-nodecentral-udp-udp
A password is required to connect to 'nl2-nodecentral-udp-udp'.
Warning: password for 'vpn.secrets.password' not given in 'passwd-file' and nmcli cannot ask without '--ask' option.
Error: Connection activation failed: No valid secrets
The link originally shared gives me a couple of options

https://wiki.archlinux.org/index.php/Ne ... stablished
Trying to connect with the above script may still fail with NetworkManager-dispatcher.service complaining about 'no valid VPN secrets', because of the way VPN secrets are stored. Fortunately, there are different options to give the above script access to your VPN password.

1: One of them requires editing the VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring that will be inaccessible for root: open up /etc/NetworkManager/system-connections/name of your VPN connection and change the password-flags and secret-flags from 1 to 0.

If that alone does not work, you may have to create a passwd-file in a safe location with the same permissions and ownership as the dispatcher script,

2: Alternatively, change the password-flags and put the password directly in the configuration file adding the section vpn-secrets:
Any recommendations?

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#23 Post by Chrisdb »

The choice is up to you, but if you're the only one using this system, I would use option 2 as it is easier tot accomplish

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#24 Post by parkerc »

Do you have any Idea why I have to store my credentials again, when I already have the username and password for the nl2.nodecentral-utp-utp VPN configuration stored in the Network Manager UI under ‘Identity’ ?

Looking under the NetworkManager/system-connections/ folder I have two connections listed.
nl2.nodecentral-utp-utp.nmconnection
Wiredconnection1
They look like they relate to the two connections I have listed on the Network Manager UI?
Unfortunately I can’t open the nmconnection file via the UI, it states that the file is of an unknown file type, but could the user/password be in there?

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#25 Post by Chrisdb »

If it doesn't work by using the GUI, check the file contents through your terminal.

What is the value of 'password-flags' and 'secret-flags'?

If both are set to '0', follow the guide from the arch Wiki you mentioned before:
create a passwd-file in a safe location (/path/to/passwd-file) with the same permissions and ownership as the dispatcher script, containing the following:

Code: Select all

vpn.secrets.password:YOUR_PASSWORD
Your script must be changed accordingly, so that it gets the password from the file:

Code: Select all

...
nmcli connection up id "$VPN_NAME" passwd-file /path/to/passwd-file
...

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#26 Post by parkerc »

Thanks for all your help on this.

Opening the nl2-nodecentral-udp-udp.nmconnection file in nano I can see under the [vpn] section the flag is set to 1

Code: Select all

[vpn]
password-flags=1
So using option 2, I’ll need to add the following new [vpn-secrets] section into the nl2-nodecentral-udp-udp.nmconnection file

Code: Select all

[vpn-secrets]
password=your_password
Sound correct to you , as I’ve tried the above, and also did a reboot or two, but the VPN is still not starting automatically ?

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#27 Post by Chrisdb »

Rerun the 'nmcli' command manually again (after reboot) and post the output

Code: Select all

sudo nmcli connection up id nl2-nodecentral-udp-udp
Also please post your final up-vpn.sh file again

EDIT:
You did change the password-flags to 0?

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#28 Post by parkerc »

Chrisdb wrote:Rerun the 'nmcli' command manually again (after reboot) and post the output
You did change the password-flags to 0?
No, let me try that...

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#29 Post by parkerc »

Chrisdb wrote:Rerun the 'nmcli' command manually again (after reboot) and post the output

Code: Select all

sudo nmcli connection up id nl2-nodecentral-udp-udp
Also please post your final up-vpn.sh file again

EDIT:
You did change the password-flags to 0?
I’ve rebooted the VM , logged in again but the VPN did not start automatically.. :(

When I rerun the following command, via the terminal...

Code: Select all

 sudo nmcli connection up id nl2-nodecentral-udp-udp
it gave me this message..
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2
So the up-vpn script seems to work, the issue is getting it to automatically run once i’m logged in ?

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#30 Post by Chrisdb »

Also please post your final up-vpn.sh file again
:roll:

Look at the journal:

Code: Select all

sudo journalctl -u NetworkManager-dispatcher.service

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#31 Post by parkerc »

:oops: - that was it !! I’m so sorry...

School-boy error - I had been checking/changing the vpn name to try out other connections, and it looks like the one in up-vpn.sh was slightly different, and that looks like it was the issue.

It’s looking good now :-).

Thank you so much..

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#32 Post by parkerc »

Hi,

I’m noticing that the automatic turning on of the vpn, often fails and I think it’s because it occurs too quickly - as running it again it normally works.

Is there a way to slightly delay the execution of the up-vpn.sh script ?

Or is there maybe a way it could retry the connection again, if first unsuccessful (e.g try up to 5 times if needed before reporting a failure?)

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#33 Post by Chrisdb »

parkerc wrote:Hi,

I’m noticing that the automatic turning on of the vpn, often fails and I think it’s because it occurs too quickly - as running it again it normally works.
It cannot start too quickly as the script is only started when the interface is up and running (issued by event).

check journal:

Code: Select all

sudo journalctl -u NetworkManager-dispatcher.service
oliverm wrote: I have the same problems.I’m really interested in all VPN world, so would be great if you do more this type of question and answers about how/where/when to use a VPN
Start a new thread with your question.

parkerc
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

#34 Post by parkerc »

Thanks @Chrisdb
Chrisdb wrote: It cannot start too quickly as the script is only started when the interface is up and running (issued by event).

check journal:

Code: Select all

sudo journalctl -u NetworkManager-dispatcher.service
This was what was reported in the journal...

Code: Select all

-- Logs begin at Wed 2020-03-04 19:57:43 GMT, end at Thu 2020-03-05 14:02:02 GMT. --
Mar 04 19:57:55 debian-x234 systemd[1]: Starting Network Manager Script Dispatcher Service...
Mar 04 19:57:55 debian-x234 systemd[1]: Started Network Manager Script Dispatcher Service.
Mar 04 19:57:57 debian-x234 nm-dispatcher[569]: req:1 'hostname': new request (2 scripts)
Mar 04 19:57:57 debian-x234 nm-dispatcher[569]: req:1 'hostname': start running ordered scripts...
Mar 04 19:57:58 debian-x234 nm-dispatcher[569]: req:2 'connectivity-change': new request (2 scripts)
Mar 04 19:57:58 debian-x234 nm-dispatcher[569]: req:2 'connectivity-change': start running ordered scripts...
Mar 04 19:58:04 debian-x234 nm-dispatcher[569]: req:3 'up' [ens3]: new request (2 scripts)
Mar 04 19:58:04 debian-x234 nm-dispatcher[569]: req:3 'up' [ens3]: start running ordered scripts...
Mar 04 19:58:04 debian-x234 nm-dispatcher[569]: req:4 'connectivity-change': new request (2 scripts)
Mar 04 19:59:12 debian-x234 nm-dispatcher[569]: Error: Connection activation failed: The connection attempt timed out
Mar 04 19:59:12 debian-x234 nm-dispatcher[569]: req:3 'up' [ens3], "/etc/NetworkManager/dispatcher.d/up-vpn.sh": complete: failed with Script '/etc/NetworkManager/dispatcher.d/up-vpn.sh' exited with error status 4.
Mar 04 19:59:12 debian-x234 nm-dispatcher[569]: req:4 'connectivity-change': start running ordered scripts...
Mar 04 19:59:22 debian-x234 systemd[1]: NetworkManager-dispatcher.service: Succeeded.

Chrisdb
Posts: 279
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

#35 Post by Chrisdb »

The connection attempt timed out...strange...

You're sure the following command works if you run it manually:

Code: Select all

sudo nmcli connection up id "$VPN_NAME"
There's not much more to go on here, we have to enable extra logging.
Edit the file '/etc/NetworkManager/NetworkManager.conf' and add (or change to INFO):

Code: Select all

[logging]
level=DEBUG
Then reboot and check the journal again with the command I provided before.

Also just to be sure, post your final 'up-vpn.sh' file.

EDIT:
Can you also post output of file: '/var/log/messages'

Post Reply