1*744bfb21SJohn Baldwin.\" Copyright (c) 2020 Gordon Bergling <gbe@FreeBSD.org> 2*744bfb21SJohn Baldwin.\" 3*744bfb21SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 4*744bfb21SJohn Baldwin.\" modification, are permitted provided that the following conditions 5*744bfb21SJohn Baldwin.\" are met: 6*744bfb21SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 7*744bfb21SJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 8*744bfb21SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 9*744bfb21SJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 10*744bfb21SJohn Baldwin.\" documentation and/or other materials provided with the distribution. 11*744bfb21SJohn Baldwin.\" 12*744bfb21SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13*744bfb21SJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14*744bfb21SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15*744bfb21SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16*744bfb21SJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17*744bfb21SJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18*744bfb21SJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19*744bfb21SJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20*744bfb21SJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21*744bfb21SJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22*744bfb21SJohn Baldwin.\" SUCH DAMAGE. 23*744bfb21SJohn Baldwin.\" 24*744bfb21SJohn Baldwin.\" $FreeBSD$ 25*744bfb21SJohn Baldwin.\" 26*744bfb21SJohn Baldwin.Dd October 28, 2022 27*744bfb21SJohn Baldwin.Dt WG 4 28*744bfb21SJohn Baldwin.Os 29*744bfb21SJohn Baldwin.Sh NAME 30*744bfb21SJohn Baldwin.Nm wg 31*744bfb21SJohn Baldwin.Nd "WireGuard - pseudo-device" 32*744bfb21SJohn Baldwin.Sh SYNOPSIS 33*744bfb21SJohn BaldwinTo load the driver as a module at boot time, place the following line in 34*744bfb21SJohn Baldwin.Xr loader.conf 5 : 35*744bfb21SJohn Baldwin.Bd -literal -offset indent 36*744bfb21SJohn Baldwinif_wg_load="YES" 37*744bfb21SJohn Baldwin.Ed 38*744bfb21SJohn Baldwin.Sh DESCRIPTION 39*744bfb21SJohn BaldwinThe 40*744bfb21SJohn Baldwin.Nm 41*744bfb21SJohn Baldwindriver provides Virtual Private Network (VPN) interfaces for the secure 42*744bfb21SJohn Baldwinexchange of layer 3 traffic with other WireGuard peers using the WireGuard 43*744bfb21SJohn Baldwinprotocol. 44*744bfb21SJohn Baldwin.Pp 45*744bfb21SJohn BaldwinA 46*744bfb21SJohn Baldwin.Nm 47*744bfb21SJohn Baldwininterface recognises one or more peers, establishes a secure tunnel with 48*744bfb21SJohn Baldwineach on demand, and tracks each peer's UDP endpoint for exchanging encrypted 49*744bfb21SJohn Baldwintraffic with. 50*744bfb21SJohn Baldwin.Pp 51*744bfb21SJohn BaldwinThe interfaces can be created at runtime using the 52*744bfb21SJohn Baldwin.Ic ifconfig Cm wg Ns Ar N Cm create 53*744bfb21SJohn Baldwincommand. 54*744bfb21SJohn BaldwinThe interface itself can be configured with 55*744bfb21SJohn Baldwin.Xr wg 8 . 56*744bfb21SJohn Baldwin.Pp 57*744bfb21SJohn BaldwinThe following glossary provides a brief overview of WireGuard 58*744bfb21SJohn Baldwinterminology: 59*744bfb21SJohn Baldwin.Bl -tag -width indent -offset 3n 60*744bfb21SJohn Baldwin.It Peer 61*744bfb21SJohn BaldwinPeers exchange IPv4 or IPv6 traffic over secure tunnels. 62*744bfb21SJohn BaldwinEach 63*744bfb21SJohn Baldwin.Nm 64*744bfb21SJohn Baldwininterface may be configured to recognise one or more peers. 65*744bfb21SJohn Baldwin.It Key 66*744bfb21SJohn BaldwinEach peer uses its private key and corresponding public key to 67*744bfb21SJohn Baldwinidentify itself to others. 68*744bfb21SJohn BaldwinA peer configures a 69*744bfb21SJohn Baldwin.Nm 70*744bfb21SJohn Baldwininterface with its own private key and with the public keys of its peers. 71*744bfb21SJohn Baldwin.It Pre-shared key 72*744bfb21SJohn BaldwinIn addition to the public keys, each peer pair may be configured with a 73*744bfb21SJohn Baldwinunique pre-shared symmetric key. 74*744bfb21SJohn BaldwinThis is used in their handshake to guard against future compromise of the 75*744bfb21SJohn Baldwinpeers' encrypted tunnel if a quantum-computational attack on their 76*744bfb21SJohn BaldwinDiffie-Hellman exchange becomes feasible. 77*744bfb21SJohn BaldwinIt is optional, but recommended. 78*744bfb21SJohn Baldwin.It Allowed IPs 79*744bfb21SJohn BaldwinA single 80*744bfb21SJohn Baldwin.Nm 81*744bfb21SJohn Baldwininterface may maintain concurrent tunnels connecting diverse networks. 82*744bfb21SJohn BaldwinThe interface therefore implements rudimentary routing and reverse-path 83*744bfb21SJohn Baldwinfiltering functions for its tunneled traffic. 84*744bfb21SJohn BaldwinThese functions reference a set of allowed IP ranges configured against 85*744bfb21SJohn Baldwineach peer. 86*744bfb21SJohn Baldwin.Pp 87*744bfb21SJohn BaldwinThe interface will route outbound tunneled traffic to the peer configured 88*744bfb21SJohn Baldwinwith the most specific matching allowed IP address range, or drop it 89*744bfb21SJohn Baldwinif no such match exists. 90*744bfb21SJohn Baldwin.Pp 91*744bfb21SJohn BaldwinThe interface will accept tunneled traffic only from the peer 92*744bfb21SJohn Baldwinconfigured with the most specific matching allowed IP address range 93*744bfb21SJohn Baldwinfor the incoming traffic, or drop it if no such match exists. 94*744bfb21SJohn BaldwinThat is, tunneled traffic routed to a given peer cannot return through 95*744bfb21SJohn Baldwinanother peer of the same 96*744bfb21SJohn Baldwin.Nm 97*744bfb21SJohn Baldwininterface. 98*744bfb21SJohn BaldwinThis ensures that peers cannot spoof another's traffic. 99*744bfb21SJohn Baldwin.It Handshake 100*744bfb21SJohn BaldwinTwo peers handshake to mutually authenticate each other and to 101*744bfb21SJohn Baldwinestablish a shared series of secret ephemeral encryption keys. 102*744bfb21SJohn BaldwinAny peer may initiate a handshake. 103*744bfb21SJohn BaldwinHandshakes occur only when there is traffic to send, and recur every 104*744bfb21SJohn Baldwintwo minutes during transfers. 105*744bfb21SJohn Baldwin.It Connectionless 106*744bfb21SJohn BaldwinDue to the handshake behavior, there is no connected or disconnected 107*744bfb21SJohn Baldwinstate. 108*744bfb21SJohn Baldwin.El 109*744bfb21SJohn Baldwin.Ss Keys 110*744bfb21SJohn BaldwinPrivate keys for WireGuard can be generated from any sufficiently 111*744bfb21SJohn Baldwinsecure random source. 112*744bfb21SJohn BaldwinThe Curve25519 keys and the pre-shared keys are both 32 bytes 113*744bfb21SJohn Baldwinlong and are commonly encoded in base64 for ease of use. 114*744bfb21SJohn Baldwin.Pp 115*744bfb21SJohn BaldwinKeys can be generated with 116*744bfb21SJohn Baldwin.Xr wg 8 117*744bfb21SJohn Baldwinas follows: 118*744bfb21SJohn Baldwin.Pp 119*744bfb21SJohn Baldwin.Dl $ wg genkey 120*744bfb21SJohn Baldwin.Pp 121*744bfb21SJohn BaldwinAlthough a valid Curve25519 key must have 5 bits set to 122*744bfb21SJohn Baldwinspecific values, this is done by the interface and so it 123*744bfb21SJohn Baldwinwill accept any random 32-byte base64 string. 124*744bfb21SJohn Baldwin.Sh EXAMPLES 125*744bfb21SJohn BaldwinCreate a 126*744bfb21SJohn Baldwin.Nm 127*744bfb21SJohn Baldwininterface and set random private key. 128*744bfb21SJohn Baldwin.Bd -literal -offset indent 129*744bfb21SJohn Baldwin# ifconfig wg0 create 130*744bfb21SJohn Baldwin# wg genkey | wg set wg0 listen-port 54321 private-key /dev/stdin 131*744bfb21SJohn Baldwin.Ed 132*744bfb21SJohn Baldwin.Pp 133*744bfb21SJohn BaldwinRetrieve the associated public key from a 134*744bfb21SJohn Baldwin.Nm 135*744bfb21SJohn Baldwininterface. 136*744bfb21SJohn Baldwin.Bd -literal -offset indent 137*744bfb21SJohn Baldwin$ wg show wg0 public-key 138*744bfb21SJohn Baldwin.Ed 139*744bfb21SJohn Baldwin.Pp 140*744bfb21SJohn BaldwinConnect to a specific endpoint using its public-key and set the allowed IP address 141*744bfb21SJohn Baldwin.Bd -literal -offset indent 142*744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' endpoint 10.0.1.100:54321 allowed-ips 192.168.2.100/32 143*744bfb21SJohn Baldwin.Ed 144*744bfb21SJohn Baldwin.Pp 145*744bfb21SJohn BaldwinRemove a peer 146*744bfb21SJohn Baldwin.Bd -literal -offset indent 147*744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' remove 148*744bfb21SJohn Baldwin.Ed 149*744bfb21SJohn Baldwin.Sh DIAGNOSTICS 150*744bfb21SJohn BaldwinThe 151*744bfb21SJohn Baldwin.Nm 152*744bfb21SJohn Baldwininterface supports runtime debugging, which can be enabled with: 153*744bfb21SJohn Baldwin.Pp 154*744bfb21SJohn Baldwin.D1 Ic ifconfig Cm wg Ns Ar N Cm debug 155*744bfb21SJohn Baldwin.Pp 156*744bfb21SJohn BaldwinSome common error messages include: 157*744bfb21SJohn Baldwin.Bl -diag 158*744bfb21SJohn Baldwin.It "Handshake for peer X did not complete after 5 seconds, retrying" 159*744bfb21SJohn BaldwinPeer X did not reply to our initiation packet, for example because: 160*744bfb21SJohn Baldwin.Bl -bullet 161*744bfb21SJohn Baldwin.It 162*744bfb21SJohn BaldwinThe peer does not have the local interface configured as a peer. 163*744bfb21SJohn BaldwinPeers must be able to mutually authenticate each other. 164*744bfb21SJohn Baldwin.It 165*744bfb21SJohn BaldwinThe peer endpoint IP address is incorrectly configured. 166*744bfb21SJohn Baldwin.It 167*744bfb21SJohn BaldwinThere are firewall rules preventing communication between hosts. 168*744bfb21SJohn Baldwin.El 169*744bfb21SJohn Baldwin.It "Invalid handshake initiation" 170*744bfb21SJohn BaldwinThe incoming handshake packet could not be processed. 171*744bfb21SJohn BaldwinThis is likely due to the local interface not containing 172*744bfb21SJohn Baldwinthe correct public key for the peer. 173*744bfb21SJohn Baldwin.It "Invalid initiation MAC" 174*744bfb21SJohn BaldwinThe incoming handshake initiation packet had an invalid MAC. 175*744bfb21SJohn BaldwinThis is likely because the initiation sender has the wrong public key 176*744bfb21SJohn Baldwinfor the handshake receiver. 177*744bfb21SJohn Baldwin.It "Packet has unallowed src IP from peer X" 178*744bfb21SJohn BaldwinAfter decryption, an incoming data packet has a source IP address that 179*744bfb21SJohn Baldwinis not assigned to the allowed IPs of Peer X. 180*744bfb21SJohn Baldwin.El 181*744bfb21SJohn Baldwin.Sh SEE ALSO 182*744bfb21SJohn Baldwin.Xr inet 4 , 183*744bfb21SJohn Baldwin.Xr ip 4 , 184*744bfb21SJohn Baldwin.Xr netintro 4 , 185*744bfb21SJohn Baldwin.Xr ipf 5 , 186*744bfb21SJohn Baldwin.Xr pf.conf 5 , 187*744bfb21SJohn Baldwin.Xr ifconfig 8 , 188*744bfb21SJohn Baldwin.Xr ipfw 8 , 189*744bfb21SJohn Baldwin.Xr wg 8 190*744bfb21SJohn Baldwin.Rs 191*744bfb21SJohn Baldwin.%T WireGuard whitepaper 192*744bfb21SJohn Baldwin.%U https://www.wireguard.com/papers/wireguard.pdf 193*744bfb21SJohn Baldwin.Re 194*744bfb21SJohn Baldwin.Sh HISTORY 195*744bfb21SJohn BaldwinThe 196*744bfb21SJohn Baldwin.Nm 197*744bfb21SJohn Baldwindevice driver first appeared in 198*744bfb21SJohn Baldwin.Fx 14.0 . 199*744bfb21SJohn Baldwin.Sh AUTHORS 200*744bfb21SJohn BaldwinThe 201*744bfb21SJohn Baldwin.Nm 202*744bfb21SJohn Baldwindevice driver written by 203*744bfb21SJohn Baldwin.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com , 204*744bfb21SJohn Baldwin.An Matt Dunwoodie Aq Mt ncon@nconroy.net , 205*744bfb21SJohn Baldwinand 206*744bfb21SJohn Baldwin.An Kyle Evans Aq Mt kevans@FreeBSD.org . 207*744bfb21SJohn Baldwin.Pp 208*744bfb21SJohn BaldwinThis manual page was written by 209*744bfb21SJohn Baldwin.An Gordon Bergling Aq Mt gbe@FreeBSD.org 210*744bfb21SJohn Baldwinand is based on the 211*744bfb21SJohn Baldwin.Ox 212*744bfb21SJohn Baldwinmanual page written by 213*744bfb21SJohn Baldwin.An David Gwynne Aq Mt dlg@openbsd.org . 214