Guide · Private VPN

How to set up a WireGuard VPN on a VPS

Run your own private VPN in 16 steps across 4 parts: choose where your traffic should exit, install WireGuard on Ubuntu or Debian, connect your laptop and phone, and keep it secure. Every command is ready to copy.

By the VPSPulse team · Updated · 15 min read

  • Your own private VPN
  • Laptop and phone setup
  • Commands for Ubuntu and Debian

How do you set up a WireGuard VPN?

Rent a Linux server in the country you want your traffic to exit from, install the wireguard package, create a key pair for the server and one for each device, describe them in /etc/wireguard/wg0.conf, turn on IP forwarding, open UDP port 51820 and start the wg-quick@wg0 service. Then import a short configuration file, or scan a QR code, in the WireGuard app on your laptop or phone. By hand it takes 15 to 30 minutes. With our one-click install, WireGuard is already on the server when you log in.

At a glance

Time
15 to 30 minutes by hand, a few minutes with the one-click install
Skill level
Comfortable with SSH and a terminal
You need
A Linux server, SSH access and the WireGuard app on each device
Default port
UDP 51820
Tested on
Ubuntu 22.04 and 24.04, Debian 12 and 13
Jump to a section
  1. Part 1: Plan your VPN server
    1. Decide what your VPN should do
    2. Choose a location and a server size
  2. Part 2: Install WireGuard
    1. Option A: get WireGuard pre-installed on VPSPulse
    2. Option B: install WireGuard by hand
    3. Create the server's key pair
    4. Write the server configuration
    5. Turn on forwarding and open the port
    6. Start WireGuard
  3. Part 3: Connect your devices
    1. Create a key pair for the device
    2. Add the device to the server
    3. Write the device's configuration
    4. Import it on your laptop or phone
    5. Check that your traffic goes through the VPN
  4. Part 4: Keep it secure and running
    1. Remove a lost or old device
    2. Keep the server updated and backed up
    3. Fix common problems
  5. FAQ

Part 1: Plan your VPN server

Two decisions shape everything else: what you expect the VPN to do, and where the server should be.

Step 1

Decide what your VPN should do

WireGuard builds an encrypted tunnel between your devices and your server. Everything you send goes through that tunnel first, and then out to the internet from the server's address. That gives you a few practical things:

  • Safer public Wi-Fi. Hotel, airport and café networks only see encrypted traffic to one address.
  • One fixed IP address of your own. Handy for logging in to services that only accept known addresses, or for reaching your own servers and admin panels.
  • Traffic that exits in a country you choose. Websites see the server's location instead of yours.
  • No shared VPN service in the middle. The server, the keys and the settings are yours, and nobody else's traffic shares your address.

Good to know: A VPN moves trust from your local network and internet provider to your server. It does not make you anonymous: your hosting account, your payments and what you log in to can still be linked to you. If privacy is the goal, read how we handle data on our anonymous VPS page.

Your own VPN is less about hiding and more about control: one tunnel, one address, keys that only you hold.

Step 2

Choose a location and a server size

For speed, pick the city closest to you. To appear in a particular country, pick a city there. Either way, the distance between you and the server adds a little delay to everything you open.

  • Size: WireGuard runs inside the Linux kernel and uses very little. One vCPU and 1 GB of RAM handle a household or a small team comfortably.
  • Traffic: all your browsing passes through the server, so look at the monthly traffic allowance each plan shows at checkout. Video calls and streaming use the most.
  • System: a current Ubuntu LTS or Debian release. Their kernels already include WireGuard, so there is nothing to compile.

Tip: If you travel, you can run more than one small server in different countries and switch between them in the WireGuard app.

Want WireGuard ready when the server starts? Our plans with the WireGuard one-click install start at $6.39/mo billed yearly, in 12 cities across 12 countries. To compare every size, see the VPS pricing page.

Part 2: Install WireGuard

