The WireGuard configuration file
A WireGuard tunnel is described by a small INI-style .conf file with one
[Interface] section for the local node and one or more [Peer] sections for
the remote ends. This reference lists every common key, its type, whether it is
required, and which keys are wg-quick extensions rather than core wg options.
How it works
The [Interface] section holds this node’s identity and (via wg-quick) its IP
and routing setup; each [Peer] defines a remote node, its public key, the IPs
it owns, and how to reach it:
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <server public key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
AllowedIPs is the heart of WireGuard’s cryptokey routing: it doubles as an
inbound source filter and an outbound route. Keys such as Address, DNS and
the PostUp/PostDown hooks are applied by the wg-quick wrapper.
Key-by-key reference
[Interface] keys
| Key | wg-quick only | Required | Type | Notes |
|---|---|---|---|---|
| PrivateKey | No | Yes | Base64 key | This node’s private key. Generate with wg genkey. |
| ListenPort | No | No | Integer | UDP port to listen on. If omitted, wg assigns a random port. |
| FwMark | No | No | Hex/integer | Firewall mark on outgoing packets; used to exempt tunnel traffic from policy routing. |
| Address | Yes | Yes* | CIDR | IP address(es) of this node’s tunnel interface. *Required by wg-quick. |
| DNS | Yes | No | IP(s) | DNS servers to configure while the tunnel is up. |
| MTU | Yes | No | Integer | Interface MTU. Default auto-detects; WireGuard overhead is ~60 bytes, so typical values are 1420 for IPv4 or 1380 for IPv6. |
| Table | Yes | No | Integer/off | Routing table. off disables route insertion; auto is the default. |
| PreUp/PostUp | Yes | No | Shell command | Run before/after wg-quick up. Useful for firewall rules (iptables). |
| PreDown/PostDown | Yes | No | Shell command | Run before/after wg-quick down. |
[Peer] keys
| Key | wg-quick only | Required | Type | Notes |
|---|---|---|---|---|
| PublicKey | No | Yes | Base64 key | The remote peer’s public key. |
| AllowedIPs | No | Yes | CIDR list | Routes for this peer (outbound) and accepted source IPs (inbound). |
| Endpoint | No | No | host:port | Where to send packets. Required for the initiating side; a server can omit it. |
| PersistentKeepalive | No | No | Seconds | Send a keepalive every N seconds to hold NAT mappings. Commonly 25. |
| PresharedKey | No | No | Base64 key | Optional symmetric key for post-quantum defence. Generate with wg genpsk. |
Minimal configurations by role
Full-tunnel VPN client:
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <server public key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0 # route ALL traffic through VPN
PersistentKeepalive = 25
Split-tunnel client (only corporate subnet):
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32
[Peer]
PublicKey = <server public key>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.0.0.0/8 # only internal traffic goes through VPN
PersistentKeepalive = 25
Server (multi-peer):
[Interface]
PrivateKey = <server private key>
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = <client-A public key>
AllowedIPs = 10.0.0.2/32 # this client's tunnel IP
[Peer]
PublicKey = <client-B public key>
AllowedIPs = 10.0.0.3/32
Tips and notes
- A minimal client needs
PrivateKey+Addressplus a peer withPublicKey,AllowedIPsandEndpoint. - Use
AllowedIPs = 0.0.0.0/0, ::/0for a full-tunnel VPN; list specific subnets for split tunnelling. - Add
PersistentKeepalive = 25on peers behind NAT to keep the path open. - Keys flagged wg-quick only will be ignored if you configure the interface directly with
wg setconf. - Generate a key pair with:
wg genkey | tee privatekey | wg pubkey > publickey.