DeveloperBreeze

Introduction

OpenVPN is a robust, open-source VPN (Virtual Private Network) solution that provides secure access to private networks over the internet. It is one of the most popular and flexible VPN services available. This tutorial will guide you through installing and configuring OpenVPN on Ubuntu, allowing you to establish a secure connection to a remote network.


Table of Contents

  1. Prerequisites
  • Ubuntu version and user permissions
  • Required packages and dependencies
  1. Installing OpenVPN on Ubuntu
  • Using the Ubuntu package manager
  • Verifying the installation
  1. Setting Up OpenVPN Client
  • Acquiring the OpenVPN configuration file (.ovpn)
  • Configuring the OpenVPN client on Ubuntu
  1. Starting and Stopping the OpenVPN Service
  • Connecting to the VPN
  • Stopping the VPN connection
  1. Verifying the OpenVPN Connection
  • Checking connection status
  • Confirming IP address and route changes
  1. Automatic OpenVPN Start on Boot
  • Configuring OpenVPN to start on system boot
  1. Troubleshooting Common OpenVPN Issues
  • Diagnosing connectivity issues
  • Resolving DNS and routing problems

1. Prerequisites

Before getting started with OpenVPN, make sure your system meets the following requirements:

  • Ubuntu Version: This tutorial is based on Ubuntu 20.04 LTS or later, but it can be adapted to other versions of Ubuntu.
  • User Permissions: You need sudo or root privileges to install and configure OpenVPN.
  • OpenVPN Configuration File: You need a valid .ovpn configuration file from your VPN provider or system administrator. This file contains all the settings needed to connect to the VPN.

2. Installing OpenVPN on Ubuntu

OpenVPN is included in the default Ubuntu package repositories, making installation straightforward.

Step 1: Update Package List

Before installing any new software, it’s a good idea to update your package list to ensure all packages are up to date.

sudo apt update

Step 2: Install OpenVPN

To install OpenVPN, use the following command:

sudo apt install openvpn

The openvpn package contains both the OpenVPN server and client software, but this tutorial focuses on setting up the client.

Step 3: Verify Installation

Once the installation is complete, you can verify the installation by checking the version of OpenVPN:

openvpn --version

You should see version information and details about the configuration of the OpenVPN installation.


3. Setting Up OpenVPN Client

To set up the OpenVPN client, you need a .ovpn configuration file provided by your VPN provider or network administrator. This file contains all the necessary details to establish a VPN connection.

Step 1: Copy the OpenVPN Configuration File

Place the .ovpn configuration file in the /etc/openvpn/ directory. You may need to rename the file for consistency:

sudo cp /path/to/your-vpn-config.ovpn /etc/openvpn/client.conf

Replace /path/to/your-vpn-config.ovpn with the actual path to your configuration file.

Step 2: Check the Configuration File

You can open the .ovpn file in a text editor (like nano) to ensure it contains all the necessary details, such as:

  • Remote server address
  • Authentication type (password, certificate)
  • Encryption protocols
sudo nano /etc/openvpn/client.conf

If any details need to be added or modified, you can edit the file here.


4. Starting and Stopping the OpenVPN Service

Now that your configuration file is in place, you can start and stop the VPN connection.

Step 1: Start OpenVPN

To start the OpenVPN connection, use the following command:

sudo openvpn --config /etc/openvpn/client.conf

You may be prompted for your VPN username and password if the configuration requires authentication.

Step 2: Stop OpenVPN

To stop the OpenVPN connection, simply press Ctrl + C in the terminal where OpenVPN is running.

Alternatively, if you’re running OpenVPN as a service:

sudo systemctl stop openvpn@client

5. Verifying the OpenVPN Connection

Once connected, you should verify that the OpenVPN connection is working properly.

Step 1: Check the Connection Status

Open a terminal and check the status of the OpenVPN service:

sudo systemctl status openvpn@client

This will display whether OpenVPN is active and connected to the VPN server.

Step 2: Confirm IP Address

You can verify that your IP address has changed by running the following command:

curl ifconfig.me

This will show your public IP address. If the VPN connection is successful, it should display the IP address of the VPN server, not your local ISP-provided IP address.

Step 3: Check Routing Table

To verify that your traffic is being routed through the VPN, check the routing table with:

ip route

You should see routes that direct traffic through the VPN interface (often labeled as tun0).


6. Automatic OpenVPN Start on Boot

To configure OpenVPN to start automatically at boot, you can enable the OpenVPN service.

Step 1: Enable OpenVPN Service

Run the following command to enable OpenVPN at boot:

sudo systemctl enable openvpn@client

This ensures that the VPN connection is initiated every time your system boots up.

Step 2: Start the Service

To start the service without rebooting:

sudo systemctl start openvpn@client

7. Troubleshooting Common OpenVPN Issues

Here are a few common problems and solutions when using OpenVPN.

Issue 1: OpenVPN Fails to Connect

  • Check the logs: Run journalctl -xe or sudo systemctl status openvpn@client to check for specific errors in the OpenVPN logs.
  • Firewall/Port Issues: Ensure that the VPN port (usually 1194 for UDP) is not blocked by your firewall or ISP.

Issue 2: DNS Issues After Connecting to VPN

If you experience DNS resolution problems after connecting to OpenVPN:

  • Edit /etc/resolv.conf: Add the DNS server provided by your VPN provider.
  sudo nano /etc/resolv.conf

Add the following line, replacing the IP with your VPN's DNS:

  nameserver 8.8.8.8

