OpenVPN
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 clients to connect | duplicate-cn
|
Add additional subnets to route through the VPN. The client will add a route for this particular subnet via the VPN gateway. | push "route 192.168.248.0 255.255.255.0"
|
Use TCP or UDP protocol. It's one or the other. You can't do both at the same time. | proto tcp or proto udp
|
Client
Usage
To connect to a VPN, run:
# openvpn --config config.ovpn
You will be prompted for a username and password if required.
See Also
- OpenVPN 2.4 reference manual - https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/