Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Setup Git Server on Ubuntu?
Next article icon

How to install and setup the OpenVPN server on Ubuntu/Debian?

Last Updated : 27 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

A VPN is a tool that acts as a middleman between you and the Internet that you browse. Whatever you do online, the VPN acts as a connecting bridge between your computer and the Internet. To the services that you are using, for example - visiting a website), to them, it appears as if your VPN is the client, but in reality, the VPN relays the information back to your computer, and in turn, hides your identity (IP address). A good VPN encrypts your connection, so whatever data goes between your computer and the VPN server is encrypted, and your ISP cannot read your internet traffic. There are a lot of VPN services that you can subscribe to, but using them means trusting them with your browsing data. So, what is the alternative? Well, you can go on to create your own VPN server, and doing so is not that tricky at all. You would require the following to create your own VPN server:

  • A Linux virtual machine with at least 1GB RAM and 1vCPU.
  • A VPN software like OpenVPN.

There is a lot of VPN software that let you host a VPN server on a Linux virtual machine, in this article, we will be focusing on one of them, which is OpenVPN. 

What is OpenVPN?

OpenVPN is Company that created the OpenVPN Community Edition VPN server which is open-source and free to use. They also developed the OpenVPN tunneling protocol which is a tunneling protocol based on SSL encryption protocol. Many VPN services use this protocol. There is something else which is called OpenVPN Access server which is an enterprise product that has a web Interface and only offers 2 simultaneous connections on the free version.

Why use OpenVPN?

There are a number of reasons which make OpenVPN a great choice.

  • OpenVPN client (the software which is used on the client devices to connect to the VPN server) supports Windows, macOS, Linux, Android and iOS.
  • It is very secure as it uses 256-bit encryption keys.
  • It has vast community support.
  • It is open source which makes it transparent, and you can modify the source code to tweak something as per your liking.

Installing and configuring OpenVPN 

Step 1: We will begin to install and configure our OpenVPN server. Begin by updating and upgrading your system packages with the following commands.

sudo apt update  sudo apt upgrade -y

Step 2: Now, configuring OpenVPN is a technical process and a lot of steps are required to be performed in order to configure it properly. Luckily, there is a script which makes this process easy for us. We will use this to script to install and configure our OpenVPN server. To download this script, execute the following command

wget https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh

 

Step 3: To execute this script, we have to give it execution permission. To do that, execute the following command

sudo chmod +x openvpn-install.sh

Step 4: Now, Execute the script

sudo ./openvpn-install.sh

It will ask a bunch of questions. 

  • The first prompt asks you to check the IP address of your Linux machine. Press enter if it is the correct one, if not, press any other key. 
  • Next, it will ask if you want to enable IPv6 connectivity. You can leave it at default and press enter.
  • Next, it will ask you which port you want to use. The default port is 1194. You can go with the default port or choose your own port. We need to open this port through our firewall, which we will do later.
  • Next, it will ask you if you want to use TCP or UDP. Press enter to choose UDP.
     
 
  • Next, It will ask you which DNS resolver you want to use. I'll recommend you to choose Cloudflare (option 3). 
  • Next, It will ask you if you want to use compression. The default option is no, go ahead and press enter.
  • Next, it will ask you to customize encryption settings. Again, the default option is no, go ahead and press enter.
 
  • Press enter at the next prompt to start the process of applying the settings and installing the required certificates.
  • Next, Enter the name of the client which will connect to our VPN server.
  • Next, it will ask if you want to use a password for the client. Enter 2 and enter your password.
 

Step 5: That's it, the configuration is done. Now OpenVPN creates a file for every client(user) that you create. To add more client, revoke an existing client or uninstall OpenVPN, execute the script again and it will give you the option to do so.

 

Step 6: We need to open port 1194 for UDP connections. Some cloud service providers have their own Firewall, you need to open this port through your cloud portal. If you use UFW to manage your firewall, execute the following command.

sudo ufw allow 1194/udp

Connecting to our OpenVPN server

To connect to our OpenVPN server, we first need the configuration file which was generated by the script at the end of its execution. 

 

