Set Up Simple OpenVPN Server and Client – Ubuntu

OpenVPN is the application that supports site-to-site and point-to-point connections to create either a routed or bridged configuration of either remote access facilities. OpenVPN allows superuser securely connect various computers into a secured network through the internet, hence giving users a legacy way for connecting to different resources on the network in a location not connected to the private network.

Now let’s get to the steps.

We’ll set up Server first

Install OpenVPN

Set up CA to generate certificates and keys for Server & Client

Set up directory

Become root & change to the newly created directory /etc/openvpn/easy-rsa and run

Generate key pair for the server

Replace myservername with your desired server name

Generate Diffie Hellman parameters for server

Generate certificate for the server

Copy all keys and certificates that have been generated in sub directories to /etc/openvpn/

Generate client certificate

Make sure you replace myclient1 with your client name

Now securely copy the below files to client machines(can use scp)

Copy server.conf from sample config files that you got along openvpn installation at /usr/share/doc/openvpn/examples/sample-config-files/

Edit /etc/openvpn/myserver.conf and make sure following are pointing to correct files

Generate ta.key for tls-auth at /etc/openvpn/

Edit /etc/sysctl.conf and uncomment the follwing line to enable ip forwading

Reload sysctl

Start openvpn service

REMEMBER to insert your server configuration file’s name at openvpn@<your server conf file name>, If not it won’t start.

Check status of service

Make sure you have something like Initialization Sequence Completed as last line

You can use the below command to view logs

Also check if OpenVPN has created a tun0 interface

Client configurations

Install OpenVPN

copy client.conf from sample files to /etc/openvpn/

Make sure the below are pointing to the correct files in /etc/openvpn/client.conf if not securely copy them from the server

Make sure following two lines are correctly so it’ll enable client mode

Start OpenVPN client service

Check status of service

See whether It says Initialization Sequence Completed at last line

Check logs on server and see if the client name and source present and recieving connection

Check if OpenVPN created tun0 interface

Try pinging VPN server from client

If you see the same output as above then its all good you’ve successfully set up a simple OpenVPN Server and Client network.

Visit Ubuntu official documentation for more info and some advanced configurations.

We value your input. Share your thoughts or ask questions by leaving a comment.

Umar Arafath

Hey there! I'm Umar Arafath, the face behind unofficialmentor, a passionate Software Engineering undergraduate diving into the IT industry. Even though my formal title may be a student, my heart lies in the field of DevOps. I share my daily learning adventures in this blog so it'll help me remember stuff. It's a win-win end of the day, I reinforce my knowledge, and you learn something new. Please be kind enough to leave a comment! Your feedback fuels my growth. Away from the desk, catch me on the cricket field or badminton court, polishing my physique. I'm also a motorbike enthusiast, who finds riding as a healing spell for my inner peace.

Leave a Reply

Your email address will not be published. Required fields are marked *