How To Set up OpenVPN Server In 5 Minutes on Ubuntu Linux

How To Set up OpenVPN Server In 5 Minutes on Ubuntu Linux

Setting up an OpenVPN server on Ubuntu Linux can be done in just a few minutes using the following steps:

  1. Install OpenVPN and the easy-rsa utility:
sudo apt-get update
sudo apt-get install openvpn easy-rsa
Source‮ww:‬w.lautturi.com
  1. Copy the easy-rsa templates to a new directory:
sudo mkdir /etc/openvpn/easy-rsa
sudo cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/
  1. Change to the easy-rsa directory and build the certificate authority (CA) certificate and key:
cd /etc/openvpn/easy-rsa
./easyrsa init-pki
./easyrsa build-ca
  1. Create a server certificate and key:
./easyrsa build-server-full server nopass
  1. Create a client certificate and key:
./easyrsa build-client-full client1 nopass
  1. Generate Diffie-Hellman parameters:
./easyrsa gen-dh
  1. Create a TLS authentication key:
openvpn --genkey --secret ta.key
  1. Copy the necessary files to the OpenVPN directory:
sudo cp pki/ca.crt pki/private/server.key pki/dh.pem ta.key /etc/openvpn
  1. Create a configuration file for the OpenVPN server (/etc/openvpn/server.conf) with the following contents:
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.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 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
keepalive 10 120
tls-auth ta.key 0
key-direction 0
cipher AES-256-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
  1. Start the OpenVPN server:
sudo systemctl start openvpn@server
  1. Enable the OpenVPN server to start at boot:
sudo systemctl enable openvpn@server

That's it! Your OpenVPN server should now be set up and running. You can now create a client configuration file (e.g., client1.ovpn) with the following contents:

client
dev tun
proto udp
remote SERVER_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth-nocache
cipher AES-256-CBC
comp-lzo
setenv opt block-outside-dns
key-direction 1
verb
Created Time:2017-10-29 22:08:31  Author:lautturi