OpenConnect VPN Server Installation

OpenConnect VPN
For more information on OpenConnect VPN Server, visit


OpenConnect is an SSL VPN client initially created to support Cisco's AnyConnect SSL VPN. It has since been ported to support the Juniper SSL VPN which is now known as Pulse Connect Secure. OpenConnect is released under the GNU Lesser Public License, version 2.1. Like vpnc, OpenConnect is not officially supported by, or associated in any way with, Cisco Systems, Juniper Networks or Pulse Secure. It just happens to interoperate with their equipment.


Install the packages that are needed to support OpenConnect

These instructions are only compatible with Debian 8 Jessie  

apt-get update
sudo apt-get -y install xz-utils dbus build-essential pkg-config libgnutls28-dev \
libwrap0-dev libpam0g-dev libseccomp-dev libreadline-dev libnl-route-3-dev ufw libev4 \
libev-dev libprotobuf-c0-dev protobuf-c-compiler gnutls-bin git

Download OCServ:

cd /tmp
tar -xf ocserv-0.11.2.tar.xz
cd ocserv-0.11.2

Compile OCServ:

./configure --prefix=/usr/local --sysconfdir=/etc
make install

Create CA and Server Certificate:

1.    Create Cert Directory:

cd ~
sudo mkdir certificates
cd certificates

2.    Create the CA Cert:

cat > ca.tmpl << "EOF"
cn = ""
organization = "Your Company"
serial = 1
expiration_days = 3650

certtool --generate-privkey --outfile ca-key.pem
certtool --generate-self-signed --load-privkey ca-key.pem --template ca.tmpl --outfile ca-cert.pem

3.    Create a Server Cert:

cat > server.tmpl << "EOF"
cn = ""
organization = "Atlantean"
expiration_days = 3650

certtool --generate-privkey --outfile server-key.pem
certtool --generate-certificate --load-privkey server-key.pem --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem --template server.tmpl --outfile server-cert.pem

4.    Copy the new Certs:

sudo mkdir /etc/ocserv
sudo cp server-cert.pem server-key.pem /etc/ocserv
sudo cp /tmp/ocserv-0.11.2/doc/sample.config /etc/ocserv/config
cd /etc/ocserv

Set Configuration File:

Set the following values in the /etc/ocserv/config file based on your infrastructure.

auth = "plain[passwd=/etc/ocserv/.ocpasswd]"

try-mtu-discovery = true

listen-host =

server-cert = /etc/ocserv/server-cert.pem
server-key = /etc/ocserv/server-key.pem

max-clients = 8
max-same-clients = 2

dns =

# comment out all route fields
# route =
# route =
# route =
# route = fef4:db8:1000:1001::/64
# novim -route =

ipv4-network =

cisco-client-compat = true

Create VPN Users:

ocpasswd -c /etc/ocserv/.ocpasswd username

Setup Network Rules:

1.    Enable NAT:

ocpasswd -c /etc/ocserv/.ocpasswd username

2.    Enable Ipv4 Forwarding:
Edit the /etc/sysctl.conf to enable IPv4 Forwarding by adding the following entry.


Apply the new IPv4 Forwarding Rule.

sysctl -p /etc/sysctl.conf

3.    Add IPTables Rule:

iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

4.    Open necessary ports on the firewall:

ufw allow 443
ufw allow 443/udp
sudo ufw allow out to any port 443

ufw allow 80
ufw allow 80/udp
sudo ufw allow out to any port 80

ufw allow 22
ufw allow 22/udp
sudo ufw allow out to any port 22

5.    Verify the firewall ruleset:

sudo ufw status verbose

6.    Change the default forwarding policy:
Edit the /etc/default/ufw file to change the forwarding policy.


7.    Set NAT Rules:
Set NAT Rules to any routes that you want to be able to access through the VPN:

echo "*nat" >> /etc/ufw/before.rules
echo ":POSTROUTING ACCEPT [0:0]" >> /etc/ufw/before.rules

# Change NAT IP/subnet HERE accordingly to your ocserv.conf configs
echo "-A POSTROUTING -s -d -o eth0 -j MASQUERADE" >> /etc/ufw/before.rules
echo "-A POSTROUTING -s -d -o eth1 -j MASQUERADE" >> /etc/ufw/before.rules

echo "COMMIT" >> /etc/ufw/before.rules

8.    Restart the firewall:

ufw disable && sudo ufw enable

Generate Lets Encrypt Certificate:

1.    Backup the self signed certs:

cd /etc/ocserv
mv server-key.pem server-key.selfsigned
mv server-cert.pem server-cert.selfsigned

2.    Pull the letsencrypt project:

git clone

3.    Generate the certificate:

cd letsencrypt/
./letsencrypt-auto certonly --standalone -d

4.    Copy the certs to the ocserv directory:

cp /etc/letsencrypt/live/ /etc/ocserv/server-key.pem
cp /etc/letsencrypt/live/ /etc/ocserv/server-cert.pem

Create the service unit file:

cat > /etc/systemd/system/ocserv.service << "EOF"
Description=OpenConnect VPN Service

ExecStart=/usr/local/sbin/ocserv -c /etc/ocserv/config


Enable Services:

systemctl enable ocserv.service
systemctl daemon-reload
systemctl start ocserv.service
systemctl status ocserv.service


Use the Cisco Anyconnect client, Juniper Pulse Client, or Open Connect client from another machine to test the new OpenConnect VPN Server.

Post Requisites:

In some instances the unit file does not stop the service correctly.
If systemctl stop ocserv.service does not stop the service, use ps -elf | grep ocserv
to find the process, and use kill {pid} to kill the service.