How to Build a Cisco AnyConnect-Compatible SSL VPN on Linux with OpenConnect Server (ocserv)

Networking tutorial - IT technology blog
Networking tutorial - IT technology blog

Why Build a Cisco AnyConnect-Compatible SSL VPN on Linux?

Your team needs access to internal staging servers, PostgreSQL databases, and private Grafana dashboards from the road. A standard UDP VPN like WireGuard (port 51820) or OpenVPN (port 1194) works great at home. Then someone checks into a hotel, sits at an airport gate, or visits a client office—and strict firewalls drop every non-standard UDP packet.

An SSL VPN on port 443 solves that problem immediately. Almost every firewall leaves TCP port 443 open because HTTPS web traffic depends on it.

Cisco AnyConnect is supported natively across Windows, macOS, Linux, iOS, and Android, and you do not need expensive Cisco hardware to host it. OpenConnect Server (ocserv) gives you a lightweight, open-source Linux server that speaks the exact same protocol. Even a modest 1 vCPU, 1 GB RAM VPS can comfortably handle 30 to 50 concurrent users while using roughly 25 MB of RAM at idle.

We have run this exact setup for a 20-person remote engineering team with rock-solid uptime, even behind restrictive corporate proxies. Below, you will install ocserv on Ubuntu, set up local user accounts, and enable split tunneling so everyday video calls do not saturate your VPN server.

Core Concepts Before You Start

Three moving parts power an ocserv deployment. Understanding them now makes troubleshooting much faster later.

1. How OpenConnect Server (ocserv) Transports Traffic

Every client session begins with a standard TLS/HTTPS handshake over TCP port 443 to authenticate the user and negotiate settings. Once authenticated, ocserv upgrades the data tunnel to DTLS over UDP port 443 for lower latency and better throughput. If a restrictive firewall blocks UDP 443, the client automatically falls back to TCP 443. The connection stays alive either way.

2. Server Certificates and User Authentication

Clients expect a valid TLS certificate because the initial handshake looks like HTTPS. A free Let’s Encrypt certificate bound to a hostname such as vpn.yourdomain.com prevents untrusted-certificate warnings in Cisco AnyConnect. For login credentials, ocserv supports local password files (ocpasswd), Linux PAM, RADIUS, and client SSL certificates. Starting with ocpasswd keeps the setup simple and self-contained.

3. What Is Split Tunneling?

Many VPNs default to a full tunnel, pushing 100% of a user’s traffic through the server. A single 1080p YouTube stream or 4 Mbps Zoom call from a developer’s laptop then consumes double the bandwidth on your VPS and adds extra round-trip latency. Split tunneling fixes this by routing only specific internal subnets—such as 10.20.0.0/16—over the VPN. Everything else goes straight out through the user’s local ISP.

Step-by-Step Hands-On Setup on Ubuntu Linux

These instructions apply to Ubuntu 22.04 or 24.04 LTS. Make sure you have sudo access, a public IPv4 address, and an A record pointing your domain to the server.

Step 1: Install ocserv and Obtain an SSL Certificate

Update your package list and install ocserv alongside certbot:

sudo apt update
sudo apt install -y ocserv certbot

Stop any web server temporarily using port 80, then request a TLS certificate for your VPN hostname:

sudo certbot certonly --standalone -d vpn.yourdomain.com

Certbot saves your certificate chain and private key inside /etc/letsencrypt/live/vpn.yourdomain.com/. Note that Let’s Encrypt certificates expire every 90 days.

Step 2: Configure ocserv and Split Tunneling

Save a backup copy of the default configuration file before making changes:

sudo cp /etc/ocserv/ocserv.conf /etc/ocserv/ocserv.conf.bak
sudo nano /etc/ocserv/ocserv.conf

Set the authentication backend, certificate paths, virtual IP pool (254 usable client addresses in this example), and split-tunnel routes:

# Authenticate users against a local password file
auth = "plain[passwd=/etc/ocserv/ocpasswd]"

# Listen on standard HTTPS port for TLS and DTLS
tcp-port = 443
udp-port = 443

# Let's Encrypt certificate paths
server-cert = /etc/letsencrypt/live/vpn.yourdomain.com/fullchain.pem
server-key = /etc/letsencrypt/live/vpn.yourdomain.com/privkey.pem

# Virtual IP pool assigned to connected VPN clients (up to 254 clients)
ipv4-network = 10.10.10.0
ipv4-netmask = 255.255.255.0

# DNS server pushed to clients (optional)
dns = 1.1.1.1

# Split Tunneling: route only internal 10.20.0.0/16 traffic through the VPN
route = 10.20.0.0/255.255.0.0

# Keep local LAN access untouched
no-route = 192.168.0.0/255.255.0.0

Leave out all route lines (or use route = default) if you ever want a full-tunnel VPN instead. Defining one or more specific route directives automatically switches clients to split-tunnel mode.

Step 3: Create VPN Users

Create your first VPN account with ocpasswd. Enter and confirm a strong password when prompted:

sudo ocpasswd -c /etc/ocserv/ocpasswd alice

User management stays just as fast later on. Run sudo ocpasswd -c /etc/ocserv/ocpasswd -l alice to lock an account, or replace -l with -d to delete it permanently.

Step 4: Enable IP Forwarding and NAT

Linux drops forwarded packets between interfaces by default. Turn on IPv4 forwarding persistently so VPN traffic can reach your internal network:

echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ocserv.conf
sudo sysctl --system

Find your server’s primary network interface (usually eth0 or ens3) with ip route | grep default. Then open port 443 and enable NAT masquerading for the 10.10.10.0/24 VPN subnet:

# Allow TCP and UDP traffic on port 443
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 443 -j ACCEPT

# Enable NAT for the VPN subnet (replace eth0 with your interface)
sudo iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE

Plain iptables commands clear on reboot unless you save them with iptables-persistent. If your server runs UFW, allow 443/tcp and 443/udp and place the masquerade rule inside /etc/ufw/before.rules instead.

Step 5: Start ocserv and Verify Split Tunneling

Enable the service at boot, restart it to load your new config, and check its status:

sudo systemctl enable --now ocserv
sudo systemctl restart ocserv
sudo systemctl status ocserv

Connect from a client using Cisco AnyConnect or sudo openconnect vpn.yourdomain.com with username alice. Once connected, run two quick checks to confirm split tunneling is active:

# Should return your local ISP IP, not the VPN server IP
curl -s ifconfig.me

# Should show 10.20.0.0/16 routed through the VPN tunnel interface
ip route | grep 10.20

Back on the server, sudo occtl show users lists every active session, assigned virtual IP, and connected client version in real time.

Wrapping Up

Your Linux server now runs a fast, Cisco AnyConnect-compatible SSL VPN with local user management and split tunneling. Remote teammates get reliable access over port 443, and your server avoids carrying their everyday web traffic. Next, add a Certbot deploy hook (systemctl reload ocserv) so 90-day certificate renewals apply automatically, or pair ocserv with PAM and Google Authenticator for two-factor login.

Share: