Ubuntu – Can “netplan” be used with OpenVPN

dnsnetplanopenvpn

I'm using Kubuntu 17.10, and use OpenVPN to connect to my corporate network. Since Ubuntu moved over to the new "netplan" way of doing network related things, I have found that several things in OpenVPN no longer work (like trying to set your DNS servers using dhcp-options and the up/down update-resolv-conf script).

My question is: is it possible to set a "netplan" that will set the OpenVPN's interface (tun0) DNS servers once tun0 is created? Something like:

network:
  version: 2
  renderer: networkd
  ethernets:
    tun0:
      dhcp4: yes
      dhcp6: no
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

I have managed to create my own vpn-up/vpn-down scripts which basically copy the appropriate yaml file over to /etc/netplan and then executes netplan apply, but this doesn't feel like the right way to do things.

Best Answer

If you're using OpenVPN on a desktop/laptop, I strongly suggest you use NetworkManager to control your VPN. It can pass through the right DNS information to the DNS backend (dnsmasq or systemd-resolved, depending on your release of Ubuntu), and it can do the right thing to bring up the VPN automatically on some interfaces, deal better with loss of connection, having to ask for credentials again, etc.

netplan does not have any special VPN support. Setting up a tun interface in an "ethernets:" stanza is likely not what you want, as will not create tun interfaces, and might in fact interfere with that OpenVPN might do to the interface; but if you really want to use it, you do need to roll your own vpn-up/vpn-down scripts triggered by openvpn to run 'netplan apply' with the right configuration files available in /etc/netplan.

Related Question