# How to set up your own WireGuard VPN on a VPS

> How to set up a WireGuard VPN server on a small VPS: server and client keys, routing, firewall rules and a phone profile, with fixes for common errors.

Source: https://lowcostserv.com/guides/set-up-wireguard-vpn · Publisher: LowCostServ (lowcostserv.com) · Prices in US dollars, as published on November 26, 2026.

Build a private VPN on a small VPS: server and client keys, routing, firewall rules and a phone profile.

By LowCostServ · Updated November 12, 2026 · 3 min read

A personal VPN is one of the best uses of a small VPS: your own exit point, no shared IP reputation, no provider reading your traffic. WireGuard is fast, modern and small enough to configure by hand. This guide uses Ubuntu or Debian on the server, the network `10.8.0.0/24` inside the tunnel, and `203.0.113.10` as the server’s public address.

## 1. Install WireGuard

```
sudo apt update
sudo apt install -y wireguard iptables qrencode
```

## 2. Create the keys

Each side has a private key, which never leaves it, and a public key, which the other side needs. Create both pairs on the server for now:

```
sudo -i
cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee phone.key | wg pubkey > phone.pub
```

## 3. Let the server route traffic

```
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/99-wireguard.conf
sysctl --system
```

Find the name of the public network interface. It is the word after `dev`:

```
ip route show default
```

The examples below assume `eth0`. Replace it if yours is different, for instance `ens3`.

## 4. Write the server configuration

Create `/etc/wireguard/wg0.conf`. Paste the contents of `server.key` and `phone.pub` where indicated:

```
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -A FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -D FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

[Peer]
# phone
PublicKey = PHONE_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32
```

If you use ufw, open the port:

```
ufw allow 51820/udp
```

## 5. Start the tunnel

```
systemctl enable --now wg-quick@wg0
wg show
```

`wg show` lists the interface and its peer. The tunnel now starts at every boot.

## 6. Configure the first device

Still on the server, create `/etc/wireguard/phone.conf` with the contents of `phone.key` and `server.pub`:

```
[Interface]
PrivateKey = PHONE_PRIVATE_KEY
Address = 10.8.0.2/32
DNS = 1.1.1.1

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
```

`AllowedIPs = 0.0.0.0/0, ::/0` sends all traffic through the tunnel. For a phone, show the file as a QR code and scan it with the WireGuard app:

```
qrencode -t ansiutf8 < phone.conf
```

On a computer, copy the file over a secure channel and import it in the WireGuard application, or place it in `/etc/wireguard/` on Linux and run `wg-quick up phone`.

## 7. Check that it works

- Connect from the device, then run `wg show` on the server: a “latest handshake” line a few seconds old means the tunnel is up.
- Open a “what is my IP” page on the device. It should show the server’s address.

## Adding more devices

Each device gets its own key pair and its own address: `10.8.0.3`, `10.8.0.4` and so on. Add a `[Peer]` block for it in `wg0.conf`, then apply the change without dropping existing connections:

```
wg syncconf wg0 <(wg-quick strip wg0)
```

## When it does not work

| Symptom | Look at |
| --- | --- |
| No handshake at all | UDP port 51820 closed by a firewall, a wrong `Endpoint`, or keys pasted in the wrong place |
| Handshake, but no internet | IP forwarding not enabled, or the wrong interface name in the `PostUp` lines |
| Websites by IP work, names do not | The `DNS` line in the client configuration |
| It worked until the server rebooted | `systemctl enable wg-quick@wg0` was skipped |

## Tidy up

Once the device is configured, delete its private key from the server: `rm /etc/wireguard/phone.key /etc/wireguard/phone.conf`. A private key belongs on one device only. And keep the server itself in shape: [Secure a new Linux server in 15 minutes](https://lowcostserv.com/guides/secure-a-new-linux-server).

## Sources and further reading

- [WireGuard: Quick Start](https://www.wireguard.com/quickstart/)
- [WireGuard: wg-quick(8) manual page](https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8)
- [Ubuntu Server documentation: Using the VPN as the default gateway](https://ubuntu.com/server/docs/how-to/wireguard-vpn/vpn-as-the-default-gateway/)
- [Ubuntu Server documentation: Common tasks in WireGuard VPN](https://ubuntu.com/server/docs/how-to/wireguard-vpn/common-tasks/)

**Put it into practice**

- [**Cloud VPS**: Cloud VPS from $3.99/mo with an unmetered 1 Gbps port.](https://lowcostserv.com/vps)
- [**Unmetered VPS**: A 1 Gbps port with no traffic bill.](https://lowcostserv.com/unmetered-vps)

**Keep reading**

- [**Your access key: an account with no email or password**: Getting started · 4 min read](https://lowcostserv.com/guides/access-key)
- [**How to connect to a Linux server with SSH**: Getting started · 3 min read](https://lowcostserv.com/guides/connect-to-a-server-with-ssh)
- [**How to connect to a Windows RDP server**: Getting started · 3 min read](https://lowcostserv.com/guides/connect-to-windows-rdp)

## Read next Two guides to follow this one.

[All security guides](https://lowcostserv.com/guides/topic/security)

- [How to secure a new Linux server in 15 minutes](https://lowcostserv.com/guides/secure-a-new-linux-server): The first steps on any fresh server: updates, a non-root user, SSH keys, a firewall and automatic security patches. (Security, 4 min read, Nov 12, 2026)
- [DMCA takedowns explained, and what DMCA-ignored hosting means](https://lowcostserv.com/guides/dmca-takedowns-explained): How a DMCA notice works, why hosts suspend first and ask later, and what “DMCA-ignored” hosting does and does not cover. (Privacy and policy, 4 min read, Nov 12, 2026)

## Your own server, in a few minutes.

Cloud VPS from $3.99 a month: no email, no ID, crypto payment, root access in minutes.

- **No KYC**: No email, no ID
- **No DMCA**: Notices not acted on
- **Crypto friendly**: BTC, ETH, XMR, USDT, SOL
- **Unmetered**: On every plan

---

LowCostServ rents cloud VPS, dedicated servers, GPU servers and Windows RDP servers and registers domain names, with no identity check and payment in crypto. Every plan and price: https://lowcostserv.com/pricing.md · The company in facts: https://lowcostserv.com/about.md · Index of the site for language models: https://lowcostserv.com/llms.txt
