Setting up an OpenVPN server on Ubuntu 18.04 LTS is a relatively simple process that can be completed in just a few minutes. Here is a step-by-step guide to help you set up an OpenVPN server on your Ubuntu 18.04 LTS system:
sudo apt-get update sudo apt-get upgrade
sudo apt-get install openvpn
sudo apt-get install easy-rsa sudo make-cadir /etc/openvpn/easy-rsa cd /etc/openvpn/easy-rsa
Now you will need to edit the file vars
to set the appropriate values for your environment. Open the file with a text editor (e.g. nano
) and make the following changes:
KEY_COUNTRY
to the two-letter code for your countryKEY_PROVINCE
to the name of your state or provinceKEY_CITY
to the name of your cityKEY_ORG
to the name of your organizationKEY_EMAIL
to your email addressOnce you have made these changes, save the file and run the following command to initialize the PKI (public key infrastructure):
source vars ./clean-all ./build-ca
Follow the prompts to create the certificate authority (CA) certificate and key. Next, generate the server certificate and key:
./build-key-server server
Again, follow the prompts to create the server certificate and key. Finally, generate the client certificates and keys:
./build-key client1 ./build-key client2
Replace client1
and client2
with the names of the clients that you want to create certificates for.
Copy the sample OpenVPN configuration file to the OpenVPN directory:
gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz > /etc/openvpn/server.conf
Edit the server.conf
file with a text editor and make the following changes:
push "redirect-gateway def1 bypass-dhcp"
line to force all client traffic through the VPNpush "dhcp-option DNS 208.67.222.222"
and push "dhcp-option DNS 208.67.220.220"
lines to set the OpenDNS servers as the DNS servers for the clientsserver
and server-bridge
options to specify the IP range for the VPN clientsca
, cert
, and key
options to point to the files that you generated in step 3Once you have made these changes, save the file and start the OpenVPN server by running the following command:
systemctl start openvpn@server