Set up a VPN on Linux

Short answer: you have two main routes — your provider’s Linux app, or the distribution-neutral WireGuard tools: import the provider’s WireGuard config and bring it up with wg-quick. Desktop users can often manage the same connection through NetworkManager instead. Kill switches are done with firewall rules, and you should verify the result with a leak test.

An honest note about this guide: the examples below are Ubuntu-style (apt, systemd, the standard wg-quick tool). Other distributions use different package managers and service names, and desktop environments differ in how they expose VPN settings. The concepts are identical everywhere; check your distribution’s documentation for the exact commands.

Route 1: your provider’s official app

Most privacy-focused providers (Proton VPN, Mullvad, IVPN and others) ship Linux apps or repositories. Install the package, sign in, connect. This is the easiest route and the only one that gives you the provider’s obfuscation options and in-app kill switch on Linux. The limits:

Route 2: wg-quick and the WireGuard config files

Nearly every provider that supports WireGuard will generate a configuration file you can download and use with the standard wireguard-tools package — no app needed. The wg-quick(8) tool that ships with wireguard-tools automates bringing a WireGuard interface up and down, sets addresses, routes and DNS from the config file, and can run extra commands on connect and disconnect.

  1. Install the tools: sudo apt install wireguard on Ubuntu-style systems (WireGuard is already in the Linux kernel).
  2. Download the config from your provider and save it as /etc/wireguard/wg0.conf, with permissions readable only by root.
  3. Bring it up: sudo wg-quick up wg0. Check with wg show that the handshake has completed.
  4. Test that your public IP has changed, then bring it down with sudo wg-quick down wg0.
  5. Make it automatic with sudo systemctl enable wg-quick@wg0 so the tunnel starts at boot.

This route uses exactly the same config format as the WireGuard mobile and desktop apps, so a config you generate for your phone works here too.

NetworkManager: the desktop alternative

If your desktop manages networks through NetworkManager — the default on Ubuntu-style systems — you can usually add a WireGuard profile through the network settings or nmcli connection import instead of using the command line, and it will follow the same Wi-Fi networks you already manage. The exact steps and supported options differ between releases, so check your distribution’s documentation. For servers, headless machines and anything where you want a fixed, scriptable setup, wg-quick remains the standard.

Kill switch patterns

wg-quick has no built-in kill switch button, but the official man page documents the standard pattern: PostUp and PreDown entries in the config file that add and remove iptables rules rejecting any packet that tries to leave via any interface other than the tunnel. With a default-route (AllowedIPs = 0.0.0.0/0) peer, this drops everything that is not going through the tunnel — the same principle the desktop apps implement. The man page notes one gap: most DHCP traffic still passes, because DHCP clients use packet sockets that bypass netfilter.

If you enable this pattern, test it deliberately: disconnect the VPN’s network link and confirm the machine cannot reach the internet until the tunnel returns. If firewall rules feel too fiddly, a provider app with a built-in kill switch, or a router-level VPN (see our router guide), may suit you better.

Check it worked

While connected, visit a leak-test page (mullvad.net/check, ipleak.net, dnsleaktest.com) and confirm the IP and DNS shown belong to the VPN. Then deliberately stop the tunnel (sudo wg-quick down wg0) with your kill switch rules active and confirm the machine goes offline rather than reverting to your naked connection. See our dedicated leak test guide for the full checklist.

What this does NOT protect you from

Sources and verification

Every factual claim on this page is registered and independently checked (two independent sources for legal, numeric and security claims). How this works: fact-checking. Spotted an error? Tell us.

WireGuard encapsulates IP packets over UDP and was designed to be far smaller and easier to audit than OpenVPN or IPsec.

  • WireGuard (Jason A. Donenfeld / ZX2C4) — WireGuard: fast, modern, secure VPN tunnel primary · accessed 2026-12-01
  • Wikipedia — WireGuard — Wikipedia (protocol passes traffic over UDP; lighter than IPsec and OpenVPN; minimal codebase) secondary · accessed 2026-12-01

The wg-quick(8) tool that ships with wireguard-tools automates bringing a WireGuard interface up and down, sets routes and DNS, and can add iptables rules that act as a kill switch.