(Last Updated On: July 7, 2018)

OpenVPN Server is a full-featured secure network tunneling VPN software. In this blog post, we will cover the steps to use nmcli to connect to OpenVPN Server on Linux. OpenVPN Server has Client software packages that run on Windows, MAC, Linux, Android, and iOS environments

I know the most common way of connecting to OpenVPN Server on Linux and Windows environments is by using OpenVPN client. But what if you wanted to use NetworkManager and its cli tool – nmcli.

OpenVPN with nmcli Requirements

The basic requirement for connecting to OpenVPN server using nmcli are:

  • NetworkManager running on a client machine
  • Installed and configured OpenVPN server
  • NetworkManager openvpn plugin
  • .ovpn OpenVPN profile for your account

So make sure you have NetworkManager installed and running on your machine. Since I use Arch Linux, I’ll add the commands, same for other distros:

Install NetworkManager on Arch Linux

To install NetworkManager on Arch Linux, use the command:

$ sudo pacman -S networkmanager

You also need to install the networkmanager-openvpn plugin

$ sudo pacman -S networkmanager-openvpn network-manager-applet

Install NetworkManager on Debian / Ubuntu

If you are running Ubuntu or any other Debian family operating system. Install the following packages

$ sudo apt-get install network-manager  network-manager-openvpn

With Gnome Desktop Environment, then include:

$ sudo apt-get install network-manager-gnome network-manager-openvpn-gnome

Install NetworkManager on CentOS 7

CentOS 7 comes with NetworkManager installed and running, you only need to install openvpn plugin for you to be able to import .ovpn profile.

$ sudo yum install NetworkManager-openvpn \
NetworkManager-openvpn-gnome

How to Import OpenVPN profile (.ovpn) using nmcli

Once you have installed the required packages and you have OpenVPN profile generated, continue to import the profile.

In this example, I assume OpenVPN profile name is called myopenvpn.ovpn and is located under your $HOME. Import the profile using the command:

$ cd ~/
$ sudo nmcli connection import type openvpn file myopenvp.ovpn
Connection 'myopenvp' (464b7c20-8999-4699-a4d7-3233cd7ea91e) successfully added.

You can confirm if the profile was imported successfully using the command:

$ nmcli connection show

To start using the profile, bring it up using:

$ nmci connection up myopenvpn
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27)

To check the connection details using:

$ nmcli connection show 
$ nmcli connection show |  egrep -i 'IP4|IPV6'

Depending on how you configured your OpenVPN server routes push, you can check ones populated on the server:

$ ip route

Try access any network on the route to see if it’s working.