How to import a OpenVPN .ovpn file with Network Manager or Command Line in Linux

Do you have an OpenVPN server on your Linux Server and need to use an OpenVPN .ovpn file on it?

How can i configure OpenVPN client on Linux?

VPN Software such as Cisco compatible VPNs (using vpnc), openvpn, and Point-to-Point Tunneling Protocol (PPTP) are supported in Gnome NetworkManager and on Linux system in general.
What needs to be done is to simply install the NetworkManager VPN plugin and configure the user's machines with the VPN's settings.
Here at LinuxAPT, we regularly help our Customers to perform Linux Queries on their Servers as part of our Server Management Services.
In this context, we shall look into how to import .opvn (OpenVPN config) file using a GUI or CLI method in Linux.

Steps to import a OpenVPN .ovpn file with Network Manager or Command Line in Linux?

To get started, follow the following process;

1. How to install OpenVPN plugin?

To get OpenVPN plugin installed, simply execute the following  apt-get command or apt command to install the Gnome NetworkManager OpenVPN plugin;

sudo apt install network-manager-openvpn-gnome openvpn-systemd-resolved

You will get an output such as this;

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following additional packages will be installed:

  libnm-glib-vpn1 libnss-resolve libpkcs11-helper1 network-manager-openvpn openvpn

Suggested packages:

  resolvconf easy-rsa

The following NEW packages will be installed:

  libnm-glib-vpn1 libnss-resolve libpkcs11-helper1 network-manager-openvpn network-manager-openvpn-gnome openvpn openvpn-systemd-resolved

0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.

Need to get 747 kB of archives.

After this operation, 2,345 kB of additional disk space will be used.

Do you want to continue? [Y/n] y

Get:1 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnm-glib-vpn1 amd64 1.8.4-1ubuntu3 [13.8 kB]

Get:2 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 libnss-resolve amd64 234-2ubuntu12 [110 kB]

Get:3 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libpkcs11-helper1 amd64 1.22-2 [44.2 kB]

Get:4 http://in.archive.ubuntu.com/ubuntu artful/main amd64 openvpn amd64 2.4.3-4ubuntu1 [469 kB]

Get:5 http://in.archive.ubuntu.com/ubuntu artful/main amd64 network-manager-openvpn amd64 1.2.10-0ubuntu2 [30.6 kB]

Get:6 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 network-manager-openvpn-gnome amd64 1.2.10-0ubuntu2 [71.0 kB]

Get:7 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 openvpn-systemd-resolved amd64 1.2.6-1 [8,626 B]

Fetched 747 kB in 3s (206 kB/s)                      

Preconfiguring packages ...

Selecting previously unselected package libnm-glib-vpn1:amd64.

(Reading database ... 197667 files and directories currently installed.)

Preparing to unpack .../0-libnm-glib-vpn1_1.8.4-1ubuntu3_amd64.deb ...

Unpacking libnm-glib-vpn1:amd64 (1.8.4-1ubuntu3) ...

Selecting previously unselected package libnss-resolve:amd64.

Preparing to unpack .../1-libnss-resolve_234-2ubuntu12_amd64.deb ...

Unpacking libnss-resolve:amd64 (234-2ubuntu12) ...

Selecting previously unselected package libpkcs11-helper1:amd64.

Preparing to unpack .../2-libpkcs11-helper1_1.22-2_amd64.deb ...

Unpacking libpkcs11-helper1:amd64 (1.22-2) ...

Selecting previously unselected package openvpn.

Preparing to unpack .../3-openvpn_2.4.3-4ubuntu1_amd64.deb ...

Unpacking openvpn (2.4.3-4ubuntu1) ...

Selecting previously unselected package network-manager-openvpn.

Preparing to unpack .../4-network-manager-openvpn_1.2.10-0ubuntu2_amd64.deb ...

Unpacking network-manager-openvpn (1.2.10-0ubuntu2) ...

Selecting previously unselected package network-manager-openvpn-gnome.

