Skip to content
TrySitePrice

Ubuntu 22.04 LTS Set Up OpenVPN Server

Best/Tutorial

Setting up an OpenVPN server on Ubuntu 22.04 LTS can be done in just a few minutes by following these steps:

  1. Install OpenVPN:
sudo apt update
sudo apt install openvpn
  1. Generate the necessary encryption keys and certificates:
sudo easyrsa init-pkirnsudo easyrsa build-carnsudo easyrsa build-server-full server nopass

This will create the necessary keys and certificates in the /etc/openvpn/easy-rsa/pki directory.

  1. Create the server configuration file:
sudo nano /etc/openvpn/server.conf
  1. Add the following contents to the file, replacing the IP address with the IP of your server:
port 1194
proto udprndev tunrnca /etc/openvpn/easy-rsa/pki/ca.crtrncert /etc/openvpn/easy-rsa/pki/issued/server.crtrnkey /etc/openvpn/easy-rsa/pki/private/server.keyrndh /etc/openvpn/easy-rsa/pki/dh.pemrnserver 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txtrnkeepalive 10 120
comp-lzornpersist-keyrnpersist-tunrnstatus openvpn-status.logrnverb 3
  1. Enable IP forwarding:
sudo nano /etc/sysctl.conf

and add or uncomment the following line:

net.ipv4.ip_forward=1

  1. Enable the OpenVPN service:
sudo systemctl start openvpn@server
  1. Enable the OpenVPN service to start automatically at boot time:
sudo systemctl enable openvpn@server
  1. Configure the firewall to allow OpenVPN traffic, you can use ufw for that.
sudo ufw allow 1194/udprnsudo ufw enable
  1. Create a client configuration file, you can use a .ovpn extension for it.
sudo nano /etc/openvpn/client.ovpn
  1. Add the following contents to the file, replacing the IP address with the IP of your server:
clientrndev tunrnproto udprnremote <your server IP> 1194
resolv-retry infiniternnobindrnpersist-key
persist-tunrncomp-lzornverb 3
<ca>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
</key>

You can copy the ca, cert and key from the server's /etc/openvpn/easy-rsa/pki directory.