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:
- If your distribution or release is not supported by the provider, you are stuck.
- Some providers restrict their app’s features on Linux.
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.
- Install the tools:
sudo apt install wireguardon Ubuntu-style systems (WireGuard is already in the Linux kernel). - Download the config from your provider and save it as
/etc/wireguard/wg0.conf, with permissions readable only by root. - Bring it up:
sudo wg-quick up wg0. Check withwg showthat the handshake has completed. - Test that your public IP has changed, then bring it down with
sudo wg-quick down wg0. - Make it automatic with
sudo systemctl enable wg-quick@wg0so 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
- A mis-typed config or firewall rule — verify with the tests above rather than assuming.
- DNS leaks if you edit the
DNS =line out of the config. - Traffic you route outside the tunnel on purpose (split tunneling).
- What you do while logged in: the VPN hides traffic from your ISP, not your identity from the sites you sign into.
Not legal advice. Using a VPN is lawful in the UK, but this page is not legal advice, and the law differs in detail between England & Wales, Scotland and Northern Ireland. If your freedom or livelihood depends on it, take advice from a qualified UK lawyer or a Citizens Advice bureau.
Sources
- WireGuard — Quick Start and WireGuard: fast, modern, secure VPN tunnel (accessed 1 Dec 2026).
- wireguard-tools — wg-quick(8) manual page (Arch Linux mirror of the upstream man page) (accessed 1 Dec 2026).