WireGuard VPN setup on your own Linux server

By Noiz / 19th October 2026 | 7 min

WireGuard is a free, open-source VPN that has been built into the Linux kernel since 2020. A WireGuard VPN on a Linux server of your own takes a handful of commands and two short configuration files to give your laptop and phone an encrypted tunnel to that server. Beyond protecting you on public Wi-Fi, the tunnel lets you keep private services, such as a mail server's administration pages, reachable only by your own devices.

In short

  • WireGuard is small and built in. Its Linux implementation is under 4,000 lines of code and has been in the Linux kernel since version 5.6, with clients for Windows, macOS, iOS, Android and the BSDs.
  • You need a Linux server you control. It needs a public IP address and root access, already secured with SSH keys and a firewall.
  • Set-up takes five steps. Install WireGuard, create keys, write the server and device configurations, then open the UDP port and start the tunnel.
  • A VPN lets you close doors. A mail server's administration pages need not be open to everyone, and Mailcow documents the building blocks to restrict them.
  • WireGuard is not the only choice. A firewall appliance, headscale, IPsec and the Noiz VPN add-on suit other situations.

What is a WireGuard VPN?

A VPN (virtual private network) creates an encrypted connection between two machines over the internet. Everything sent through it is unreadable to the networks in between.

WireGuard does this with a small, modern design:

  • Modern cryptography. It uses the Noise protocol framework with Curve25519, ChaCha20-Poly1305 and BLAKE2s, and rotates its session keys every few minutes.
  • A small codebase. Its Linux implementation is under 4,000 lines of code, which makes it practical to audit.
  • Quiet by default. It does not answer packets from senders it does not recognise, so a scan of the server does not reveal it.
  • Everywhere. It is in the Linux kernel since version 5.6, with clients for Windows, macOS, iOS, Android and the BSDs.

Each device is identified by a public key, much like an SSH key. Each side lists the other's public key and the addresses it may use, a setting called AllowedIPs, which acts as both the route and the access list.

What do you need to set up a WireGuard VPN?

You need three things:

  • A Linux server with a public IP address and root access, such as a Noiz Cloud server running Ubuntu or Debian.
  • The server already secured with SSH keys and a firewall. The usual first steps are SSH keys, a non-root user and a firewall that allows only what you use.
  • The WireGuard app on each device you want to connect.

How do you set up WireGuard on your own server?

The job has five steps. This is the shape of the job, so you know what is involved. Test each step before relying on it.

1. Install WireGuard

On Debian and Ubuntu:

sudo apt install wireguard

2. Create a key pair on the server and on each device

wg genkey | tee privatekey | wg pubkey > publickey

The private key never leaves the machine it was made on. Only public keys are exchanged. The phone and desktop apps generate their own keys for you.

3. Write the server's configuration

The server's file, /etc/wireguard/wg0.conf, names its own private key, its address inside the VPN and the port it listens on, then one [Peer] section per device:

[Interface]
PrivateKey = <server private key>
Address = 10.8.0.1/24
ListenPort = 51820

[Peer]
PublicKey = <laptop public key>
AllowedIPs = 10.8.0.2/32

Port 51820 is the usual choice, not a built-in default; WireGuard picks a random port if you do not set one.

4. Write each device's configuration

The device's file mirrors the server's: its own private key and address, then the server's public key, the server's public address and port as the endpoint, and the addresses to send through the tunnel. The AllowedIPs setting decides how much goes through:

AllowedIPs What goes through the tunnel
The VPN range Only VPN traffic
0.0.0.0/0 Everything, which is what you want on public Wi-Fi

5. Open the port and start the tunnel

Allow the chosen UDP port in the server's firewall, then start WireGuard and enable it at boot:

sudo ufw allow 51820/udp
sudo systemctl enable --now wg-quick@wg0

If devices are to send all their traffic through the server, the server also needs IP forwarding switched on, in a file under /etc/sysctl.d/, and a NAT rule. On Debian 13 the old /etc/sysctl.conf file is no longer read.

A VPN runs both ways. A device on the VPN can reach the server, and the server can reach the device. Firewall the WireGuard interface as carefully as the public one.

How do you keep a private mail server off the open internet?

Use the VPN to close doors. A mail server has to keep port 25 open to receive mail from the rest of the world, but its administration pages, and even webmail and IMAP if your users are all on the VPN, need not be open to everyone.

Mailcow documents the building blocks. Mailcow, the open-source mail server, runs in Docker. Its documentation warns that ordinary host firewall rules on the INPUT chain do not restrict it, because Docker manages its own rules, and that restrictions belong in the DOCKER-USER chain. Mailcow can also bind its services to a chosen IP address. Combined with WireGuard, that lets you make the administration interface answer only on the VPN. Mailcow documents these building blocks rather than a ready recipe, so plan and test the result.

When should you use something else?

Other tools suit other situations:

Your situation Option What it offers
An office that wants the VPN at the edge of its network A firewall appliance such as OPNsense An open-source firewall that has included WireGuard since version 24.1
Many devices, changing often headscale An open-source, self-hosted coordination server for Tailscale clients, which manages keys and addresses across many devices for you
An enterprise policy IPsec The UK National Cyber Security Centre prefers IPsec for enterprise VPNs and says WireGuard has yet to be proven in enterprise settings
No server to run The Noiz VPN add-on An encrypted tunnel from each device, set up and supported by Noiz, with nothing for you to configure

For a small business or a single server, WireGuard's simplicity is a strength.

Where does Noiz fit?

A Noiz Cloud server gives you the root access and Linux system WireGuard needs. If you would rather Noiz did the Linux side, Linux administration is quoted by the hour, once off or maintained monthly.

Read next:

If you run a mail server and want its private pages reachable only from your own devices, get in touch.

Sources

  • WireGuard: https://www.wireguard.com/
  • WireGuard, protocol and cryptography: https://www.wireguard.com/protocol/
  • WireGuard, quick start: https://www.wireguard.com/quickstart/
  • WireGuard, installation: https://www.wireguard.com/install/
  • WireGuard, known limitations: https://www.wireguard.com/known-limitations/
  • WireGuard whitepaper: https://www.wireguard.com/papers/wireguard.pdf
  • wg(8) manual page: https://manpages.debian.org/bookworm/wireguard-tools/wg.8.en.html
  • wg-quick(8) manual page: https://manpages.debian.org/bookworm/wireguard-tools/wg-quick.8.en.html
  • Ubuntu Server, introduction to WireGuard VPN: https://ubuntu.com/server/docs/explanation/intro-to/wireguard-vpn/
  • Ubuntu Server, WireGuard VPN as the default gateway: https://ubuntu.com/server/docs/how-to/wireguard-vpn/vpn-as-the-default-gateway/
  • Ubuntu Server, WireGuard security tips: https://ubuntu.com/server/docs/how-to/wireguard-vpn/security-tips/
  • Debian 13 release notes, issues: https://www.debian.org/releases/trixie/release-notes/issues.html
  • Mailcow, prerequisites and firewall: https://docs.mailcow.email/getstarted/prerequisite-system/
  • Mailcow, IP bindings: https://docs.mailcow.email/post_installation/firststeps-ip_bindings/
  • OPNsense 24.1 release notes: https://docs.opnsense.org/releases/CE_24.1.html
  • headscale: https://github.com/juanfont/headscale
  • NCSC, virtual private networks: https://www.ncsc.gov.uk/collection/device-security-guidance/infrastructure/virtual-private-networks

Note: while some of this content was produced with the help of AI, the final editing has been done by a real human being.