Configure OpenVPN Client to Autostart on Ubuntu Linux

You’ve set up an OpenVPN server on pfSense or some other router/gateway and you have a remote server you’d like to connect back to the private network. Here’s how you do it.

First, let’s get it installed:

# sudo apt update && apt upgrade -y
# sudo apt install openvpn

Copy/paste your client configuration from your server place it in /etc/openvpn/nameofserver.config

# sudo nano /etc/openvpn/nameofserver.config

Change the line that reads auth-user-pass to auth-user-pass /etc/openvpn/pass

Let’s put your username and password in there:

# sudo nano /etc/openvpn/pass

Line 1 should be the username, line 2 should be the password.

username
password

Save it. Next, enable the service with your particular connection:

# systemctl enable openvpn@nameofserver
# systemctl start openvpn@nameofserver

You should be able to see a tunnel connection now:

# ip a

3: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100
    link/none
    inet 192.168.1.3/24 brd 192.168.1.255 scope global tun0
       valid_lft forever preferred_lft forever

All set. For setting up a server, see the following:

https://www.digitalocean.com/community/tutorials/how-to-set-up-and-configure-an-openvpn-server-on-ubuntu-20-04

https://docs.netgate.com/pfsense/en/latest/recipes/openvpn-ra.html

https://docs.opnsense.org/manual/how-tos/sslvpn_client.html