Pick one route: let the checkout install WireGuard for you, or install it yourself on any Ubuntu or Debian server.

Step 3

Option A: get WireGuard pre-installed on VPSPulse

If you would rather not set it up by hand, choose WireGuard at checkout. The server is delivered with WireGuard installed on Ubuntu 22.04.

  1. Pick a plan and a city

    Open the checkout with the button below and choose a size and the city your traffic should exit from. There are 12 cities in 12 countries to choose from.

  2. Pay and wait a few minutes

    Pay by card, PayPal, bank transfer or cryptocurrency, monthly or yearly (yearly saves 20%). You receive the server's dedicated IPv4 address and login details when it is ready.

  3. Log in and look at the setup

    Connect over SSH and run sudo wg show to see the WireGuard interface the install created, with its port and address range.

  4. Add your devices

    Continue with Part 3. Use the interface name, port and addresses that sudo wg show and the files in /etc/wireguard list, if they differ from the examples in this guide.

Deploy WireGuard

From $6.39/mo billed yearly

Other tools install the same way. Browse the full list of one-click apps.

Step 4

Option B: install WireGuard by hand

Log in to your server over SSH as a user with sudo rights. If this is a brand new server, our guide on how to set up a VPS covers the first login, updates and SSH keys. Then update the package list and install WireGuard, plus qrencode to show configurations as QR codes for your phone.

sudo apt updatesudo apt install -y wireguard qrencode

The wireguard package brings the wg and wg-quick tools. The tunnel itself runs in the kernel, which has included WireGuard since Linux 5.6.

Step 5

Create the server's key pair

WireGuard identifies every machine by a key pair: a private key that never leaves it and a public key you share with the other side. Create the server's pair in /etc/wireguard, readable only by root:

sudo sh -c 'umask 077; wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key'sudo cat /etc/wireguard/server_private.keysudo cat /etc/wireguard/server_public.key

Watch out: The private key is the server's identity. Never paste it into a chat, a ticket or a device configuration: devices only ever need the server's public key.

Step 6

Write the server configuration

First find the name of the network interface that connects the server to the internet. It is often eth0 or ens3:

ip -o -4 route show to default | awk '{print $5}'

Open a new file with sudo nano /etc/wireguard/wg0.conf and paste the lines below. Replace SERVER_PRIVATE_KEY with the private key from the previous step, and both eth0 with your interface name if it is different.

/etc/wireguard/wg0.conf
[Interface]Address = 10.8.0.1/24ListenPort = 51820PrivateKey = SERVER_PRIVATE_KEYPostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADEPostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
What each line in the server configuration does
LineWhat it does
AddressThe server's address inside the VPN. 10.8.0.1/24 leaves 10.8.0.2 to 10.8.0.254 for your devices.
ListenPortThe UDP port WireGuard listens on. 51820 is the usual choice; any free port works.
PrivateKeyThe server's private key.
PostUpRuns when the tunnel starts: lets VPN traffic through and gives it the server's public address on the way out (NAT).
PostDownRemoves those rules again when the tunnel stops.

Step 7

Turn on forwarding and open the port

By default Linux does not pass traffic from one network interface to another. Turn that on permanently:

echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-wireguard.confsudo sysctl --system

If you use the UFW firewall, open the WireGuard port and allow VPN traffic to leave through your internet interface (again, replace eth0 if yours differs):

sudo ufw allow 51820/udpsudo ufw route allow in on wg0 out on eth0sudo ufw status

Good to know: Keep SSH open before you turn UFW on (sudo ufw allow OpenSSH), or you can lock yourself out of the server.

Step 8

Start WireGuard

Start the tunnel and make it come back after every reboot:

sudo systemctl enable --now wg-quick@wg0sudo wg show

sudo wg show lists the wg0 interface with its public key and listening port. There are no peers yet: you add your devices in the next part.

Part 3: Connect your devices

