WireGuard Router Setup
Configure a WireGuard tunnel on a home router with key generation, firewall rules, and handshake validation.

Networking Editorial
Overview
This guide walks through configuring a WireGuard tunnel on a consumer router with a modern firmware stack (OpenWrt, pfSense, or a vendor provided WireGuard package). By the end you will have a validated client interface with a stable handshake, correct routing, and no DNS leaks.
Prerequisites
- Admin access to the router's web UI or SSH console.
- Firmware with a native WireGuard package (OpenWrt 21.02+, pfSense 2.6+, or vendor equivalent).
- A server side WireGuard endpoint with public key, endpoint host, and allowed subnet.
- One free UDP port for inbound handshake traffic (default 51820).
Step by step configuration
Generate the client key pair, create the tunnel interface, then attach a single peer with your provider's public key and endpoint.
Generate a key pair
On the router shell, run
wg genkey | tee privatekey | wg pubkey > publickey. Restrict the private key file to mode 600.Create the WireGuard interface
Assign a client IP inside the tunnel subnet (for example 10.0.0.2/32) and set DNS to the provider's resolver so lookups traverse the tunnel.
Attach the peer
Enter the server public key, the endpoint host:port, allowed IPs (0.0.0.0/0 for a full tunnel), and a persistent keepalive of 25 seconds when the router sits behind NAT.
Open the firewall
Allow outbound UDP to the endpoint port and permit forwarding between the WireGuard zone and your LAN. Add a masquerade rule on the WireGuard interface if the provider expects source NAT.
[Interface]
PrivateKey = <client-private-key>
Address = 10.0.0.2/32
DNS = 1.1.1.1, 1.0.0.1
MTU = 1420
[Peer]
PublicKey = <server-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25Validation
Bring the interface up and confirm the tunnel is doing what you expect before making it the default route for LAN clients.
Handshake and routing
Run wg show on the router. A recent 'latest handshake' timestamp and non zero transfer counters mean the tunnel is negotiated. Then verify the router's default route now traverses the tunnel with ip route get 1.1.1.1.
Which UDP port should I use?
WireGuard defaults to UDP 51820, but any port your provider accepts works. Match the ListenPort on the server side and the Endpoint port on the client side.
Why is my handshake failing?
Nearly every failed handshake is either a firewall rule dropping outbound UDP or a mismatched public key. Confirm the peer public key matches the server's key, then verify UDP is allowed to the endpoint host and port.