Skip to content

Instantly share code, notes, and snippets.

@TimoDJatomika
Last active December 24, 2018 09:13
Show Gist options
  • Save TimoDJatomika/cf230514e724e5ab7a10a97bcad973e6 to your computer and use it in GitHub Desktop.
Save TimoDJatomika/cf230514e724e5ab7a10a97bcad973e6 to your computer and use it in GitHub Desktop.
How to install OpenVPN on a Ubuntu 18.04 Server

How to install OpenVPN on Ubuntu 18.04

by Timo Stankowitz github@brainoftimo.com

apt

sudo su
apt update -y
apt install openvpn -y

certs

Use the programm XCA to generate all certs and keys

mkdir /etc/openvpn/certs

copy the following files into that folder

  • ca.crt
  • server.crt
  • server.key (chown 600)
  • dh2048.pem

server conf

vi /etc/openvpn/server.conf

copy the following content into that file

port 1194
proto udp
dev tun

ca /etc/openvpn/certs/ca.crt
cert /etc/openvpn/certs/server.crt
key /etc/openvpn/certs/server.key
dh /etc/openvpn/certs/dh2048.pem

server 172.28.28.0 255.255.255.0

push "redirect-gateway def1 bypass-dhcp"

client-to-client

push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 4.2.2.2"

push "topology subnet"
topology subnet

route 172.28.28.0 255.255.255.0

keepalive 10 120

#comp-lzo

user nobody
group nogroup

persist-key
persist-tun

status /var/log/openvpn-status.log
verb 3
log-append /var/log/openvpn

activate masquerade

#!/bin/bash

echo activate MASQUERADE

iptables -t nat -A POSTROUTING -s 172.28.28.0/24 -o eth0 -j MASQUERADE

# enable ip forwarding
sysctl -w net.ipv4.ip_forward=1

reboot

Reboot the server. The OpenVPN Server should start automatically. Verify it with systemctl status openvpn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment