Setting Up WireGuard on Ubuntu/Linux

Setting Up WireGuard on Ubuntu

Ubuntu is a Linux distribution thats really popular. Updated versions of Ubuntu come with WireGuard support built-in to it’s NetworkManager package. Setup is pretty straightforward, but here’s a step-by-step method.
This installation method should work for almost all Linux distributions, modifying how WireGuard get’s installed based on each distributions preferred package manager.

Install WireGuard

If you haven’t already, get WireGuard via Ubuntu’s package manager apt. The commands are as follows.

sudo apt update
sudo apt install wireguard

Generate Encryption Keys

When using WireGuard in Linux it’s super easy to generate your keys, the command below will create 2 files; one for the private key and one for the public key.

sudo wg genkey | tee private.key | wg pubkey > public.key

Build Client Configuration

Once you have a public and private key secured, head over to your devices page and 'Setup A New Device` as described in our Getting Started guide.

When finished you should have a complete WireGuard configuration saved as wg0.conf.

Load Configuration and Connect

In Linux there are multiple ways to do this. The simplest is via the command line, but NetworkManager supports WireGuard as well.

Command Line

To start WireGuard via the command line, first copy the configuration to the proper location in /etc/wireguard/.

sudo cp wg0.conf /etc/wireguard/wg0.conf

Once wg0.conf is in it’s place you can use the wg-quick command to bring the interface up.

sudo wg-quick up wg0

The output should look something like the following

[email protected]:~$ sudo cp /tmp/wireguard/wg0.conf /etc/wireguard/wg0.conf
[email protected]:~$ sudo wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.223.192.81/32 dev wg0
[#] ip -6 address add fdd7:2413:ae79:12d8::108b:eb5b/128 dev wg0
[#] ip link set mtu 1280 up dev wg0
[#] resolvconf -a tun.wg0 -m 0 -x
[#] wg set wg0 fwmark 51820
[#] ip -6 route add ::/0 dev wg0 table 51820
[#] ip -6 rule add not fwmark 51820 table 51820
[#] ip -6 rule add table main suppress_prefixlength 0
[#] ip6tables-restore -n
[#] ip -4 route add 0.0.0.0/0 dev wg0 table 51820
[#] ip -4 rule add not fwmark 51820 table 51820
[#] ip -4 rule add table main suppress_prefixlength 0
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
[#] iptables-restore -n
[email protected]:~$ 

NetworkManager Setup

NetworkManager provides a graphical user interface via Ubuntu’s Settings Dialogue. You can begin by opening up Network Settings in Ubuntu.

Click the + sign next to VPN and then 'Import From File` to get started.

ubuntu2

Find your wg0.conf file and load it up!


Click ‘Add’ to add the configuration to NetworkManager.

From here just toggle the switch to connect!

You’ll also see the VPN icon in your system tray.

ubuntu7

That’s it! You’re finished. Check your IP Address.


If you have any more questions or need additional help, give us a shout in our Support Category.