VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more

OpenVPN configuration files + Ubuntu’s network manager

DevOps

OpenVPN has feature that exports client configuration files. While it is definitely possible to run OpenVPN from the command line, I prefer to have a GUI that allows me to easily connect/disconnect from VPN. Ubuntu’s network manager and the .ovpn configuration files exported from OpenVPN does not play well together, however.

There is a workaround which involves cutting and pasting parts of the configuration file into separate files and adding some references to them in the configuration. After having done this a couple of times and helped other people with the same issue, I decided I’d write a simple tool to do the job instead.

openvpn-config-splitter is a very simple CLI-tool I wrote in node.js. It does most of the hard work for you, but you’ll still have to import the configuration and possibly change a few settings. Here’s a step-by-step guide on how to get OpenVPN installed, integrated with the network manager in Ubuntu (or Debian, Linux Mint etc.) and how to get your configuration imported:

  1. Install OpenVPN along with the OpenVPN extensions:
    sudo apt-get install network-manager-openvpn network-manager-openvpn-gnome
  2. Make sure you’ve got node.js installed (apt-get install nodejs), and run npm install -g openvpn-config-splitter (you might have to use sudo to install globally).
  3. Get your OpenVPN configuration file (ask your sysadmin if you’re not sure where/how) and put it somewhere you’ll find it, say ~/openvpn
  4. Run ovpnsplit ~/openvpn/client.ovpn (path to your configuration file) – after running this, you should be able to find a bunch of other files in the same folder (ca.crt, client.key and a few others).
  5. Open the network manager (it varies a bit from distro to distro) – somewhere in there you’ll find an option to add a VPN connection. When it prompts you to choose a VPN connection type, select “Import a saved VPN configuration” from the dropdown (or find a different import option, somewhere) and browse to the folder you stored your configuration file in.
  6. Make sure you select the altered configuration file (it should be postfixed with .split.ovpn).
  7. You’ll probably have to enter your username and password. Click save and try to connect!

If you run into a problem where you can only access resources on your organizations network, open up the VPN settings, go to “IPv4 Settings” and select “Automatic (VPN) addresses only“, then click on the “Routes” button. Check the “Use this connection only for resources on its network“-option and save the configuration. Disconnect, then reconnect. Hopefully you should be up and running!

If you have any issues reaching resources on your organizations network, you might have to set up one or more DNS-servers under the “IPv4 Settings”-tab, along with one or more search domains. Your sysadmin should be able to give you those settings, if needed.

Happy VPN’ing!

Developer at VG with a passion for Node.js, React, PHP and the web platform as a whole. espen.codes - @rexxars


3 comments

  • Julian

    and also you have to install npm before using it in stage 2
    ie sudo apt-get install npm


  • Joe

    Thanks so much for this, it really has saved me alot of time and hassle, configure openvpn on ubuntu workstations.


  • Raja Nagendra Kumar

    Thank You very much, found this after 3 hours of search and trying.. but once found worked in 3 min..

    It is clearly ubentu openvpn config file import issue.. this has nice workaround


Leave your comment