Phase 03 · Harden and verify

VPN Kill Switch Setup for Windows, Mac, Linux

Set up a VPN kill switch on Windows, macOS, and Linux using WireGuard, OpenVPN, UFW, and Packet Filter, then verify it actually blocks traffic.

This guide
21

steps, roughly in order.

01

What a kill switch does

A kill switch blocks any internet traffic outside the VPN tunnel. Enforcement happens in one of two places. The VPN client can hold the block itself, or the operating system firewall can hold it independently of the client. This guide covers both, on Windows, macOS, and Linux. Read the companion post first if you want the concept rather than the commands.

What a VPN kill switch is, and what it cannot do

02

Decide between a client kill switch and a firewall kill switch

Client-level blocking is a setting inside the VPN application. It is quick to enable, quick to reverse, and it disappears when the application does. Firewall-level blocking lives in the operating system and survives a client crash, a driver reset, and a reboot. Choose client-level if you want something you can undo in one click. Choose firewall-level if the leak you care about is the one that happens while nobody is watching.

03

Write down the way out before you write the first rule

Every firewall procedure below can lock a machine off the network. On a remote host reached over SSH, a default-deny outbound policy can end your session and leave you with no route back in. Decide the teardown command before you run the first rule. Keep console or out-of-band access open while you work. If the host is remote and you have no console, do not run these steps at all.

04

Windows with WireGuard

Open the WireGuard application, select your tunnel, choose Edit, and enable Block untunneled traffic. The setting installs firewall rules that drop traffic which is not going through the tunnel, so it keeps working if the tunnel drops. Deactivating the tunnel in the application removes the block. That is convenient, and it is also the limit of what a client-held kill switch can promise.

OpenVPN kill switch on WindowsAllowedIPs and split tunneling

05

Windows with OpenVPN and Defender Firewall

Open Windows Defender Firewall with Advanced Security, then open its Properties dialog. Set Outbound connections to Block on the Domain, Private, and Public profiles. Nothing leaves the machine until you add allow rules. Expect Windows Update, the Microsoft Store, and background services to stop working whenever the tunnel is down. That is the policy behaving correctly rather than a fault to troubleshoot.

06

Allow the tunnel back out on Windows

Add two outbound allow rules. The first is a program rule for the OpenVPN client so it can still reach the server, pointed at the full path to openvpn.exe on your machine. The second allows all programs but scopes Local IP address to the address your VPN adapter is assigned. Defender Firewall rules cannot be bound to an adapter by name, so the local address is what ties the rule to the tunnel. Read that address out of ipconfig while the tunnel is up rather than guessing it.

07

The same rules from the command line on Windows

Run these from an elevated prompt. Set the default with netsh advfirewall set allprofiles firewallpolicy blockinbound,blockoutbound. Add the program rule with netsh advfirewall firewall add rule name=OpenVPN dir=out action=allow enable=yes, followed by program= and the full path to your openvpn.exe. Add the tunnel rule with netsh advfirewall firewall add rule name=VPNTunnel dir=out action=allow, followed by localip= and the address your VPN adapter holds. Quote any path containing a space.

08

Keep DNS inside the tunnel on Windows

Windows can send name lookups out of an interface that is not the tunnel, which leaks the domains you visit even when the kill switch holds. The OpenVPN directive block-outside-dns exists for exactly this. The manual lists it among the Windows-specific options, and it uses the Windows Filtering Platform to stop any application reaching port 53 outside the tunnel. Add it to the profile on Windows, and leave it out on macOS and Linux, where the resolver stack handles DNS instead.

block-outside-dns and other OpenVPN flagsDNS leak protection setup

09

Linux with UFW

Identify your VPN interface, usually wg0 or tun0. Allow your management port first if this machine is remote, for example ufw allow 22/tcp. Set the defaults with ufw default deny outgoing and ufw default deny incoming. Allow the tunnel with ufw allow out on wg0. Allow the handshake with ufw allow out to SERVER_IP port PORT proto udp, substituting the endpoint from your config. Apply it with ufw enable.

10

Let your own network back in on Linux

A default-deny outbound policy also blocks printers, network storage, and the router administration page. Add only the exception you actually need, for example ufw allow out to 192.168.1.0/24. Keep the range narrow. Every address you allow outside the tunnel is an address your device can reach unencrypted. Skip this step entirely if nothing on the local network is worth reaching.

