I was running Gnome and I noticed something obnoxious about autoconnecting to my VPN on startup and after resume. It simply wasn't working, and I changed password permissions and availability to no avail. Something odd was that if I enabled all connections and passwords for all users, it would connect supposedly right after boot but when I logged in, I couldn't resolve any domains or access web pages and had to restart the connection. Mixing and matching permissions made it so that I was also unable to auto reconnect after resume from S3 suspend. I created this simple systemd script with a certain network configuration which fixed my problem. Make sure you have the following configuration options checked that I'll point out too before creating the systemd service.
1 Answer
We must first configure permissions on the VPN and ethernet connections to avoid the buggy startup with fully permissive options. Instead we will make both the VPN connection and the wired ethernet connection unavailable to all users by unchecking the Make available to other users
box for both connections. However, when we save the password for the VPN, select Store this password for all users
so we can connect immediately on the lockscreen after resume from suspend. Then open nmcli-connection-editor
and select your wired ethernet connection, go to the General
tab, and check the box Automatically connect to VPN
and select your VPN connection. Now we move onto the next phase, creating the systemd service to auto-connect on boot login and resume.
First find the uuid of your ethernet connection using nmcli con
which should be labeled something like Wired connection 1
Save a file /etc/systemd/system/vpn-autostart.service
with the following contents:
[Unit]
Description=Autostart VPN on boot and resume from suspend over ethernet
After=suspend.target
[Service]
User=root
Type=oneshot
ExecStart=nmcli con up uuid <youruuidhere>
StandardOutput=syslog
[Install]
WantedBy=suspend.target
WantedBy=default.target
After creating and saving the file, run the following commands:
systemctl daemon-reload
systemctl enable vpn-autostart.service
systemctl start vpn-autostart.service
Now simply restart the computer and your OpenVPN autoconnection woes are over with ethernet on Gnome!