1a6bca3d2SAaron LI.\" SPDX-License-Identifier: BSD-2-Clause 2a6bca3d2SAaron LI.\" 3a6bca3d2SAaron LI.\" Copyright (c) 2020 Gordon Bergling <gbe@FreeBSD.org> 4a6bca3d2SAaron LI.\" 5a6bca3d2SAaron LI.\" Redistribution and use in source and binary forms, with or without 6a6bca3d2SAaron LI.\" modification, are permitted provided that the following conditions 7a6bca3d2SAaron LI.\" are met: 8a6bca3d2SAaron LI.\" 1. Redistributions of source code must retain the above copyright 9a6bca3d2SAaron LI.\" notice, this list of conditions and the following disclaimer. 10a6bca3d2SAaron LI.\" 2. Redistributions in binary form must reproduce the above copyright 11a6bca3d2SAaron LI.\" notice, this list of conditions and the following disclaimer in the 12a6bca3d2SAaron LI.\" documentation and/or other materials provided with the distribution. 13a6bca3d2SAaron LI.\" 14a6bca3d2SAaron LI.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15a6bca3d2SAaron LI.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16a6bca3d2SAaron LI.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17a6bca3d2SAaron LI.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18a6bca3d2SAaron LI.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19a6bca3d2SAaron LI.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20a6bca3d2SAaron LI.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21a6bca3d2SAaron LI.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22a6bca3d2SAaron LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23a6bca3d2SAaron LI.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24a6bca3d2SAaron LI.\" SUCH DAMAGE. 25a6bca3d2SAaron LI.\" 26874a3174SAaron LI.Dd January 18, 2024 27a6bca3d2SAaron LI.Dt WG 4 28a6bca3d2SAaron LI.Os 29a6bca3d2SAaron LI.Sh NAME 30a6bca3d2SAaron LI.Nm wg 31874a3174SAaron LI.Nd WireGuard protocol driver 32a6bca3d2SAaron LI.Sh SYNOPSIS 33a6bca3d2SAaron LITo load the driver as a module at boot time, place the following line in 34874a3174SAaron LI.Xr rc.conf 5 : 35a6bca3d2SAaron LI.Bd -literal -offset indent 36a6bca3d2SAaron LIif_wg_load="YES" 37a6bca3d2SAaron LI.Ed 38874a3174SAaron LI.Pp 39874a3174SAaron LITo compile this driver into the kernel, add the following line to 40874a3174SAaron LI.Xr kernconf 5 41874a3174SAaron LIkernel configuration file: 42874a3174SAaron LI.Bd -literal -offset indent 43874a3174SAaron LI.Cd pseudo-device wg 44874a3174SAaron LI.Ed 45a6bca3d2SAaron LI.Sh DESCRIPTION 46a6bca3d2SAaron LIThe 47a6bca3d2SAaron LI.Nm 48a6bca3d2SAaron LIdriver provides Virtual Private Network (VPN) interfaces for the secure 49a6bca3d2SAaron LIexchange of layer 3 traffic with other WireGuard peers using the WireGuard 50a6bca3d2SAaron LIprotocol. 51a6bca3d2SAaron LI.Pp 52a6bca3d2SAaron LIA 53a6bca3d2SAaron LI.Nm 54a6bca3d2SAaron LIinterface recognizes one or more peers, establishes a secure tunnel with 55a6bca3d2SAaron LIeach on demand, and tracks each peer's UDP endpoint for exchanging encrypted 56a6bca3d2SAaron LItraffic with. 57a6bca3d2SAaron LI.Pp 58a6bca3d2SAaron LIThe interfaces can be created at runtime using the 59a6bca3d2SAaron LI.Ic ifconfig Cm wg Ns Ar N Cm create 60874a3174SAaron LIcommand, and then can be configured with 61874a3174SAaron LI.Xr ifconfig 8 . 62*451640b7SAaron LIIn addition, the 63*451640b7SAaron LI.Nm 64*451640b7SAaron LI.Xr rc 8 65*451640b7SAaron LIscript can be used to easily manage the interfaces; refer to 66*451640b7SAaron LI.Xr rc.conf 5 67*451640b7SAaron LIand 68*451640b7SAaron LI.Xr wg.conf 5 69*451640b7SAaron LIfor the details. 70*451640b7SAaron LI.Ss Terminology 71874a3174SAaron LIThe following glossary provides a brief overview of WireGuard terminology: 72a6bca3d2SAaron LI.Bl -tag -width indent -offset 3n 73a6bca3d2SAaron LI.It Peer 74a6bca3d2SAaron LIPeers exchange IPv4 or IPv6 traffic over secure tunnels. 75a6bca3d2SAaron LIEach 76a6bca3d2SAaron LI.Nm 77874a3174SAaron LIinterface may be configured to recognize one or more peers. 78a6bca3d2SAaron LI.It Key 79a6bca3d2SAaron LIEach peer uses its private key and corresponding public key to 80a6bca3d2SAaron LIidentify itself to others. 81a6bca3d2SAaron LIA peer configures a 82a6bca3d2SAaron LI.Nm 83a6bca3d2SAaron LIinterface with its own private key and with the public keys of its peers. 84a6bca3d2SAaron LI.It Pre-shared key 85a6bca3d2SAaron LIIn addition to the public keys, each peer pair may be configured with a 86a6bca3d2SAaron LIunique pre-shared symmetric key. 87a6bca3d2SAaron LIThis is used in their handshake to guard against future compromise of the 88874a3174SAaron LIpeers' encrypted tunnel if an attack on their Diffie-Hellman exchange 89874a3174SAaron LIbecomes feasible. 90a6bca3d2SAaron LIIt is optional, but recommended. 91a6bca3d2SAaron LI.It Allowed IP addresses 92a6bca3d2SAaron LIA single 93a6bca3d2SAaron LI.Nm 94a6bca3d2SAaron LIinterface may maintain concurrent tunnels connecting diverse networks. 95a6bca3d2SAaron LIThe interface therefore implements rudimentary routing and reverse-path 96a6bca3d2SAaron LIfiltering functions for its tunneled traffic. 97a6bca3d2SAaron LIThese functions reference a set of allowed IP address ranges configured 98a6bca3d2SAaron LIagainst each peer. 99a6bca3d2SAaron LI.Pp 100a6bca3d2SAaron LIThe interface will route outbound tunneled traffic to the peer configured 101a6bca3d2SAaron LIwith the most specific matching allowed IP address range, or drop it 102a6bca3d2SAaron LIif no such match exists. 103a6bca3d2SAaron LIThe interface will accept tunneled traffic only from the peer 104a6bca3d2SAaron LIconfigured with the most specific matching allowed IP address range 105a6bca3d2SAaron LIfor the incoming traffic, or drop it if no such match exists. 106a6bca3d2SAaron LIThat is, tunneled traffic routed to a given peer cannot return through 107a6bca3d2SAaron LIanother peer of the same 108a6bca3d2SAaron LI.Nm 109a6bca3d2SAaron LIinterface. 110a6bca3d2SAaron LIThis ensures that peers cannot spoof one another's traffic. 111a6bca3d2SAaron LI.It Handshake 112a6bca3d2SAaron LITwo peers handshake to mutually authenticate each other and to 113a6bca3d2SAaron LIestablish a shared series of secret ephemeral encryption keys. 114a6bca3d2SAaron LIEither peer may initiate a handshake. 115a6bca3d2SAaron LIHandshakes occur only when there is traffic to send, and recur every 116a6bca3d2SAaron LItwo minutes during transfers. 117a6bca3d2SAaron LI.It Connectionless 118a6bca3d2SAaron LIDue to the handshake behavior, there is no connected or disconnected 119a6bca3d2SAaron LIstate. 120a6bca3d2SAaron LI.El 121a6bca3d2SAaron LI.Ss Keys 122a6bca3d2SAaron LIPrivate keys for WireGuard can be generated from any sufficiently 123a6bca3d2SAaron LIsecure random source. 124a6bca3d2SAaron LIThe Curve25519 keys and the pre-shared keys are both 32 bytes 125a6bca3d2SAaron LIlong and are commonly encoded in base64 for ease of use. 126a6bca3d2SAaron LI.Pp 127a6bca3d2SAaron LIKeys can be generated with 128874a3174SAaron LI.Xr openssl 1 129a6bca3d2SAaron LIas follows: 130a6bca3d2SAaron LI.Pp 131874a3174SAaron LI.Dl $ openssl rand -base64 32 132a6bca3d2SAaron LI.Pp 133874a3174SAaron LIAlthough a valid Curve25519 key must have 5 bits set to specific values, 134874a3174SAaron LIthis is done by the 135874a3174SAaron LI.Nm 136874a3174SAaron LIinterface and so it will accept any random 32-byte base64 string. 137a6bca3d2SAaron LI.Sh EXAMPLES 138a6bca3d2SAaron LICreate a 139a6bca3d2SAaron LI.Nm 140874a3174SAaron LIinterface and set random private key: 141a6bca3d2SAaron LI.Bd -literal -offset indent 142a6bca3d2SAaron LI# ifconfig wg0 create 143874a3174SAaron LI# ifconfig wg0 wgkey `openssl rand -base64 32` wgport 54321 144a6bca3d2SAaron LI.Ed 145a6bca3d2SAaron LI.Pp 146a6bca3d2SAaron LIRetrieve the associated public key from a 147a6bca3d2SAaron LI.Nm 148874a3174SAaron LIinterface: 149a6bca3d2SAaron LI.Bd -literal -offset indent 150874a3174SAaron LI$ ifconfig wg0 | grep 'wgpubkey:' 151a6bca3d2SAaron LI.Ed 152a6bca3d2SAaron LI.Pp 153874a3174SAaron LIBy default, the private key and pre-shared key (if set) are hidden from 154874a3174SAaron LIthe interface status output, but can be made to show up by specifying the 155874a3174SAaron LI.Fl k 156874a3174SAaron LIflag for 157874a3174SAaron LI.Xr ifconfig 8 : 158a6bca3d2SAaron LI.Bd -literal -offset indent 159874a3174SAaron LI# ifconfig -k wg0 | grep -E 'wgkey:|wgpsk:' 160a6bca3d2SAaron LI.Ed 161a6bca3d2SAaron LI.Pp 162874a3174SAaron LIConnect to a specific endpoint using its public-key and set the 163874a3174SAaron LIallowed IP address: 164a6bca3d2SAaron LI.Bd -literal -offset indent 165874a3174SAaron LI# ifconfig wg0 wgpeer <peer_pubkey> \\ 166874a3174SAaron LI wgendpoint 10.0.1.100 54321 \\ 167874a3174SAaron LI wgaip 192.168.2.100/32 168874a3174SAaron LI.Ed 169874a3174SAaron LI.Pp 170874a3174SAaron LISet description for a peer: 171874a3174SAaron LI.Bd -literal -offset indent 172874a3174SAaron LI# ifconfig wg0 wgpeer <peer_pubkey> wgdescr <peer_description> 173874a3174SAaron LI.Ed 174874a3174SAaron LI.Pp 175874a3174SAaron LIRemove a peer: 176874a3174SAaron LI.Bd -literal -offset indent 177874a3174SAaron LI# ifconfig wg0 -wgpeer <peer_pubkey> 178a6bca3d2SAaron LI.Ed 179a6bca3d2SAaron LI.Sh DIAGNOSTICS 180a6bca3d2SAaron LIThe 181a6bca3d2SAaron LI.Nm 182a6bca3d2SAaron LIinterface supports runtime debugging, which can be enabled with: 183a6bca3d2SAaron LI.Pp 184a6bca3d2SAaron LI.D1 Ic ifconfig Cm wg Ns Ar N Cm debug 185a6bca3d2SAaron LI.Pp 186a6bca3d2SAaron LISome common error messages include: 187874a3174SAaron LI.Bl -tag -width indent 188874a3174SAaron LI.It Sy "Handshake for peer X did not complete after 5 seconds, retrying" 189a6bca3d2SAaron LIPeer X did not reply to our initiation packet, for example because: 190874a3174SAaron LI.Bl -bullet -compact 191a6bca3d2SAaron LI.It 192a6bca3d2SAaron LIThe peer does not have the local interface configured as a peer. 193a6bca3d2SAaron LIPeers must be able to mutually authenticate each other. 194a6bca3d2SAaron LI.It 195874a3174SAaron LIThe peer's endpoint IP address is incorrectly configured. 196a6bca3d2SAaron LI.It 197a6bca3d2SAaron LIThere are firewall rules preventing communication between hosts. 198a6bca3d2SAaron LI.El 199874a3174SAaron LI.It Sy "Invalid handshake initiation" 200a6bca3d2SAaron LIThe incoming handshake packet could not be processed. 201a6bca3d2SAaron LIThis is likely due to the local interface not containing 202a6bca3d2SAaron LIthe correct public key for the peer. 203874a3174SAaron LI.It Sy "Invalid initiation MAC" 204a6bca3d2SAaron LIThe incoming handshake initiation packet had an invalid MAC. 205a6bca3d2SAaron LIThis is likely because the initiation sender has the wrong public key 206a6bca3d2SAaron LIfor the handshake receiver. 207874a3174SAaron LI.It Sy "Packet has disallowed src IP from peer X" 208a6bca3d2SAaron LIAfter decryption, an incoming data packet has a source IP address that 209a6bca3d2SAaron LIis not assigned to the allowed IPs of Peer X. 210a6bca3d2SAaron LI.El 211a6bca3d2SAaron LI.Sh SEE ALSO 212a6bca3d2SAaron LI.Xr inet 4 , 213a6bca3d2SAaron LI.Xr ip 4 , 214a6bca3d2SAaron LI.Xr netintro 4 , 215*451640b7SAaron LI.Xr wg.conf 5 , 216874a3174SAaron LI.Xr ifconfig 8 217a6bca3d2SAaron LI.Rs 218a6bca3d2SAaron LI.%T WireGuard whitepaper 219a6bca3d2SAaron LI.%U https://www.wireguard.com/papers/wireguard.pdf 220a6bca3d2SAaron LI.Re 221a6bca3d2SAaron LI.Sh HISTORY 222a6bca3d2SAaron LIThe 223a6bca3d2SAaron LI.Nm 224a6bca3d2SAaron LIdevice driver first appeared in 225874a3174SAaron LI.Dx 6.5 , 226874a3174SAaron LI.Fx 13.2 , 227874a3174SAaron LIand 228874a3174SAaron LI.Ox 6.8 . 229a6bca3d2SAaron LI.Sh AUTHORS 230a6bca3d2SAaron LI.An -nosplit 231a6bca3d2SAaron LIThe 232a6bca3d2SAaron LI.Nm 233a6bca3d2SAaron LIdevice driver was written by 234a6bca3d2SAaron LI.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com , 235a6bca3d2SAaron LI.An Matt Dunwoodie Aq Mt ncon@nconroy.net , 236a6bca3d2SAaron LI.An Kyle Evans Aq Mt kevans@FreeBSD.org , 237a6bca3d2SAaron LIand 238a6bca3d2SAaron LI.An Matt Macy Aq Mt mmacy@FreeBSD.org . 239a6bca3d2SAaron LI.Pp 240a6bca3d2SAaron LIThis manual page was written by 241a6bca3d2SAaron LI.An Gordon Bergling Aq Mt gbe@FreeBSD.org 242a6bca3d2SAaron LIand is based on the 243a6bca3d2SAaron LI.Ox 244a6bca3d2SAaron LImanual page written by 245a6bca3d2SAaron LI.An David Gwynne Aq Mt dlg@openbsd.org . 246