1c72854c0SGordon Bergling.\" SPDX-License-Identifier: BSD-2-Clause 219c03f4aSGordon Bergling.\" 3744bfb21SJohn Baldwin.\" Copyright (c) 2020 Gordon Bergling <gbe@FreeBSD.org> 4744bfb21SJohn Baldwin.\" 5744bfb21SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 6744bfb21SJohn Baldwin.\" modification, are permitted provided that the following conditions 7744bfb21SJohn Baldwin.\" are met: 8744bfb21SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 9744bfb21SJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 10744bfb21SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 11744bfb21SJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 12744bfb21SJohn Baldwin.\" documentation and/or other materials provided with the distribution. 13744bfb21SJohn Baldwin.\" 14744bfb21SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15744bfb21SJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16744bfb21SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17744bfb21SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18744bfb21SJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19744bfb21SJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20744bfb21SJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21744bfb21SJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22744bfb21SJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23744bfb21SJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24744bfb21SJohn Baldwin.\" SUCH DAMAGE. 25744bfb21SJohn Baldwin.\" 261dd6f95bSEd Maste.Dd June 12, 2023 27744bfb21SJohn Baldwin.Dt WG 4 28744bfb21SJohn Baldwin.Os 29744bfb21SJohn Baldwin.Sh NAME 30744bfb21SJohn Baldwin.Nm wg 3119c03f4aSGordon Bergling.Nd "WireGuard protocol driver" 32744bfb21SJohn Baldwin.Sh SYNOPSIS 33744bfb21SJohn BaldwinTo load the driver as a module at boot time, place the following line in 34744bfb21SJohn Baldwin.Xr loader.conf 5 : 35744bfb21SJohn Baldwin.Bd -literal -offset indent 36744bfb21SJohn Baldwinif_wg_load="YES" 37744bfb21SJohn Baldwin.Ed 38744bfb21SJohn Baldwin.Sh DESCRIPTION 39744bfb21SJohn BaldwinThe 40744bfb21SJohn Baldwin.Nm 41744bfb21SJohn Baldwindriver provides Virtual Private Network (VPN) interfaces for the secure 42744bfb21SJohn Baldwinexchange of layer 3 traffic with other WireGuard peers using the WireGuard 43744bfb21SJohn Baldwinprotocol. 44744bfb21SJohn Baldwin.Pp 45744bfb21SJohn BaldwinA 46744bfb21SJohn Baldwin.Nm 4719c03f4aSGordon Berglinginterface recognizes one or more peers, establishes a secure tunnel with 48744bfb21SJohn Baldwineach on demand, and tracks each peer's UDP endpoint for exchanging encrypted 49744bfb21SJohn Baldwintraffic with. 50744bfb21SJohn Baldwin.Pp 51744bfb21SJohn BaldwinThe interfaces can be created at runtime using the 52744bfb21SJohn Baldwin.Ic ifconfig Cm wg Ns Ar N Cm create 53744bfb21SJohn Baldwincommand. 54744bfb21SJohn BaldwinThe interface itself can be configured with 55744bfb21SJohn Baldwin.Xr wg 8 . 56744bfb21SJohn Baldwin.Pp 57744bfb21SJohn BaldwinThe following glossary provides a brief overview of WireGuard 58744bfb21SJohn Baldwinterminology: 59744bfb21SJohn Baldwin.Bl -tag -width indent -offset 3n 60744bfb21SJohn Baldwin.It Peer 61744bfb21SJohn BaldwinPeers exchange IPv4 or IPv6 traffic over secure tunnels. 62744bfb21SJohn BaldwinEach 63744bfb21SJohn Baldwin.Nm 64ffc4f93eSBenedict Reuschlinginterface may be configured to recognize one or more peers. 65744bfb21SJohn Baldwin.It Key 66744bfb21SJohn BaldwinEach peer uses its private key and corresponding public key to 67744bfb21SJohn Baldwinidentify itself to others. 68744bfb21SJohn BaldwinA peer configures a 69744bfb21SJohn Baldwin.Nm 70744bfb21SJohn Baldwininterface with its own private key and with the public keys of its peers. 71744bfb21SJohn Baldwin.It Pre-shared key 72744bfb21SJohn BaldwinIn addition to the public keys, each peer pair may be configured with a 73744bfb21SJohn Baldwinunique pre-shared symmetric key. 74744bfb21SJohn BaldwinThis is used in their handshake to guard against future compromise of the 7519c03f4aSGordon Berglingpeers' encrypted tunnel if an attack on their 76744bfb21SJohn BaldwinDiffie-Hellman exchange becomes feasible. 77744bfb21SJohn BaldwinIt is optional, but recommended. 7819c03f4aSGordon Bergling.It Allowed IP addresses 79744bfb21SJohn BaldwinA single 80744bfb21SJohn Baldwin.Nm 81744bfb21SJohn Baldwininterface may maintain concurrent tunnels connecting diverse networks. 82744bfb21SJohn BaldwinThe interface therefore implements rudimentary routing and reverse-path 83744bfb21SJohn Baldwinfiltering functions for its tunneled traffic. 8419c03f4aSGordon BerglingThese functions reference a set of allowed IP address ranges configured 8519c03f4aSGordon Berglingagainst each peer. 86744bfb21SJohn Baldwin.Pp 87744bfb21SJohn BaldwinThe interface will route outbound tunneled traffic to the peer configured 88744bfb21SJohn Baldwinwith the most specific matching allowed IP address range, or drop it 89744bfb21SJohn Baldwinif no such match exists. 90744bfb21SJohn Baldwin.Pp 91744bfb21SJohn BaldwinThe interface will accept tunneled traffic only from the peer 92744bfb21SJohn Baldwinconfigured with the most specific matching allowed IP address range 93744bfb21SJohn Baldwinfor the incoming traffic, or drop it if no such match exists. 94744bfb21SJohn BaldwinThat is, tunneled traffic routed to a given peer cannot return through 95744bfb21SJohn Baldwinanother peer of the same 96744bfb21SJohn Baldwin.Nm 97744bfb21SJohn Baldwininterface. 9819c03f4aSGordon BerglingThis ensures that peers cannot spoof one another's traffic. 99744bfb21SJohn Baldwin.It Handshake 100744bfb21SJohn BaldwinTwo peers handshake to mutually authenticate each other and to 101744bfb21SJohn Baldwinestablish a shared series of secret ephemeral encryption keys. 10219c03f4aSGordon BerglingEither peer may initiate a handshake. 103744bfb21SJohn BaldwinHandshakes occur only when there is traffic to send, and recur every 104744bfb21SJohn Baldwintwo minutes during transfers. 105744bfb21SJohn Baldwin.It Connectionless 106744bfb21SJohn BaldwinDue to the handshake behavior, there is no connected or disconnected 107744bfb21SJohn Baldwinstate. 108744bfb21SJohn Baldwin.El 109744bfb21SJohn Baldwin.Ss Keys 110744bfb21SJohn BaldwinPrivate keys for WireGuard can be generated from any sufficiently 111744bfb21SJohn Baldwinsecure random source. 112744bfb21SJohn BaldwinThe Curve25519 keys and the pre-shared keys are both 32 bytes 113744bfb21SJohn Baldwinlong and are commonly encoded in base64 for ease of use. 114744bfb21SJohn Baldwin.Pp 115744bfb21SJohn BaldwinKeys can be generated with 116744bfb21SJohn Baldwin.Xr wg 8 117744bfb21SJohn Baldwinas follows: 118744bfb21SJohn Baldwin.Pp 119744bfb21SJohn Baldwin.Dl $ wg genkey 120744bfb21SJohn Baldwin.Pp 121744bfb21SJohn BaldwinAlthough a valid Curve25519 key must have 5 bits set to 122744bfb21SJohn Baldwinspecific values, this is done by the interface and so it 123744bfb21SJohn Baldwinwill accept any random 32-byte base64 string. 124*bf454ca8SMark Johnston.Sh NETMAP 125*bf454ca8SMark Johnston.Xr netmap 4 126*bf454ca8SMark Johnstonapplications may open a WireGuard interface in emulated mode. 127*bf454ca8SMark JohnstonThe netmap application will receive decrypted, unencapsulated packets prepended 128*bf454ca8SMark Johnstonby a dummy Ethernet header. 129*bf454ca8SMark JohnstonThe Ethertype field will be one of 130*bf454ca8SMark Johnston.Dv ETHERTYPE_IP 131*bf454ca8SMark Johnstonor 132*bf454ca8SMark Johnston.Dv ETHERTYPE_IPV6 133*bf454ca8SMark Johnstondepending on the address family of the packet. 134*bf454ca8SMark JohnstonPackets transmitted by the application should similarly begin with a dummy 135*bf454ca8SMark JohnstonEthernet header; this header will be stripped before the packet is encrypted 136*bf454ca8SMark Johnstonand tunneled. 137744bfb21SJohn Baldwin.Sh EXAMPLES 138744bfb21SJohn BaldwinCreate a 139744bfb21SJohn Baldwin.Nm 140744bfb21SJohn Baldwininterface and set random private key. 141744bfb21SJohn Baldwin.Bd -literal -offset indent 142744bfb21SJohn Baldwin# ifconfig wg0 create 143744bfb21SJohn Baldwin# wg genkey | wg set wg0 listen-port 54321 private-key /dev/stdin 144744bfb21SJohn Baldwin.Ed 145744bfb21SJohn Baldwin.Pp 146744bfb21SJohn BaldwinRetrieve the associated public key from a 147744bfb21SJohn Baldwin.Nm 148744bfb21SJohn Baldwininterface. 149744bfb21SJohn Baldwin.Bd -literal -offset indent 150744bfb21SJohn Baldwin$ wg show wg0 public-key 151744bfb21SJohn Baldwin.Ed 152744bfb21SJohn Baldwin.Pp 153744bfb21SJohn BaldwinConnect to a specific endpoint using its public-key and set the allowed IP address 154744bfb21SJohn Baldwin.Bd -literal -offset indent 155744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' endpoint 10.0.1.100:54321 allowed-ips 192.168.2.100/32 156744bfb21SJohn Baldwin.Ed 157744bfb21SJohn Baldwin.Pp 158744bfb21SJohn BaldwinRemove a peer 159744bfb21SJohn Baldwin.Bd -literal -offset indent 160744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' remove 161744bfb21SJohn Baldwin.Ed 162744bfb21SJohn Baldwin.Sh DIAGNOSTICS 163744bfb21SJohn BaldwinThe 164744bfb21SJohn Baldwin.Nm 165744bfb21SJohn Baldwininterface supports runtime debugging, which can be enabled with: 166744bfb21SJohn Baldwin.Pp 167744bfb21SJohn Baldwin.D1 Ic ifconfig Cm wg Ns Ar N Cm debug 168744bfb21SJohn Baldwin.Pp 169744bfb21SJohn BaldwinSome common error messages include: 170744bfb21SJohn Baldwin.Bl -diag 171744bfb21SJohn Baldwin.It "Handshake for peer X did not complete after 5 seconds, retrying" 172744bfb21SJohn BaldwinPeer X did not reply to our initiation packet, for example because: 173744bfb21SJohn Baldwin.Bl -bullet 174744bfb21SJohn Baldwin.It 175744bfb21SJohn BaldwinThe peer does not have the local interface configured as a peer. 176744bfb21SJohn BaldwinPeers must be able to mutually authenticate each other. 177744bfb21SJohn Baldwin.It 178744bfb21SJohn BaldwinThe peer endpoint IP address is incorrectly configured. 179744bfb21SJohn Baldwin.It 180744bfb21SJohn BaldwinThere are firewall rules preventing communication between hosts. 181744bfb21SJohn Baldwin.El 182744bfb21SJohn Baldwin.It "Invalid handshake initiation" 183744bfb21SJohn BaldwinThe incoming handshake packet could not be processed. 184744bfb21SJohn BaldwinThis is likely due to the local interface not containing 185744bfb21SJohn Baldwinthe correct public key for the peer. 186744bfb21SJohn Baldwin.It "Invalid initiation MAC" 187744bfb21SJohn BaldwinThe incoming handshake initiation packet had an invalid MAC. 188744bfb21SJohn BaldwinThis is likely because the initiation sender has the wrong public key 189744bfb21SJohn Baldwinfor the handshake receiver. 190744bfb21SJohn Baldwin.It "Packet has unallowed src IP from peer X" 191744bfb21SJohn BaldwinAfter decryption, an incoming data packet has a source IP address that 192744bfb21SJohn Baldwinis not assigned to the allowed IPs of Peer X. 193744bfb21SJohn Baldwin.El 194744bfb21SJohn Baldwin.Sh SEE ALSO 195744bfb21SJohn Baldwin.Xr inet 4 , 196744bfb21SJohn Baldwin.Xr ip 4 , 19719c03f4aSGordon Bergling.Xr ipsec 4 , 198744bfb21SJohn Baldwin.Xr netintro 4 , 199*bf454ca8SMark Johnston.Xr netmap 4 , 20019c03f4aSGordon Bergling.Xr ovpn 4 , 201744bfb21SJohn Baldwin.Xr ipf 5 , 202744bfb21SJohn Baldwin.Xr pf.conf 5 , 203744bfb21SJohn Baldwin.Xr ifconfig 8 , 204744bfb21SJohn Baldwin.Xr ipfw 8 , 205744bfb21SJohn Baldwin.Xr wg 8 206744bfb21SJohn Baldwin.Rs 207744bfb21SJohn Baldwin.%T WireGuard whitepaper 208744bfb21SJohn Baldwin.%U https://www.wireguard.com/papers/wireguard.pdf 209744bfb21SJohn Baldwin.Re 210744bfb21SJohn Baldwin.Sh HISTORY 211744bfb21SJohn BaldwinThe 212744bfb21SJohn Baldwin.Nm 213744bfb21SJohn Baldwindevice driver first appeared in 214001830eaSJohn Baldwin.Fx 13.2 . 215744bfb21SJohn Baldwin.Sh AUTHORS 21619c03f4aSGordon Bergling.An -nosplit 217744bfb21SJohn BaldwinThe 218744bfb21SJohn Baldwin.Nm 21919c03f4aSGordon Berglingdevice driver was written by 220744bfb21SJohn Baldwin.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com , 221744bfb21SJohn Baldwin.An Matt Dunwoodie Aq Mt ncon@nconroy.net , 2221dd6f95bSEd Maste.An Kyle Evans Aq Mt kevans@FreeBSD.org , 223744bfb21SJohn Baldwinand 2241dd6f95bSEd Maste.An Matt Macy Aq Mt mmacy@FreeBSD.org . 225744bfb21SJohn Baldwin.Pp 226744bfb21SJohn BaldwinThis manual page was written by 227744bfb21SJohn Baldwin.An Gordon Bergling Aq Mt gbe@FreeBSD.org 228744bfb21SJohn Baldwinand is based on the 229744bfb21SJohn Baldwin.Ox 230744bfb21SJohn Baldwinmanual page written by 231744bfb21SJohn Baldwin.An David Gwynne Aq Mt dlg@openbsd.org . 232