[email protected]Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Knowledge BaseJanuary 15, 2024

How to install OpenVPN

Guide to Install OpenVPN on Ubuntu 20.04

Step 1: Update System Packages

sudo apt update
sudo apt upgrade -y

Step 2: Install OpenVPN and Easy-RSA

sudo apt install openvpn easy-rsa -y

Step 3: Set Up the Certificate Authority (CA)

  1. Create a directory for Easy-RSA:

make-cadir ~/openvpn-ca
cd ~/openvpn-ca
  1. Edit the vars file to customize CA settings:

nano vars

Update the following lines with your information:

set_var EASYRSA_REQ_COUNTRY    "US"
set_var EASYRSA_REQ_PROVINCE   "California"
set_var EASYRSA_REQ_CITY       "Los Angeles"
set_var EASYRSA_REQ_ORG        "MyOrganization"
set_var EASYRSA_REQ_EMAIL      "[email protected]"
set_var EASYRSA_REQ_OU         "MyOrganizationalUnit"

Step 4: Build the CA

./easyrsa init-pki
./easyrsa build-ca nopass

Step 5: Generate Server Certificate and Key

./easyrsa gen-req server nopass
sudo cp pki/private/server.key /etc/openvpn/

Step 6: Sign Server Certificate

./easyrsa sign-req server server
sudo cp pki/issued/server.crt /etc/openvpn/
sudo cp pki/ca.crt /etc/openvpn/

Step 7: Generate Diffie-Hellman Parameters

./easyrsa gen-dh
sudo cp pki/dh.pem /etc/openvpn/

Step 8: Configure OpenVPN Server

  1. Copy the sample configuration file:

sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
cd /etc/openvpn/
sudo gzip -d server.conf.gz
  1. Edit the server configuration file:

sudo nano server.conf

Uncomment or set the following lines:

ca ca.crt
cert server.crt
key server.key  # keep secret
dh dh.pem
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

Step 9: Enable IP Forwarding

Edit the sysctl configuration:

sudo nano /etc/sysctl.conf

Uncomment this line:

net.ipv4.ip_forward=1

Apply changes:

sudo sysctl -p

Step 10: Start and Enable OpenVPN

sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server

Step 11: Configure Firewall (if UFW is enabled)

sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw enable

Step 12: Generate Client Certificates

cd ~/openvpn-ca
./easyrsa gen-req client1 nopass
./easyrsa sign-req client client1
cp pki/private/client1.key /etc/openvpn/
cp pki/issued/client1.crt /etc/openvpn/

Step 13: Create Client Configuration File

Create a client config file client1.ovpn:

client
dev tun
proto udp
remote your_server_ip 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
auth SHA256
auth-nocache
verb 3
<ca>
$(cat /etc/openvpn/ca.crt)
</ca>
<cert>
$(cat /etc/openvpn/client1.crt)
</cert>
<key>
$(cat /etc/openvpn/client1.key)
</key>

Step 14: Connect to VPN

Transfer the client1.ovpn file to your client machine and connect using:

openvpn --config client1.ovpn

OpenVPN is now installed and configured on your Ubuntu 20.04 server.

 

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Mon – Fri 9:00AM – 5:00PM