How to Set Up WireGuard VPN Client on Ubuntu Desktop
Tags: vpn, linux, ubuntu
Published: 2021-03-22 20:12:59

---
title: How to Set Up WireGuard VPN Client on Ubuntu Desktop
published: true
date: 2021-01-14 00:00:00 UTC
tags: vpn, linux, ubuntu
canonical_url: https://tech.serhatteker.com/post/2021-01/how-to-set-up-wireguard-client-on-ubuntu-desktop/
series : Set-Up WireGuard VPN
---

## 0. Prerequisite

You need a working **WireGuard** VPN server. Learn how to set that up here: [How to Set Up WireGuard VPN Server on Ubuntu]({{< relref "how-to-set-up-wireguard-vpn-server-on-ubuntu.md" >}} "How to Set Up WireGuard VPN Server on Ubuntu")

## 1. Install

First we update our Ubuntu host machine then install **WireGuard**:

```bash
$ sudo apt update
$ sudo apt install wireguard
```

**NOTE:**

You may see over the web that you should install WireGuard with **ppa**,
like:

*$ sudo add-apt-repository ppa:wireguard/wireguard*

This is an outdated method and as we seen in https://launchpad.net/%7Ewireguard:

> This formerly was responsible for producing a PPA for WireGuard on Ubuntu. That functionality has now been folded into Ubuntu itself, so our old PPA has been removed. Simply run **apt install wireguard** on all Ubuntus ≥ 16.04



## 2. Configure

### 2.0. Keys

WireGuard ships with two command-line tools: `wg` and `wg-quick` that allow you to configure and manage the WireGuard.

Run the following command to generate the *public* and *private* keys:

```bash
$ sudo mkdir -p /etc/wireguard/clients
$ wg genkey | sudo tee /etc/wireguard/clients/desktop.key | wg pubkey | sudo tee /etc/wireguard/desktop/clients.key.pub
```

This places our keys under our `/etc/wireguard/clients` directory that we just created. As usual, **DO NOT** share your **private** key with anyone else, otherwise your VPN will be compromised.

You can view these files with `cat`:

```bash
$ cat /etc/wireguard/clients/desktop.key
$ cat /etc/wireguard/clients/desktop.key.pub
```

### 2.1. dekstop.conf File

Create configuration file,

```bash
$ sudoedit /etc/wireguard/wg0.conf
```

and add following settings:

```systemd
[Interface]
PrivateKey = DESKTOP_CLIENT_PRIVATE_KEY
Address = 10.0.0.2/24

[Peer]
PublicKey = YOUR_SERVER_PUBLIC_KEY
Endpoint = YOUR_SERVER_IP_ADDRESS:51820
AllowedIPs = 0.0.0.0/0
```

Replace `DESKTOP_CLIENT_PRIVATE_KEY` with your *private* key in `/etc/wireguard/clients/desktop.key`.

### 2.2. Add Desktop Client to Server

The last configuration step is to add your dekstip client's **public** key and **IP address** to your **server**:

```bash
$ sudo wg set wg0 peer DESKTOP_CLIENT_PUBLIC_KEY allowed-ips 10.0.0.2
```

## 3. Start WireGuard

### 3.0. wg up

When everything done above, bring the `wg0` interface up using the attributes specified in the configuration file:

```bash
$ sudo wg-quick up wg0
```

Now you should be connected to your Ubuntu VPN server, and the traffic from your client machine should be routed through it. You can check the connection with:

```bash
$ sudo wg
```

and the output should be like:

```bash
interface: wg0
  public key: HFqTSN2SE6LvvEU/xV3eJ0KArQEkTx1mYZpAjRtAjwE=
  private key: (hidden)
  listening port: 22870
  fwmark: 0xca6c

peer: 8Mg3Vgw+QduVhJaLERXQbyrPL1/nUWa27Ly8ZVTGTHs=
  endpoint: XXX.XXX.XXX.XXX:51820
  allowed ips: 0.0.0.0/0
  latest handshake: 1 minute, 18 seconds ago
  transfer: 67.58 KiB received, 170.36 KiB sent
```

### 3.1. Start at Boot

If you want to to start your **WireGuard** after every system reboot just run:

```bash
$ sudo systemctl enable wg-quick@wg0
```

To remove this:

```bash
$ sudo systemctl disable wg-quick@wg0
```

## 4. Test WireGuard

You can now check you `IP` searching on the browser **what is my ip** or just use `curl` to achieve that from your `cli`:

```bash
$ curl ifconfig.me
```

You should now see your `YOUR_SERVER_IP_ADDRESS` instead of your your *local* `IP` which your **ISP** provided.

Congrats!

All done!




[How to Set Up WireGuard VPN Server on Ubuntu]: https://tech.serhatteker.com/post/2021-01/how-to-set-up-wireguard-vpn-server-on-ubuntu/