BestVPSHosting.netVPS hosting compared RU

Updated

Blog · Tutorials

How to make your own VPN with WireGuard on a VPS

Short answer: How to make your own VPN: rent a small Linux VPS (a 1 GB plan has a median price of $6.04 a month in our data), install WireGuard from the Ubuntu or Debian repositories, generate keys, write /etc/wireguard/wg0.conf, enable IP forwarding and NAT, open UDP 51820, then import the client config or scan its QR code.

This guide shows how to make your own VPN on a small Linux VPS with WireGuard, step by step: keys, the wg0.conf files for server and client, IP forwarding, NAT, the firewall, client apps, QR codes for phones and a leak test. It follows the official WireGuard quick start and the Ubuntu Server documentation, works on Ubuntu 24.04 LTS, Ubuntu 26.04 LTS, Debian 12 and Debian 13, and takes about 40 minutes.

What your own VPN does and does not give you

A self-hosted VPN encrypts everything between your devices and your server. The café Wi-Fi, the hotel network or your home ISP sees only UDP packets going to one IP address. Websites see the VPS's address and location instead of yours.

It does not make you anonymous:

  • The VPS is rented in your name and paid with your card, so the IP address leads back to you.
  • Nobody else shares that IP, so your traffic is easier to single out than on a commercial VPN where many users share each address.
  • The hosting provider can see traffic leaving the server and answers abuse complaints and legal requests in its own country.
  • Sites that block data-center IP ranges will block your VPN too.

Treat your own VPN as a privacy tool for untrusted networks and a way to get a fixed exit IP in a chosen country.

What you need to make a VPN on a VPS

  • A Linux VPS running Ubuntu 24.04 LTS, Ubuntu 26.04 LTS, Debian 12 or Debian 13, with root or sudo access over SSH.
  • KVM virtualization. WireGuard runs in the kernel (built in since Linux 5.6). On a container-based VPS such as OpenVZ or LXC you cannot load kernel modules yourself, so it only works if the host already provides it. A KVM VPS avoids the question.
  • A public IPv4 address. Some of the cheapest plans charge extra for one or are IPv6-only.
  • A data center in the country you want to appear from. Distance also adds latency.

WireGuard publishes no CPU, RAM or disk minimums, so any small plan runs it. A good WireGuard VPS is decided by traffic allowance, port speed, location and terms that allow VPN use. These are the top five plans in our VPS for VPN server ranking as of November 30, 2026, which ranks small plans by country coverage and traffic:

#ProviderPlanSpecsPrice / monthLocations
1LikeVPSLite1 vCPU, 1 GB RAM, 25 GB NVMe, unmetered traffic$9.5026
2netcupVPS piko G11s1 vCPU, 1 GB RAM, 30 GB SSD, unmetered traffic$2.07
prepaid annually or longer
5
3SolidVPS (formerly SolidSEOVPS)SBudgetSSD4G2 vCPU, 4 GB RAM, 40 GB SSD, 2 TB traffic$3.3321
4OVHcloud VPSVPS-12 vCPU, 4 GB RAM, 40 GB NVMe, unmetered traffic$4.5411
5RUVDSStart1 vCPU, 512 MB RAM, 10 GB HDD, unmetered traffic$1.7821

Top 5 of 196 providers in our Best VPS for a VPN Server (WireGuard, OpenVPN) ranking, updated November 30, 2026. Each plan meets the software's published minimum requirements.

Step 1: Rent a VPS and update it

  1. Order the VPS with Ubuntu or Debian and, if the panel offers it, add your SSH public key.
  2. Log in as root (or a sudo user) with ssh [email protected], using your server's IP. On Windows, our PuTTY guide covers the first login and SSH keys.
  3. Install updates:
apt update && apt upgrade -y

Reboot if the upgrade installed a new kernel. The rest of this guide runs as root; prefix commands with sudo if you log in as a normal user.

Step 2: Install WireGuard