Preparing to unpack .../5-network-manager-openvpn-gnome_1.2.10-0ubuntu2_amd64.deb ...

Unpacking network-manager-openvpn-gnome (1.2.10-0ubuntu2) ...

Selecting previously unselected package openvpn-systemd-resolved.

Preparing to unpack .../6-openvpn-systemd-resolved_1.2.6-1_amd64.deb ...

Unpacking openvpn-systemd-resolved (1.2.6-1) ...

Setting up libnm-glib-vpn1:amd64 (1.8.4-1ubuntu3) ...

Processing triggers for ureadahead (0.100.0-20) ...

Setting up libpkcs11-helper1:amd64 (1.22-2) ...

Setting up openvpn (2.4.3-4ubuntu1) ...

Processing triggers for libc-bin (2.26-0ubuntu2) ...

Processing triggers for systemd (234-2ubuntu12) ...

Setting up libnss-resolve:amd64 (234-2ubuntu12) ...

First installation detected...

Checking NSS setup...

Processing triggers for man-db ( ...

Processing triggers for dbus (1.10.22-1ubuntu1) ...

Setting up openvpn-systemd-resolved (1.2.6-1) ...

Setting up network-manager-openvpn (1.2.10-0ubuntu2) ...

Setting up network-manager-openvpn-gnome (1.2.10-0ubuntu2) ...

Processing triggers for libc-bin (2.26-0ubuntu2) ...

2. How to import OpenVPN config file from command line with NetworkManager?

To perform this task, open your server vian an SSH tool such as putty and execute the following command;

sudo nmcli connection import type openvpn file /path/to/your.ovpn

For instance;

sudo nmcli connection import type openvpn file /home/root/ubuntu16.04LTS.ovpn 

You will get an output such as this;

Connection 'ubuntu16.04LTS' (800b8c5a-0851-48ae-813c-c90eb593014d) successfully added.

Then your connection is named "ubuntu16.04LTS" and to make connection to the OpenVPN server, execute:

nmcli connection up ubuntu16.04LTS

You will see the following output;

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27)

In order to see OpenVPN connection details, execute;

nmcli connection show ubuntu16.04LTS

In order to see  IPv4/IPv6 OpenVPN client IP and other info, execute;

nmcli connection show ubuntu16.04LTS | egrep -i 'IP4|IPV6'
nmcli connection show ubuntu16.04LTS | egrep -i 'IP4'

The output will look like this;


To verify the OpenVPN Server, use the ping command as shown below;

ping -c 4

You will get an output such as this;

PING vpn ( 56(84) bytes of data.
64 bytes from vpn ( icmp_seq=1 ttl=64 time=288 ms
64 bytes from vpn ( icmp_seq=2 ttl=64 time=279 ms
64 bytes from vpn ( icmp_seq=3 ttl=64 time=172 ms
64 bytes from vpn ( icmp_seq=4 ttl=64 time=77.5 ms


--- vpn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 77.547/204.609/288.526/86.425 ms

3. How to import an .ovpn file with Network Manager GUI?

i. Start by opening "Network Manager" from "Gnome settings" option and select "Network" tab and click on the "VPN +" symbol.
ii. Then from the "Add VPN" windows,  click on the "Import from file…" option.
iii. Next, go to the .ovpn file located at "/home/username/ubuntu16.04LTS.ovpn" and click on the "Open" button.. Then click on the "Add" button.
iv. Finally, click on the "off" button to turn on the VPN.

How to test your configured VPN server?

Now that you have configured the OpenVPN server, you can now browse the Internet using your VPN server. To do this, use the ping command/dig command/host command as shown below;

ping google.com

To know your IP address, execute the following command;

dig +short myip.opendns.com @resolver1.opendns.com

Or you can use;

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

[Need additional support to set up OpenVPN on your Linux Server? We are available to help you today.]


This article will guide you on how to import .opvn (OpenVPN config) file using a GUI or CLI method in Linux.