Repository

Looks good to me!

User Tools

Site Tools


kb:internet:connectivity:openvpn

OpenVPN

Server

Incomplete documentation.

curl -fsSL https://swupdate.openvpn.net/repos/repo-public.gpg | gpg --dearmor | sudo tee /etc/apt/keyrings/openvpn-repo-public.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/openvpn-repo-public.gpg] https://build.openvpn.net/debian/openvpn/stable jammy main" | sudo tee /etc/apt/sources.list.d/openvpn-aptrepo.list > /dev/null

sudo apt update
sudo apt install openvpn openvpn-dco-dkms

wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.1.2/EasyRSA-3.1.2.tgz
tar -xzvf EasyRSA-3.1.2.tgz

./easyrsa init-pki
./easyrsa build-ca
./easyrsa gen-req client
./easyrsa sign-req client

cd /usr/share/doc/openvpn/examples/sample-config-files/
sudo cp server.conf /etc/openvpn/server/
sudo cp client.conf /etc/openvpn/client/

sudo openvpn server.conf

OpenVPN client

Update: To update with new info.

In Alpine containers, note the container must have NET_ADMIN privilege, or run in --privileged (privileged: true) mode.

mkdir -p /dev/net
mknod /dev/net/tun c 20 100
chmod 666 -R /dev/net
apk add openvpn
openvpn {% CONFIG_FILE %}

For Docker containers, need to redirect to VPN container.

expressvpn:
  container_name: expressvpn
  image: polkaned/expressvpn
  environment:
    - ACTIVATION_CODE={% your-activation-code %}
    - SERVER={% LOCATION/ALIAS/COUNTRY %}
    - PREFERRED_PROTOCOL={% protocol %}
    - LIGHTWAY_CIPHER={% lightway-cipher %}
  cap_add:
    - NET_ADMIN
  devices: 
    - /dev/net/tun
  stdin_open: true
  tty: true
  command: /bin/bash
  privileged: true
  restart: unless-stopped
  ports:
    # ports of other containers that use the vpn (to access them locally)

downloader:
  image: example/downloader
  container_name: downloader
  network_mode: service:expressvpn
  depends_on:
    - expressvpn
  # ports should not be published here

For automated connections as client, consider creating a service and connect on boot:

[Unit]
Description=OpenVPN
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=openvpn \
    --config /home/justin/config.ovpn \
    --auth-user-pass /home/justin/config.ovpn.passwd \
    --auth-nocache

[Install]
WantedBy=multi-user.target

To check the server certificate as a client, execute the following (copied from ServerFault):

WD=/tmp/openvpn-cert
mkdir $WD
echo -e '#!'"/bin/sh\ncp \$peer_cert $WD/server-cert-\$1.pem" >$WD/extract-cert.sh
chmod +x $WD/extract-cert.sh
echo -e "fakeusername\nfakepassword" >$WD/creds.dat
openvpn --config config.ovpn --auth-user-pass $WD/creds.dat --tls-export-cert $WD --script-security 2 --tls-verify $WD/extract-cert.sh --log /dev/null
openssl x509 -in $WD/server-cert-0.pem -noout

OpenVPN server

Following this tutorial: https://linuxconfig.org/how-to-setup-a-openvpn-server-on-ubuntu-20-04/

Historical stuff I have no idea why it's here

kb/internet/connectivity/openvpn.txt · Last modified: 5 months ago ( 4 July 2024) by justin