MyHBD Logo
tutorial

Install OpenConnect VPN Server (ocserv) on Ubuntu 20.04 with Let’s Encrypt

This tutorial is going to show you how to install your own VPN server by installing OpenConnect VPN server on ubuntu 20.04. OpenConnect (ocserv) is an open-source implementation of cisco AnyConnect VPN protocol which is used in business and universities. OpenConnect is an SSL based VPN protocol that allows users to connect to remote networks.

MyHBD Team
2 min read
Share:
Install OpenConnect VPN Server (ocserv) on Ubuntu 20.04 with Let’s Encrypt
MyHBD

Install OpenConnect VPN Server (ocserv) on Ubuntu 20.04 with Let’s Encrypt

Featured article image

tutorial

Step 1: Install OpenConnect

sudo apt update sudo apt install ocserv systemctl status ocserv sudo systemctl start ocserv sudo ufw allow 80,443/tcp code

Step 2: Install Certbot

sudo apt install certbot certbot --version

Step 3: Obtain TLS Certificate

Standalone

sudo certbot certonly --standalone --preferred-challenges http \ --agree-tos --email [email protected] -d vpn.example.com

Apache (Webroot)

sudo nano /etc/apache2/sites-available/vpn.example.com.conf sudo mkdir /var/www/ocserv sudo chown www-data:www-data /var/www/ocserv -R sudo a2ensite vpn.example.com sudo systemctl reload apache2 sudo certbot certonly --webroot --agree-tos \ --email [email protected] -d vpn.example.com -w /var/www/ocserv

Nginx (Webroot)

sudo nano /etc/nginx/conf.d/vpn.example.com.conf sudo mkdir -p /var/www/ocserv sudo chown www-data:www-data /var/www/ocserv -R sudo systemctl reload nginx sudo certbot certonly --webroot --agree-tos \ --email [email protected] -d vpn.example.com -w /var/www/ocserv

Step 4: Configure ocserv

sudo nano /etc/ocserv/ocserv.conf sudo systemctl restart ocserv

Step 5: Create VPN Accounts

sudo ocpasswd -c /etc/ocserv/ocpasswd username

Step 6: Enable IP Forwarding

echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/60-custom.conf sudo sysctl -p /etc/sysctl.d/60-custom.conf

Step 7: Configure IP Masquerading

sudo apt install ufw sudo ufw allow 22/tcp ip addr sudo nano /etc/ufw/before.rules sudo ufw enable sudo systemctl restart ufw sudo iptables -t nat -L POSTROUTING

Step 8: Open VPN Ports

sudo ufw allow 443/tcp sudo ufw allow 443/udp

Done: your OpenConnect VPN server is ready.

Was this helpful?

Help others find useful content by rating this article

Your feedback helps improve our content and SEO ranking

Install OpenConnect VPN Server (ocserv) on Ubuntu 20.04 with Let’s Encrypt | MyHBD Blog