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

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

Re: Automatically start vpn on boot up ?

#36 Post by parkerc »

Here’s the more detailed log file after the VMs has booted up.

Code: Select all

 - Logs begin at Wed 2020-03-11 22:24:00 GMT, end at Wed 2020-03-11 22:26:56 GMT. --
Mar 11 22:24:08 debian-x234 systemd[1]: Starting Network Manager Script Dispatcher Service...
Mar 11 22:24:08 debian-x234 systemd[1]: Started Network Manager Script Dispatcher Service.
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname': new request (2 scripts)
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname': environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname': environment: NM_DISPATCHER_ACTION=hostname
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname': start running ordered scripts...
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname', "/etc/NetworkManager/dispatcher.d/01-ifupdown": run script
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname', "/etc/NetworkManager/dispatcher.d/01-ifupdown": complete
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": run script
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": complete
Mar 11 22:24:09 debian-x234 nm-dispatcher[550]: req:1 'hostname': completed (2 scripts)
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': new request (2 scripts)
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': environment: CONNECTIVITY_STATE=NONE
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': environment: NM_DISPATCHER_ACTION=connectivity-change
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': start running ordered scripts...
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change', "/etc/NetworkManager/dispatcher.d/01-ifupdown": run script
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change', "/etc/NetworkManager/dispatcher.d/01-ifupdown": complete
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": run script
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": complete
Mar 11 22:24:10 debian-x234 nm-dispatcher[550]: req:2 'connectivity-change': completed (2 scripts)
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: new request (2 scripts)
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Settings/1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: CONNECTION_FILENAME=/etc/NetworkManager/system-connections/Wired connection 1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: CONNECTION_UUID=21293ade-0112-y44de-b09b-5f06au9ecaa50
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: CONNECTION_ID=Wired connection 1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DEVICE_IFACE=ens3
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DEVICE_IP_IFACE=ens3
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_ADDRESS_0=192.168.1.110/24 192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_NUM_ADDRESSES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_GATEWAY=192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_NAMESERVERS=192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_DOMAINS=localdomain
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_ROUTE_0=192.168.1.0/24 0.0.0.0 100
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP4_NUM_ROUTES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_ADDRESS_0=fe80::5054:ff:fed4:1c85/64 0.0.0.0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_NUM_ADDRESSES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_GATEWAY=0.0.0.0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_ROUTE_0=fe80::/64 :: 100
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_ROUTE_1=ff00::/8 :: 256
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: IP6_NUM_ROUTES=2
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_BROADCAST_ADDRESS=192.168.1.255
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DAD_WAIT_TIME=0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DHCP_LEASE_TIME=86400
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DHCP_MESSAGE_TYPE=5
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DHCP_SERVER_IDENTIFIER=192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DOMAIN_NAME=localdomain
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DOMAIN_NAME_SERVERS=192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_DOMAIN_SEARCH=localdomain.
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_EXPIRY=1584051851
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_IP_ADDRESS=192.168.1.110
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_NETWORK_NUMBER=192.168.1.0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_NEXT_SERVER=0.0.0.0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_BROADCAST_ADDRESS=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_DOMAIN_NAME=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_DOMAIN_NAME_SERVERS=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_DOMAIN_SEARCH=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_HOST_NAME=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_INTERFACE_MTU=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_MS_CLASSLESS_STATIC_ROUTES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_NETBIOS_NAME_SERVERS=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_NETBIOS_SCOPE=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_NTP_SERVERS=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_RFC3442_CLASSLESS_STATIC_ROUTES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_ROOT_PATH=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_ROUTERS=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_STATIC_ROUTES=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_SUBNET_MASK=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_TIME_OFFSET=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_REQUESTED_WPAD=1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_ROUTERS=192.168.1.1
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: DHCP4_SUBNET_MASK=255.255.255.0
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: environment: NM_DISPATCHER_ACTION=up
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: start running ordered scripts...
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3], "/etc/NetworkManager/dispatcher.d/01-ifupdown": run script
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': new request (2 scripts)
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': environment: CONNECTIVITY_STATE=FULL
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Mar 11 22:24:11 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': environment: NM_DISPATCHER_ACTION=connectivity-change
Mar 11 22:24:14 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3], "/etc/NetworkManager/dispatcher.d/01-ifupdown": complete
Mar 11 22:24:14 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3], "/etc/NetworkManager/dispatcher.d/up-vpn.sh": run script
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: Error: Connection activation failed: The connection attempt timed out
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3], "/etc/NetworkManager/dispatcher.d/up-vpn.sh": complete: failed with Script '/etc/NetworkManager/disMar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:3 'up' [ens3]: completed (2 scripts)
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': start running ordered scripts...
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change', "/etc/NetworkManager/dispatcher.d/01-ifupdown": run script
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change', "/etc/NetworkManager/dispatcher.d/01-ifupdown": complete
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": run script
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change', "/etc/NetworkManager/dispatcher.d/up-vpn.sh": complete
Mar 11 22:25:15 debian-x234 nm-dispatcher[550]: req:4 'connectivity-change': completed (2 scripts)
Mar 11 22:25:25 debian-x234 systemd[1]: NetworkManager-dispatcher.service: Succeeded
Trying this command remotely via SSH also now fails, but if I log in via VNC and run it it works ! Weird !

