13

I'm having trouble adding a WireGuard VPN connection to the Network Manager on Ubuntu. I've followed several online tutorials and tried different methods, but nothing seems to work.

I've installed WireGuard using the sudo apt install wireguard command and created the configuration file /etc/wireguard/wg0.conf . The VPN connection works fine when I start it using the sudo wg-quick up wg0 command, but I can't seem to add it to the Network Manager.

When I go to "Add VPN Connection" in the Network Manager, I only see options for OpenVPN and PPTP. There's also an option to "Import from file", but when I select my wg0.conf file, it says that the file format is not supported.

I've tried restarting the Network Manager with sudo service network-manager restart , but that doesn't seem to help. I'm running Ubuntu 22.04.1 LTS.

Any help or suggestions would be greatly appreciated. Thanks in advance!

2 Answers2

12

Modern Network Manager supports WireGuard by default, including one in Ubuntu 22.04 (maybe earlier). It's compiled-in, so wireguard package isn't needed. However, 22.04 Ubuntu network settings didn't support WG yet.

With that in mind, there are at least two ways to add connection:

  1. Open nm-connection-editor GUI, then use it to add WG connection.

  2. Alternatively: use nmcli. For example, if you were provided with WireGuard conf file by a system administrator, to add the connection just execute a

    nmcli connection import type wireguard file ./MyWG.conf
    

Ideally the connection ought to just appear in the network applet. But as mentioned, the 22.04 Gnome didn't know how to deal with WG yet; as a workaround you can start/stop the connection via terminal:

  • nmcli connection show
  • nmcli connection up MyWG
  • nmcli connection down MyWG

My colleague (Ubuntu 22.04) and me (Archlinux) are successfully using WG via NetworkManager, and we have no /etc/wireguard directory, nor wg command. So nothing mentioned in the other answer is necessary.

Hi-Angel
  • 4,810
2

Install wireguard

$ sudo apt install wireguard

Create a Cryptographic Key Pair

$ sudo -i
# cd /etc/wireguard
# umask 077
# wg genkey | tee /etc/wireguard/privatekey | wg pubkey | tee /etc/wireguard/publickey

Add Client Public Key to WireGuard VPN Server

# wg set wg0 peer <client-public-key> allowed-ips <client-VPN-address>

Create a Network Connection with NetworkManager's Connection Editor GUI Heading

Using nm-connection-editor's GUI as described here.

FedKad
  • 13,420
jasmines
  • 11,311