I have installed an OpenVPN server on a Debian Linux server. I have a client.ovpn file for my VPN server. How do I use it with Network Manager GUI? Is it possible to install or import client.ovpn file using the command line with Network Manager on a Ubuntu Linux or CentOS Linux desktop?

The Gnome NetworkManager has pluggable support for VPN software, including Cisco compatible VPNs (using vpnc), openvpn, and Point-to-Point Tunneling Protocol (PPTP). You need to simply install the NetworkManager VPN plugin and configure the users machines with the VPN’s settings.
How to use a .ovpn file with Network Manager in linux
This page explains how to import .opvn (OpenVPN config) file using a GUI or CLI method in Linux.

Step 1 – Install OpenVPN plugin

Type 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
Sample outputs:

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 (2.7.6.1-2) ...
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) ...

Step 2 – How to import OpenVPN config file from command line with NetworkManager (method #1)

Open the Terminal application. The syntax is:
sudo nmcli connection import type openvpn file /path/to/your.ovpn
For example:
$ sudo nmcli connection import type openvpn file /home/vivek/ubuntu16.04LTS.ovpn
Sample outputs:

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

Your connection is called ‘ubuntu16.04LTS’ and to make connection to the OpenVPN server, run:
$ nmcli connection up ubuntu16.04LTS
Sample outputs:

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

To see OpenVPN connection details:
$ nmcli connection show ubuntu16.04LTS
To see IPv4/IPv6 OpenVPN client IP and other info, run:
$ nmcli connection show ubuntu16.04LTS | egrep -i 'IP4|IPV6'
$ nmcli connection show ubuntu16.04LTS | egrep -i 'IP4'

Sample outputs:

IP4.ADDRESS[1]:                         10.8.0.8/24
IP4.GATEWAY:                            10.8.0.1
IP4.DNS[1]:                             10.8.0.1

Verify it with the ping command i.e. send ping-pong requests to OpenVPN gateway:
$ ping -c 4 10.8.0.1
Sample outputs:

PING vpn (10.8.0.1) 56(84) bytes of data.
64 bytes from vpn (10.8.0.1): icmp_seq=1 ttl=64 time=288 ms
64 bytes from vpn (10.8.0.1): icmp_seq=2 ttl=64 time=279 ms
64 bytes from vpn (10.8.0.1): icmp_seq=3 ttl=64 time=172 ms
64 bytes from vpn (10.8.0.1): 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

Step 3 – Import a .ovpn file with Network Manager GUI (method #2)

Open Network Manager from Gnome settings option and select Network tab and click on the VPN + symbol:

Fig.01: Configuring OpenVPN client

From the Add VPN windows, click on the “Import from file…” option:

Fig.02: Click on “Import from file…”


You must navigate to your .ovpn file (/home/vivek/ubuntu16.04LTS.ovpn) and click on Open button:

Fig.3: Navigate your file system and select the file to import

Click on the Add button:

Fig.04: You can see all settings imported. Make sure IPv4/IPv6 and routing/DNS all set to automatic.

Finally, click on off button to turn on the VPN:

Fig.05: Testing your OpenVPN client

You can now browse the Internet using your VPN server. Test it using ping command/dig command/host command:
$ ping google.com
$ host cyberciti.biz

To find out your IP address i.e. make sure you public IP address changed after connecting to the OpenVPN server, run:
$ dig +short myip.opendns.com @resolver1.opendns.com
OR
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
And, there you have it a .ovpn file with Network Manager GUI/CLI imported directly for connection purpose on Linux operating system.
[toc]pi-hole[/toc]
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Alejandro Nov 30, 2017 @ 8:48

    Is there a way for making work if the vpn has an aditional challenge like Google Authenticator?

  • Kai Aug 19, 2020 @ 6:25

    If somebody else runs into the issue on Fedora 32 (Kernel 5.7.15-200.fc32.x86_64) that the openvpn plugin fails (VPN plugin: failed: connect-failed (1)): The certificates were included in my .ovpn file. When importing this file, the certificates will be extracted and saved under /root/.cert

    The solution from this ticket in the Red Hat Bugtracker solved the issue for me: https://bugzilla.redhat.com/show_bug.cgi?id=1774678
    Please run as root or with sudo to fix labels of cert files. :
    restorecon -Rv /root/.cert/

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum