OpenVPN

From Leo's Notes
Revision as of 19:36, 16 August 2021 by Leo (talk | contribs)
This page was last edited on 16 August 2021, at 19:36.

Server

Setup OpenVPN using docker

To quickly get a OpenVPN server up and running, the easiest solution would be to use docker and docker-compose and the image kylemanna/docker-openvpn. The following instructions are outlined in the project's documentation.

Create the following docker-compose file:

version: '2'
services:
  openvpn:
    cap_add:
     - NET_ADMIN
    image: kylemanna/openvpn
    container_name: openvpn
    ports:
     - "1194:1194/udp"
    restart: always
    volumes:
     - ./openvpn-data/conf:/etc/openvpn

Setup the config and PKI keys:

## Setup the config and PKI keys:
# docker-compose run --rm openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
# docker-compose run --rm openvpn ovpn_initpki

## Edit the OpenVPN configuration if desired.
# vi openvpn-data/conf/openvpn.conf

## Bring up the server
# docker-compose up -d openvpn

Create clients by generating a new client certificate and the client configuration file:

## with a passphrase (recommended)
# docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME
## -or- without a passphrase (not recommended)
# docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME nopass

## Generate the client config
# docker-compose run --rm openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn

Configuration

The OpenVPN configuration is typically at /etc/openvpn/openvpn.conf.

Description Option
Disable ping-restart. Defaults to keepalive 10 30, which corresponds to 10 second ping intervals and 30 second ping-restart. keepalive 0 0
Allow multiple c

live / ping-restart

Allow multiple clients to connect

duplicate-cn

Client

Usage

To connect to a VPN, run:

# openvpn --config config.ovpn

You will be prompted for a username and password if required.