WireGuard is in the standard repositories of every current Ubuntu and Debian release. Install it together with qrencode, which you will use for phones:

apt install -y wireguard qrencode

The wireguard package pulls in wireguard-tools, which provides the wg and wg-quick commands.

Step 3: Generate the key pairs

Each side of a WireGuard tunnel has a private key and a public key. The server needs its own pair, and every device needs a separate one. These commands follow the official quick start; umask 077 makes the key files readable by root only:

cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee laptop.key | wg pubkey > laptop.pub
wg genkey | tee phone.key | wg pubkey > phone.pub

Making device keys on the server lets you hand out finished configs and QR codes. The more private option is to let each WireGuard app create its own key pair and copy only the public key to the server.

Step 4: Write the server config

First find the name of the server's public network interface:

ip route show default
default via 203.0.113.1 dev eth0 proto static

The word after dev is the interface (eth0 here; ens3 and enp1s0 are also common). Then write /etc/wireguard/wg0.conf. The heredoc copies the keys into the file for you; replace eth0 if your interface has another name:

cat > /etc/wireguard/wg0.conf <<EOF
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = $(cat /etc/wireguard/server.key)
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

[Peer]
# laptop
PublicKey = $(cat /etc/wireguard/laptop.pub)
AllowedIPs = 10.8.0.2/32

[Peer]
# phone
PublicKey = $(cat /etc/wireguard/phone.pub)
AllowedIPs = 10.8.0.3/32
EOF
chmod 600 /etc/wireguard/wg0.conf

Address gives the server the first address of a private tunnel network, 10.8.0.0/24. ListenPort is the UDP port clients connect to; Ubuntu's documentation notes there is no standard WireGuard port, and 51820 is the value in the official examples. Each [Peer] is one device, and its AllowedIPs is the single tunnel address it may use.

Step 5: Turn on IP forwarding

By default Linux does not route packets between interfaces, so traffic from the tunnel would stop at the server. Enable forwarding in a drop-in file, as the Ubuntu documentation does:

echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/70-wireguard-routing.conf
sysctl -p /etc/sysctl.d/70-wireguard-routing.conf
net.ipv4.ip_forward = 1

The file under /etc/sysctl.d/ keeps the setting after reboots.

Step 6: Add NAT with iptables or nftables

Your devices use private 10.8.0.x addresses, so the server has to rewrite their traffic to its own public IP (masquerading). Pick one of these two methods.

Option A: iptables

The PostUp and PostDown lines in Step 4 add the masquerade rule when the tunnel starts and remove it when it stops. It is the same rule the Ubuntu documentation uses. Ubuntu ships the iptables command; on a minimal Debian install, add it with apt install -y iptables.

Option B: nftables

Debian uses nftables as its default firewall framework. If you prefer it, delete the two PostUp/PostDown lines from wg0.conf and add this table to the end of /etc/nftables.conf:

table ip wg_nat {
    chain postrouting {
        type nat hook postrouting priority srcnat; policy accept;
        ip saddr 10.8.0.0/24 oifname "eth0" masquerade
    }
}

Then install the service if it is missing, load the rules and make them permanent:

apt install -y nftables
systemctl enable --now nftables
nft list table ip wg_nat

Debian's stock /etc/nftables.conf starts with flush ruleset, which wipes rules that other tools add, UFW's included. Don't combine this option with UFW; filter traffic in the same file or in the provider's cloud firewall instead.

Step 7: Open the UDP port in the firewall

Two firewalls can block the tunnel: the one on the server and the one in your provider's control panel.

On the server, if you use UFW with option A (common on Ubuntu), allow SSH first so you don't lock yourself out, then the WireGuard port, then forwarding from the tunnel to the internet:

ufw allow OpenSSH
ufw allow 51820/udp
ufw route allow in on wg0 out on eth0
ufw enable