This jivendra.ovpn file in our configuration file, we need to download this in order for us to connect to it. Now, there are ways to download it, you can set up an FTP server, or use SCP. The easiest way to get this file is to copy the contents of this file, create a new file on the client device, paste the contents and save this file as the name of the configuration file. You can print the contents of the configuration file with the following command.

cat jivendra.ovpn

Copy the output from the terminal, create a new file on your local machine, paste the contents and save it as 'jivendra.ovpn', or you can name it anything, the name does not matter. Now, You need to download the client software on your machine. 

Step 1: Let's see how you connect to your VPN server from a Linux client. Download OpenVPN on your device with the following command

sudo apt install openvpn
 

Step 2: Now to connect to the server, execute the following command

sudo openvpn --config path_to_client_configuration_file

 

After that, we should see the following at your terminal.

 

Our device is successfully connected to your self-hosted OpenVPN server. To close the connection, press Ctrl + C.


Next Article
How to Setup Git Server on Ubuntu?

J

jivendrasah
Improve
Article Tags :
  • Linux-Unix
  • How To
  • Installation Guide
  • how-to-install

Similar Reads

  • How to install the NFS server on Ubuntu?
    NFS, which stands for Network File System, was created in 1984 by Sun Microsystems. A file system called Network File System (NFS) enables local access to distant files from various places across a network.NFS has a typical client/server architecture for this access, facilitating sharing between Lin
    4 min read
  • How To Install the Apache Web Server on Debian 11?
    Apache is an open-source web server that’s available for Linux servers free of charge. Installing an Apache web server on Linux is a straightforward process. In this article, we will install Apache Web Server Debian 11 (Bullseye). Steps to Install Apache Web Server in LinuxStep 1: Update Your System
    3 min read
  • How to Install GUI on Ubuntu Server?
    The Ubuntu Server is a variant of the standard Ubuntu. It is a tailored version for networks and services. Ubuntu Server is an open-source operating system for IoT devices and Servers. Unlike standard Ubuntu, the Ubuntu server doesn't have any Graphical User Interface or GUI. There may be many insta
    3 min read
  • How to Setup Git Server on Ubuntu?
    Git is a popular version control system that is widely used for software development and other collaborative projects. Setting up a Git server on Ubuntu allows you to host Git repositories on your Git, which can be useful for collaborating with a team or hosting open-source projects that others can
    6 min read
  • How to Install and Customize Apache on Ubuntu or Debian?
    One of the most dominant forces in web server software is the Apache HTTP Server, often shortened to Apache. This free and open-source project, overseen by the Apache Software Foundation, has been a major player in shaping the Internet since its launch in 1995. Installing an Apache web server on Ubu
    2 min read
  • How to Install and Manage Node using NVM on Godaddy Server ?
    Managing multiple versions of Node.js on your server can be quite a task, especially if you're developing or maintaining applications that require different versions. Node Version Manager (NVM) simplifies this process by allowing you to install and switch between different versions of Node.js easily
    3 min read
  • How To Install the Apache Web Server on CentOS 7
    Apache Web Server, commonly known as Apache is a free, open-source, and one of the most widely used web servers in the world. Apache web server is developed and maintained by Apache Software Foundation. Apache is not any physical server, it is a software application running either on a physical/virt
    4 min read
  • How to Install and Set up a WAMP Server ?
    Windows, Apache, MySQL and PHP is commonly abbreviated as WAMP. Some people may confuse with LAMP but the only difference between the two is their operating systems. In case of LAMP, L stands for Linux. Setting up a server included the installation of all the software listed in the abbreviation. Ano
    3 min read
  • How to Install Consul Server on Ubuntu 22.04
    Consul is a free and open-source service discovery by Hashicorp. It's available on every Linux distribution, including Debian/Ubuntu, and RHEL/CentOS distributions. It is used for service discovery. Required Ubuntu VersionGenerally, we should use the latest Ubuntu versions currently 22.04 but this m
    4 min read
  • How to Set Up a Mail Server with Postfix and Dovecot on Ubuntu?
    If you are running a Small Business or have a Personal Website, then the Development of a Personal Mail Server will become essential. To Set Up Mail Server on Ubuntu, you need to use Postfix and Dovecot Tools. Postfix and Dovecot on Ubuntu are essential to Send and Receive Emails in a Mail Server. T
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences