Setting up WireGuard on OPNsense
Run a WireGuard VPN endpoint on an OPNsense firewall via the official plugin, for either remote-client (“Road Warrior”) or router-to-router (“Site-to-Site”) tunnels — plus two gotchas that show up once the setup gets more advanced: no automatic reconnect after a peer’s IP changes, and DNS split-tunneling on Windows clients.
Prerequisites
- An OPNsense firewall with access to System → Firmware → Plugins.
- For Road Warrior: at least one client device that will run the official WireGuard client.
- For Site-to-Site: a second WireGuard-capable router/host to peer with.
Steps
1. Install the plugin
- Open the OPNsense GUI.
- Go to System → Firmware → Plugins.
- Search for
os-wireguardand click the + to install it. - Once installed, configuration lives under VPN → WireGuard.
2. Choose Road Warrior or Site-to-Site
- Road Warrior — a single client (laptop, phone) reaches the local network from anywhere. This is the default/standard WireGuard use case (one server, one or more client peers). OPNsense has a step-by-step wizard for it — see the official how-to.
- Site-to-Site — two full networks reach each other continuously, via two OPNsense (or other WireGuard-capable) routers peering with each other. More involved than Road Warrior since both sides need routing/interface configuration — see the official how-to.
3. Handle peers with a dynamic-IP endpoint (auto-reconnect)
WireGuard only resolves a peer’s endpoint hostname once, at the initial handshake — if that peer’s
IP later changes (e.g. it’s behind a dynamic-DNS home connection), WireGuard keeps retrying the
stale old IP and never reconnects on its own. See WireGuard endpoint DNS re-resolution for the underlying cause and re-resolve mechanisms
(the OPNsense side of this is typically a periodic cron job that re-applies the peer’s configured
hostname; Linux clients/servers have a ready-made wireguard-tools script and systemd timer for
the same purpose).
4. Split-tunnel DNS on Windows clients (optional, advanced)
By default, a WireGuard client’s DNS = config line redirects all DNS queries through the
tunnel while it’s up — there’s no built-in way to route only specific domains’ lookups through the
VPN and let everything else resolve normally, even by appending a DNS suffix to the DNS = line.
The documented workaround uses Windows’ NRPT (Name Resolution Policy Table, a mechanism
originally built for DirectAccess) via PostUp/PostDown script hooks in the WireGuard for
Windows client’s tunnel config:
[Interface]
PostUp = powershell -command "Add-DnsClientNrptRule -Namespace '<domain.tld>','.<domain.tld>' -NameServers '<internal-dns-server-ip>'"
PostDown = powershell -command "Get-DnsClientNrptRule | Where { $_.Namespace -match '.*\.domain\.tld' } | Remove-DnsClientNrptRule -force"This adds an NRPT rule for <domain.tld> (and its subdomains) pointing at your internal DNS
server only while the tunnel is up, and removes it again on disconnect — every other DNS query
keeps using the client’s normal resolver.
Script execution is disabled by default in the WireGuard for Windows client; enable it first via registry:
reg add HKLM\Software\WireGuard /v DangerousScriptExecution /t REG_DWORD /d 1 /fVerify
- Road Warrior / Site-to-Site: confirm the WireGuard handshake completes (OPNsense shows the peer’s last handshake time under VPN → WireGuard → Status) and traffic routes as expected.
- NRPT split-tunnel DNS: while the tunnel is connected, run (elevated PowerShell)
Get-DnsClientNrptRuleand confirm the rule for<domain.tld>is present. PreferResolve-DnsName <name>or a browser/pingto test resolution —nslookupdoes not honor NRPT rules and will appear to fail even when the setup is correct.
Troubleshooting
- A peer stops reconnecting after its IP changes: this is expected WireGuard behavior, not a misconfiguration — see WireGuard endpoint DNS re-resolution for the fix (a periodic re-resolve job).
nslookupfails to resolve a split-tunnel domain even though the tunnel and NRPT rule look correct: this is a known NRPT limitation, not a broken setup — test withping,Resolve-DnsName, or an application (browser) instead.- NRPT
PostUp/PostDownscripts silently don’t run at all: check thatDangerousScriptExecutionis set in the registry (see step 4) — the WireGuard Windows client refuses to runPostUp/PostDownscripts otherwise.
Related
- WireGuard endpoint DNS re-resolution — the general re-resolve problem and Linux-side fix, referenced from step 3 above.
Sources
- Legacy wiki.js: OPNsense WireGuard setup — private source (original wiki.js text)