UFW drops forwarded traffic by default, so without the route allow line clients connect but cannot reach the internet. In the provider's panel, check for a cloud firewall or security group and allow inbound UDP 51820 there too.

Step 8: Start the tunnel

wg-quick reads wg0.conf, creates the interface and runs the PostUp lines. The systemd unit starts it now and on every boot:

systemctl enable --now wg-quick@wg0
wg show
interface: wg0
  public key: (server public key)
  private key: (hidden)
  listening port: 51820

peer: (laptop public key)
  allowed ips: 10.8.0.2/32

Peers show no endpoint or handshake until a device connects.

Step 9: Set up the client apps

Each device needs a config that mirrors the server's. Create the laptop's, replacing 203.0.113.10 with your VPS's IP:

cat > /etc/wireguard/laptop.conf <<EOF
[Interface]
PrivateKey = $(cat /etc/wireguard/laptop.key)
Address = 10.8.0.2/32
DNS = 9.9.9.9

[Peer]
PublicKey = $(cat /etc/wireguard/server.pub)
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
EOF

Create phone.conf the same way with phone.key and Address = 10.8.0.3/32, then lock both files with chmod 600 /etc/wireguard/*.conf.

  • AllowedIPs = 0.0.0.0/0, ::/0 sends all IPv4 and IPv6 traffic through the tunnel. Including ::/0 matters even if the server has no IPv6: otherwise a device on an IPv6 network sends that traffic around the VPN.
  • DNS sets the resolver while the tunnel is up. Use any resolver you trust; the example uses Quad9.
  • PersistentKeepalive = 25 keeps the connection open through home routers and mobile NAT. The quick start suggests 25 seconds as a sensible interval.

Computers

Official WireGuard apps exist for Windows, macOS, iOS and Android, and Linux uses wireguard-tools; all are listed on the WireGuard install page. Copy laptop.conf to the computer (with scp or PSCP), open the app, choose Import tunnel(s) from file and click Activate. On a Linux computer, save it as /etc/wireguard/wg0.conf and run wg-quick up wg0.

Phones: scan a QR code

Print the phone config as a QR code in the SSH window:

qrencode -t ansiutf8 < /etc/wireguard/phone.conf

In the WireGuard app, tap +, choose the QR code option and scan the terminal. Once the phone shows the tunnel, delete phone.conf and phone.key from the server; they are a working credential.

Step 10: Test for IP, DNS and IPv6 leaks

  1. On the server, run wg show. Each connected device shows a latest handshake a few seconds or minutes old, and its transfer counters grow as you browse.
  2. On the device, open any what-is-my-IP page. It should show the VPS's address and country.
  3. Run a DNS leak test such as dnsleaktest.com, which the Ubuntu documentation also suggests. It should list only the resolver you set (Quad9 in the example), not your ISP's.
  4. Check IPv6 with an IPv6 test page. You should see either no IPv6 address or the server's, never your home network's.

To stop traffic from leaking when the tunnel drops, turn on the kill switch: in the Windows app, Block untunneled traffic (kill-switch) in the tunnel editor; on Android, Always-on VPN and Block connections without VPN in the system VPN settings.

How to add more devices

Every device gets its own key pair, its own tunnel address and its own [Peer] block. Never import one config on two devices at the same time: they share a key, so the server keeps switching between them.

  1. Generate keys: wg genkey | tee tablet.key | wg pubkey > tablet.pub.
  2. Append a [Peer] with tablet.pub and AllowedIPs = 10.8.0.4/32 to wg0.conf.
  3. Apply the change without disconnecting anyone:
wg syncconf wg0 <(wg-quick strip wg0)
  1. Write tablet.conf as in Step 9 with Address = 10.8.0.4/32.

To revoke a lost device, delete its [Peer] block and run the same syncconf command, or remove it live with wg set wg0 peer <public-key> remove.

Troubleshooting a WireGuard VPS

No handshake at all

wg show lists no latest handshake. UDP 51820 is blocked (UFW, the provider's cloud firewall or the network you are on), the Endpoint IP or port is wrong, or a key went into the wrong place: each side needs the other's public key, never a private one. Some guest networks let only common ports out; moving ListenPort and Endpoint to UDP 443 can help.

Connected, but no websites load

The handshake works, so forwarding or NAT is missing. sysctl net.ipv4.ip_forward must print 1, the NAT rule must name the right interface, and with UFW the route allow rule must exist. If IP addresses load but names don't, the DNS line is missing or the resolver is unreachable.

This appears when the tunnel starts on a kernel without WireGuard support, typical of container-based VPS plans. Move to a KVM plan.

Some sites hang while others load

That points to an MTU problem on networks with extra encapsulation. Add MTU = 1280 to the client's [Interface] section and reconnect.

Can I use a VPN in a cloud VPS server?

Yes, in both senses of the question. Running a VPN server on a cloud VPS, as in this guide, is a standard use as long as the provider's acceptable use policy allows it (see below).

Running a VPN client on a VPS, for example to connect the server to a commercial VPN, also works, with one trap. A full-tunnel client replaces the server's default route, so replies to your SSH session go into the tunnel and your connection drops. Before you try, keep the provider's web console open, and limit the client's routes or exclude your own IP from the tunnel.

Other ways to make your own VPN

There is more than one answer to how to make a VPN. WireGuard by hand gives you the most control with the fewest moving parts; these are the other common routes, as their official pages describe them:

Route What it is Where the server runs Things to know
OpenVPN TLS-based VPN; Access Server adds a web admin panel VPS or own hardware Access Server defaults to UDP 1194 and TCP 443, plus TCP 943 for its web UI; without a subscription it allows two simultaneous connections; OpenVPN advises starting with 1 GB RAM
Tailscale WireGuard-based network of your devices, coordinated by Tailscale's control server Any device; a VPS can act as an exit node An exit node carries all internet traffic; it needs IP forwarding and admin approval
Headscale Open-source, self-hosted implementation of the Tailscale control server Your VPS Runs a single tailnet; not affiliated with Tailscale Inc.; uses the Tailscale clients
Router-based VPN server on a home router or a machine behind it Home Needs a reachable public IP (dynamic DNS if it changes); you exit from your home connection, not a new location
Outline Outline Manager desktop app sets up a server and shares access with users A cloud provider or your own server ("Set up Outline anywhere") Point-and-click setup
Algo Ansible scripts for a personal WireGuard and IPsec (IKEv2) VPN Supported clouds, or your own Ubuntu server Does not claim to provide anonymity or censorship avoidance; no OpenVPN
PiVPN "The Simplest VPN installer, designed for Raspberry Pi"; WireGuard or OpenVPN Raspberry Pi OS, Debian or Ubuntu One-line installer from install.pivpn.io; maintained on a best-effort basis

The scripts save typing, but updates, the firewall and the provider's rules stay your job.

Running a VPN for your own use is legal in the US and most other countries, and it does not change what is legal: the laws where you are and where the server sits still apply. A few governments restrict VPNs or allow only approved services, so check local rules before relying on one abroad.

The provider's acceptable use policy (AUP) is the more practical limit. Read it before you pay. As an example, the "Proxies and VPNs" section of the V.PS AUP permits private proxies, prohibits open or anonymous proxies of any kind and Tor exit nodes, and the policy makes the customer liable for all use of the service. Other providers draw the line elsewhere, so search the policy for "VPN", "proxy" and "Tor", and ask support if it is unclear. If you share your VPN with friends, abuse reports about their traffic land on your account.

What does it cost to make your own VPN?

The software is free; the VPS is the only cost. As of November 30, 2026, the cheapest plan in our data with at least 512 MB of RAM costs $0.48 a month. These are the five cheapest plans with 1 GB of RAM, one per provider:

#ProviderPlanSpecsPrice / month
1ScalewaySTARDUST1-S1 vCPU, 1 GB RAM, 10 GB SSD, unmetered traffic$0.48
IPv4 extra
2V.PSAMS Nano1 vCPU, 1 GB RAM, 15 GB SSD, 1 TB traffic$0.92
prepaid annually or longer
3HostodoEPYC-1G1C16GN1 vCPU, 1 GB RAM, 20 GB NVMe, 3 TB traffic$1.67
prepaid annually or longer
4HosteonsGigabit KVM VPS 11 vCPU, 1 GB RAM, 10 GB SSD, 1 TB traffic$1.75
prepaid annually or longer
5netcupVPS piko G11s1 vCPU, 1 GB RAM, 30 GB SSD, unmetered traffic$2.07
prepaid annually or longer

Check the notes in the price column. The lowest prices can exclude an IPv4 address (which this setup needs) or require a year paid up front.

Traffic decides more than price. Every byte you download through the VPN passes through the server, so the monthly transfer allowance caps how much you can stream. 79 of 199 providers in our data offer unmetered VPS plans, and our explainer on bandwidth vs port speed shows how far a given allowance goes.

Which route should you choose?

For one person with a laptop and a phone, a plain WireGuard server on a small KVM plan is the shortest path: one config file, one UDP port and no daemon beyond the kernel module. Tailscale or Headscale suit reaching your own machines from anywhere, OpenVPN Access Server fits if you need a web admin panel or TCP 443, and Algo or PiVPN write the configs for you. Choose the server location first, then compare plans in the VPS for VPN ranking; our VPS vs VPN explainer covers the basics.

Frequently asked questions

What port does WireGuard use?

WireGuard has no fixed port. The official quick start uses UDP 51820 in its examples, and that has become the usual choice, but any free UDP port works as long as the server's ListenPort, the client's Endpoint and every firewall rule agree. WireGuard does not run over TCP.

How many devices can connect to one WireGuard server?

WireGuard publishes no limit. Each device needs its own key pair and its own tunnel address, so a 10.8.0.0/24 network leaves room for 253 clients. In practice the plan's port speed and monthly transfer allowance run out long before the software does.

Is 512 MB of RAM enough for a WireGuard VPN?

Yes. The WireGuard project publishes no CPU, RAM or disk minimums, and the tunnel runs inside the Linux kernel. A 512 MB or 1 GB plan is enough for a handful of devices; traffic allowance and location matter more. Our VPS for VPN ranking filters plans on that basis.

Is your own VPN safer than a commercial VPN?

It is a different trade-off. You stop trusting a VPN company and start trusting your VPS provider, and you get an IP that only you use, which is easier to link to you than a shared one. You also take over patching. For privacy on public Wi-Fi either works.

Is a VPS the same as a VPN?

No. A VPS is a rented virtual server that can run any software; a VPN is an encrypted tunnel. This guide runs VPN software on a VPS, so the server becomes your private exit point. Our explainer on VPS vs VPN covers the difference.

Do I need to update a self-hosted VPN?

Yes. WireGuard lives in the Linux kernel, so its fixes arrive with kernel updates, and the rest of the server needs patches too. On Ubuntu and Debian, unattended-upgrades installs security updates automatically; reboot after kernel updates. See our VPS security checklist.

Sources

Commands and requirements were checked against these pages on November 30, 2026. Prices and plan tables in the article come from our provider data, updated the same day.

  1. WireGuard: Quick Start
  2. WireGuard: Installation (official clients)
  3. Ubuntu Server docs: Using the VPN as the default gateway
  4. Ubuntu Server docs: WireGuard VPN peer-to-site (on router)
  5. OpenVPN Access Server: system requirements
  6. Tailscale docs: Exit nodes (route all traffic)
  7. Headscale README (juanfont/headscale)
  8. Algo VPN README (trailofbits/algo)
  9. PiVPN README
  10. Outline: server setup with Outline Manager
  11. V.PS Acceptable Use Policy