Code: Select all

 sudo nmcli connection up id "$VPN_NAME"
The up-vpn.sh is below.

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

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

Re: Automatically start vpn on boot up ?

#37 Post by Chrisdb »

what is the content of the '01-ifupdown' file?

Remove the following lines from your script:

Code: Select all

# http://forums.debian.net/viewtopic.php?f=10&t=145355

# Also to enable dispatcher, run:
# sudo systemctl enable NetworkManager-dispatcher.service
And make sure that:

Code: Select all

#!/bin/sh
is the first line in your file.

Now were going to try something else. Make sure that your 'wired' connection is up.

So the end result would look something like this:

Code: Select all

#!/bin/sh

LAN_INTERFACE="ens3"
VPN_NAME="nl2-nodecentral-udp-udp"

interface=$1 status=$2

if [ "$1" = "$LAN_INTERFACE" ]; then
	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
fi

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

Re: Automatically start vpn on boot up ?

#38 Post by parkerc »

Chrisdb wrote:what is the content of the '01-ifupdown' file?
Here’s the content of 01-ifupdown.sh ..

Code: Select all

 
#!/bin/sh -e
# Script to dispatch NetworkManager events
#
# Runs ifupdown scripts when NetworkManager fiddles with interfaces.
# See NetworkManager(8) for further documentation of the dispatcher events.

# We do not handle connectivity-change events in ifupdown so simply exit at
# this point
if [ "$2" = "connectivity-change" ]; then
    exit 0;
fi

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2
    exit 1;
fi

if [ -n "$IP4_NUM_ADDRESSES" ] && [ "$IP4_NUM_ADDRESSES" -gt 0 ]; then
   ADDRESS_FAMILIES="$ADDRESS_FAMILIES inet"
fi
if [ -n "$IP6_NUM_ADDRESSES" ] && [ "$IP6_NUM_ADDRESSES" -gt 0 ]; then
   ADDRESS_FAMILIES="$ADDRESS_FAMILIES inet6"
fi

# If we have a VPN connection ignore the underlying IP address(es)
if [ "$2" = "vpn-up" ] || [ "$2" = "vpn-down" ]; then
   ADDRESS_FAMILIES=""
fi

if [ -n "$VPN_IP4_NUM_ADDRESSES" ] && [ "$VPN_IP4_NUM_ADDRESSES" -gt 0 ]; then
   ADDRESS_FAMILIES="$ADDRESS_FAMILIES inet"
fi
if [ -n "$VPN_IP6_NUM_ADDRESSES" ] && [ "$VPN_IP6_NUM_ADDRESSES" -gt 0 ]; then
   ADDRESS_FAMILIES="$ADDRESS_FAMILIES inet6"
fi

# We're probably bringing the interface down.
[ -n "$ADDRESS_FAMILIES" ] || ADDRESS_FAMILIES="inet"

# Fake ifupdown environment
export IFACE="$1"
export LOGICAL="$1"
export METHOD="NetworkManager"
export VERBOSITY="0"

for i in $ADDRESS_FAMILIES; do

    export ADDRFAM="$i"

    # Run the right scripts
    case "$2" in
        up|vpn-up)
            export MODE="start"
            export PHASE="post-up"
            run-parts /etc/network/if-up.d
            ;;
        down|vpn-down)
            export MODE="stop"
            export PHASE="post-down"
            run-parts /etc/network/if-post-down.d
            ;;
# pre-up/pre-down not implemented. See
# https://bugzilla.gnome.org/show_bug.cgi?id=387832
#        pre-up)
#            export MODE="start"
#            export PHASE="pre-up"
#            run-parts /etc/network/if-pre-up.d
#            ;;
#        pre-down)
#            export MODE="stop"
#            export PHASE="pre-down"
#            run-parts /etc/network/if-down.d
#            ;;
        hostname|dhcp4-change|dhcp6-change)
            # Do nothing
            ;;
        *)
            echo "$0: called with unknown action \`$2'" 1>&2
            exit 1
            ;;
    esac
done
And I’ve updated the up-vpn.sh to be as you suggested.

Code: Select all

 #!/bin/sh

LAN_INTERFACE="ens3"
VPN_NAME="nl2-nodecentral-udp-udp"

interface=$1 status=$2

if [ "$1" = "$LAN_INTERFACE" ]; then
   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
fi

Post Reply