Issue 3: Internet Not Working After VPN Connects

  • Check Default Gateway: Ensure the VPN server is configured as the default gateway. Use ip route to confirm routing.
  • Split Tunneling: If your configuration is set up for split tunneling, check that only specific traffic is routed through the VPN.

Conclusion

Using OpenVPN on Ubuntu provides a secure and flexible way to access remote networks. By following this tutorial, you’ve learned how to install OpenVPN, configure a client, and establish a secure VPN connection. Additionally, we’ve covered automatic startup and troubleshooting common issues, ensuring that your OpenVPN connection remains stable and reliable.

If you want further security and automation, you can explore using NetworkManager for easy VPN management or integrating OpenVPN with firewall rules for enhanced protection.

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

How to Stop SSH From Timing Out

If your SSH session closes after a minute of inactivity, it’s usually caused by idle timeouts. You can fix this with keep-alive settings on both the server and client.

Edit the SSH daemon config:

Aug 21, 2025
Read More
Tutorial

✅ How to Disable MySQL Password Validation on Ubuntu 25.04

If you want to bring back strong password policies:

INSTALL COMPONENT 'file://component_validate_password';

May 01, 2025
Read More
Tutorial

How to Move the MySQL Data Directory to a New Location on Ubuntu 25.04

If needed, recreate the MySQL socket directory:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

May 01, 2025
Read More
Tutorial

How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)

nvidia-smi

You should see output like:

Apr 14, 2025
Read More
Tutorial

🛡️ Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work

// web.php
Route::post('/contact', [ContactController::class, 'submit'])->middleware('throttle:3,1');

// ContactController
public function submit(Request $request) {
    if ($request->has('fake_field')) return abort(403); // honeypot
    if (now()->diffInSeconds(session('form_start_time')) < 3) return abort(403); // timing
    // other checks...
}

And in Blade:

Apr 04, 2025
Read More
Tutorial

How To view tables and the number of records in each table in a PostgreSQL database,

   SELECT relname AS table_name,
          n_live_tup AS row_count
   FROM pg_stat_user_tables
   ORDER BY table_name;

This query fetches the table names and live row estimates from PostgreSQL’s statistics catalog, pg_stat_user_tables.

Nov 06, 2024
Read More
Tutorial

How to install PostgreSQL

  \c mydatabase
  • Exit psql:

Nov 06, 2024
Read More
Tutorial

How to view tables on a PostgreSQL database hosted on Heroku

   heroku config:get DATABASE_URL -a <your-app-name>

This will display a URL in the format: postgres://<user>:<password>@<host>:<port>/<database>

Nov 06, 2024
Read More
Tutorial

How to view your Heroku Apps

Sign in to your Heroku account if you’re not already logged in.

Once logged in, you’ll see a list of all your applications on the dashboard. You can click on each app to view details, manage settings, view metrics, and more.

Nov 06, 2024
Read More
Cheatsheet

Essential dpkg Commands Cheat Sheet for Debian and Ubuntu Systems

  sudo dpkg --update-avail

Updates available packages by checking online repositories and downloads the latest versions to your local repository.

Oct 24, 2024
Read More
Tutorial

Clearing Unnecessary Logs on Ubuntu

  • Logrotate configuration files are located in /etc/logrotate.conf and /etc/logrotate.d/.

To trigger log rotation manually:

Oct 24, 2024
Read More
Tutorial

Getting Started with DevSecOps — Secure CI/CD Pipelines with Jenkins

If your team uses Slack, you can integrate Jenkins with Slack to receive real-time notifications about your pipeline status.

Tools like OWASP Dependency-Check and SonarQube generate security reports that can be visualized on the Jenkins dashboard or sent via email.

Oct 22, 2024
Read More
Tutorial
bash

How to Install and Configure Apache on Ubuntu

  • Access logs: /var/log/apache2/access.log
  • Error logs: /var/log/apache2/error.log

You can view the logs using the cat or tail command:

Oct 21, 2024
Read More
Tutorial
bash

How to Create SSL for a Website on Ubuntu

sudo systemctl restart nginx

Open your Apache SSL configuration file to further customize your SSL settings:

Oct 21, 2024
Read More
Tutorial
bash

How to Install MongoDB Shell (mongosh) on Ubuntu

wget https://downloads.mongodb.com/compass/mongosh-1.10.1-linux-x64.tgz

Extract the contents of the downloaded file using the tar command:

Oct 18, 2024
Read More
Tutorial

How to Install MongoDB on Ubuntu

curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-server-6.0.gpg

This downloads the MongoDB GPG key and stores it in your system's trusted keyring.

Oct 18, 2024
Read More
Cheatsheet

PM2 Cheatsheet

pm2 kill
pm2 uninstall pm2-logrotate

Oct 14, 2024
Read More
Tutorial
bash

How to Update Node.js and npm on Ubuntu

For Node.js 18 (LTS) (recommended):

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Oct 03, 2024
Read More
Tutorial
bash

How to Grant MySQL Root Privileges for 127.0.0.1

If you're working with a Laravel or any other application that uses MySQL, update your .env file or configuration file to use 127.0.0.1 as the DB_HOST instead of localhost:

DB_HOST=127.0.0.1
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=your_new_password

Oct 03, 2024
Read More
Tutorial
bash

How to Reset the MySQL Root Password Using DROP USER

   DROP USER 'root'@'localhost';

This removes the existing root user, including any potential issues related to password or privileges.

Oct 03, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!