Each laptop, phone or tablet gets its own key pair and its own address inside the VPN. The steps below add a laptop; repeat them for every device with the next free address.

Step 9

Create a key pair for the device

The quickest way is to create the device's keys on the server, in a folder only root can read:

sudo sh -c 'umask 077; mkdir -p /etc/wireguard/clients; wg genkey | tee /etc/wireguard/clients/laptop.key | wg pubkey > /etc/wireguard/clients/laptop.pub'sudo cat /etc/wireguard/clients/laptop.pub

Tip: For the strictest setup, let the WireGuard app create the key pair on the device instead, and copy only its public key to the server. The private key then never exists anywhere else.

Step 10

Add the device to the server

Tell the server about the device: its public key and the one address it may use. Replace LAPTOP_PUBLIC_KEY with the key you just printed. The last line loads the change without dropping devices that are already connected.

sudo tee -a /etc/wireguard/wg0.conf > /dev/null <<'EOF' [Peer]# laptopPublicKey = LAPTOP_PUBLIC_KEYAllowedIPs = 10.8.0.2/32EOFsudo bash -c 'wg syncconf wg0 <(wg-quick strip wg0)'

Each device needs its own [Peer] block with a different address: 10.8.0.3/32 for the phone, 10.8.0.4/32 for the next one, and so on.

Step 11

Write the device's configuration

Create sudo nano /etc/wireguard/clients/laptop.conf with the lines below. Fill in the laptop's private key, the server's public key and the server's public IPv4 address.

laptop.conf
[Interface]PrivateKey = LAPTOP_PRIVATE_KEYAddress = 10.8.0.2/32DNS = 1.1.1.1, 9.9.9.9 [Peer]PublicKey = SERVER_PUBLIC_KEYEndpoint = YOUR_SERVER_IP:51820AllowedIPs = 0.0.0.0/0, ::/0PersistentKeepalive = 25
What each line in the device configuration does
LineWhat it does
AddressThe device's own address inside the VPN; it must match the AllowedIPs you gave it on the server.
DNSThe name servers the device uses while connected, so lookups go through the tunnel too.
EndpointWhere to reach the server: its public IP address and the WireGuard port.
AllowedIPsWhich traffic goes into the tunnel. 0.0.0.0/0, ::/0 sends everything, so IPv6 cannot slip around the VPN.
PersistentKeepaliveSends a tiny packet every 25 seconds, so routers and mobile networks keep the connection open.

Step 12

Import it on your laptop or phone

  • Windows, macOS and Linux: install the official WireGuard app, choose to import a tunnel from a file and pick laptop.conf. Copy the file over a secure channel, for example with scp.
  • Android and iOS: install the WireGuard app, tap the add button and scan a QR code shown in your SSH window with the command below.
sudo qrencode -t ansiutf8 < /etc/wireguard/clients/laptop.conf

Tip: Once a device is set up, delete its private key and configuration from the server with sudo rm /etc/wireguard/clients/laptop.key /etc/wireguard/clients/laptop.conf. The server only needs the public key.

Step 13

Check that your traffic goes through the VPN

Switch the tunnel on in the app, then check both ends:

  • On the server, sudo wg show lists the device with a recent latest handshake and growing transfer numbers.
  • On the device, open any "what is my IP" page: it should show your server's IP address and location, not your own.
sudo wg show

Part 4: Keep it secure and running

A VPN server needs little care, but these habits keep it safe and quick to fix.

Step 14

Remove a lost or old device

If a phone is lost or a laptop is retired, remove its key at once. The first command takes it off the running tunnel; then delete its [Peer] block from the file so it stays gone after a restart.

sudo wg set wg0 peer LAPTOP_PUBLIC_KEY removesudo nano /etc/wireguard/wg0.conf

Step 15