11

Linux with nftables

Use nftables when the host already uses it, or when you want one ruleset covering IPv4 and IPv6 together. Create a table in the inet family with an output chain declared as type filter hook output priority 0 and policy drop. Accept oifname lo and oifname wg0. Accept the server address on its UDP port so the handshake can complete. Load the file with nft -f and inspect the result with nft list ruleset. Read that output back and confirm every rule before you make the ruleset persistent.

VPN kill switch on Linux with iptables and nftables

12

The nftables tradeoff worth understanding

Adding ct state established,related to the output chain lets replies to existing inbound sessions leave the machine. That is what keeps a remote SSH session alive while you are still writing rules. It also lets a connection that was already open outside the tunnel keep sending. Decide which of those two matters more on this host. On a laptop you can usually leave it out, and on a remote server you usually cannot.

13

Make the Linux rules survive a reboot

UFW keeps its rules across reboots once ufw enable has been run. An nftables ruleset loaded by hand does not. Write it to the file your distribution loads at boot, then enable the nftables service. The file path and the service name both differ between distributions, so look up yours rather than copying a path from anywhere. Test the reboot while you still have console access rather than afterwards.

14

macOS with WireGuard

Enable On-Demand in the WireGuard application so the tunnel comes back without you noticing that it dropped. On-Demand is a reconnection policy and not a block. Traffic can still leave during the gap between the drop and the reconnect, which is where most real leaks happen. Use it alongside the Packet Filter rules below when that gap matters.

15

macOS with Packet Filter

Identify the tunnel interface with ifconfig, usually a utun device. The number is assigned when the tunnel comes up and can change, so check it after a reconnect rather than assuming. Write rules that block out all, then pass out on lo0, then pass out on the utun interface, then pass out to the server address on its port. Load the file with pfctl -f, enable Packet Filter with pfctl -e, and confirm what is active with pfctl -sr.

macOS VPN kill switch with pfctl

16

Make the macOS rules stick

Packet Filter is not enabled by default on macOS, and pfctl -e does not survive a reboot on its own. Persisting a ruleset means loading it at startup, so check the supported way to do that on the macOS version you run. Re-check it after a major system update rather than assuming your arrangement survived. Until that is in place, treat these rules as a per-session control and re-apply them deliberately.

17

Block IPv6 if the tunnel does not carry it

A ruleset written only for IPv4 leaves IPv6 free to leave the machine. Check first whether your tunnel carries IPv6 at all. In WireGuard that means an IPv6 range in AllowedIPs and an IPv6 address on the interface. The nftables inet family and a Packet Filter block out all rule both cover IPv6 already. UFW covers IPv6 only when IPV6 is set to yes in /etc/default/ufw, so read that file rather than assuming a default.

18

Verify by separating an IP leak from a DNS leak

Connect the tunnel and record two things: your public IP address, and the resolvers a leak test reports. Then drop the tunnel at the interface rather than in the client, using ip link set wg0 down on Linux or disabling the adapter on Windows. Immediately request a page by raw IP address, then request one by hostname. Traffic reaching a raw IP means the kill switch is not blocking. Names still resolving means DNS is escaping. Those are two different failures with two different fixes.

How to test whether a kill switch worksDNS leak protection setup

19

Test the reconnect window, not only the disconnect

Most real leaks happen in the seconds around a reconnect rather than during a long outage. Kill the VPN process instead of clicking disconnect, because a client-held kill switch cannot enforce anything once its own process is gone. Suspend the machine and wake it. Move a laptop from Wi-Fi to a wired connection. Watch the physical interface with tcpdump during each of those and look for anything that is not encapsulated tunnel traffic.

20

When the kill switch will not let go

Rules outlive the client that needed them, and a machine left offline after you stop using the VPN is usually a leftover policy rather than a broken adapter. On Windows run netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound and delete the rules you added by name. On Linux run ufw default allow outgoing, or delete the nftables table you created. On macOS run pfctl -d. Reboot afterwards and confirm normal traffic returns.

Connection troubleshooting

Where this fits
01

Get access

Create an anonymous account, pay in crypto, and produce your first credentials.

02

Connect a device

Import the tunnel on desktop, mobile, or a router with WireGuard or OpenVPN.