Skip to content

Instantly share code, notes, and snippets.

@schickling
Last active September 23, 2020 09:41
Show Gist options
  • Save schickling/225550662982cad94e77 to your computer and use it in GitHub Desktop.
Save schickling/225550662982cad94e77 to your computer and use it in GitHub Desktop.
Install OpenVPN on Ubuntu 14.04 for yourserver.se

Preconditions

  • You need to have TUN/TAP enabled

Install dependencies

$ apt-get install -y openvpn easy-rsa

Make certificates

$ make-cadir /etc/openvpn/easy-rsa
$ cd /etc/openvpn/easy-rsa
$ source vars
$ ./clean-all
$ ./build-ca
$ ./build-key-server server # take server IP as common name
$ ./build-key client
$ ./build-dh

Download

$ scp [email protected]:/etc/openvpn/easy-rsa/keys/{ca.crt,client.crt,client.key} .

Prepare forwarding

$ vim /etc/sysctl.conf # uncomment net.ipv4.ip_forward=1
$ sysctl -p

Configure OpenVPN

$ vim /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key
dh /etc/openvpn/easy-rsa/keys/dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
client-to-client
duplicate-cn
keepalive 10 120
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
log /var/log/openvpn.log
verb 3

Prepare autostart

$ vim /etc/rc.local

Replace xx.xx.xx.xx with your server IP.

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j SNAT --to xx.xx.xx.xx
openvpn /etc/openvpn/server.conf

Restart

$ reboot
@FloFlo77
Copy link

Hi,
Appreciate the step-by-step tutorial firstly. I almost make it work.
But the weird problem occurs after connection.

Actually I can connect to server via Tunnelblick client on my MacBook.
But after 60 seconds, the log in server shows:

“TLS Error: TLS key negotiation failed to occur within 60 seconds”
“TLS Error: TLS handshake failed”
“SIGUSR1[soft,tls-error] received, client-instance restarting”

Actually during the first 60 seconds, I can browser the internet properly. And also I can ping server successfully, even I check the ip which presents correctly 10.8.0.6 and external ip is my server’s.
But after about 60s, encounter the error. The connection is still on, but cannot access internet any more.

Any idea?

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