Keep the server updated and backed up

  • Install security updates automatically: sudo apt install -y unattended-upgrades, then sudo dpkg-reconfigure -plow unattended-upgrades.
  • Log in with SSH keys and turn off password logins. Our VPS setup guide shows how.
  • Back up /etc/wireguard to a safe place off the server. If you ever reinstall the system, putting it back saves you from setting up every device again.
sudo tar czf ~/wireguard-backup.tar.gz -C /etc wireguard

Watch out: That backup contains the server's private key. Store it encrypted and never share it.

Step 16

Fix common problems

Common WireGuard problems and how to fix them
What you seeWhat to check
No "latest handshake" in sudo wg showUDP port 51820 is not open, the Endpoint address or port is wrong, or the keys are swapped: each side needs the other side's public key.
Handshake works, but no websites loadForwarding is off (sysctl net.ipv4.ip_forward should print 1), the interface name in PostUp is wrong, or the UFW route rule is missing.
Some sites load, others hangPackets are too large for a network on the way. Add MTU = 1380 under [Interface] in the device configuration.
Names do not resolveCheck the DNS line in the device configuration, or try another resolver.
Works on Wi-Fi, not on mobile dataSome networks block unusual UDP ports. Change ListenPort to 443, open 443/udp in the firewall and update the Endpoint on your devices.

Why run your VPN on a VPSPulse server

WireGuard pre-installed

Pick WireGuard at checkout and the server is delivered with it installed on Ubuntu 22.04, ready in minutes.

12 cities to exit from

Choose where your traffic leaves the tunnel, in 12 countries, and add a second location any time.

Pay the way you prefer

Card, PayPal, bank transfer or cryptocurrency, monthly or yearly.

Full root access

A dedicated IPv4 address and full control of the system, so your VPN works exactly the way you set it up.

FAQ

WireGuard VPN: frequently asked questions

Is WireGuard better than OpenVPN?

For most personal VPNs, yes. WireGuard has far less code, uses modern encryption, connects in a moment and is usually faster, especially on phones. OpenVPN can still be useful where only TCP connections get through, because it can run over TCP port 443.

How many devices can I connect?

As many as you add. Each device needs its own key pair and its own address. The `10.8.0.0/24` range in this guide leaves room for 253 devices, and a small server handles a household or a small team without trouble.

Does my own VPN make me anonymous?

No. It hides your traffic from the local network and your internet provider, and websites see the server's address instead of yours. But your hosting account, your payments and the accounts you log in to can still be linked to you.

Which port does WireGuard use?

WireGuard uses UDP. Port 51820 is the usual choice, but any free port works. Open the same port in the server's firewall and use it in the `Endpoint` line on your devices.

How much RAM and CPU does a WireGuard VPN need?

Very little. WireGuard runs inside the Linux kernel, so one vCPU and 1 GB of RAM are plenty for a few users. The monthly traffic allowance matters more than the CPU, because all your browsing passes through the server.

Can I use the same server for other things?

Yes. It is a normal Linux server with full root access, so you can run a website or other apps on it as well. Just keep the VPN's address range from clashing with any other network you use.

What happens if I reinstall the server?

A reinstall erases the disk, including the server's keys, so your devices stop connecting. Restore your backup of `/etc/wireguard` and the same device configurations work again; without a backup, set up the server and devices again with this guide.

Is running my own VPN legal?

In most countries, yes, although a few restrict VPNs. You are responsible for following the laws where you and your server are, and our Terms of Service do not allow illegal use.

Sources: the WireGuard quick start and the manual pages for wg and wg-quick, checked against Ubuntu 24.04 and Debian 12.

Next: lock down SSH with our guide to setting up a VPS, or compare VPS locations to choose where your VPN exits.

Skip the setup: get WireGuard pre-installed from $6.39/mo

We install WireGuard on Ubuntu 22.04 for you, on a server with full root access and a dedicated IPv4 address, in 12 cities across 12 countries.

Paying with cryptocurrency? See how it works on our crypto VPS page.