xref: /freebsd/share/man/man4/wg.4 (revision ffc4f93e960d38b6f70d59409127f7562e40f916)
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
64*ffc4f93eSBenedict 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.
124744bfb21SJohn Baldwin.Sh EXAMPLES
125744bfb21SJohn BaldwinCreate a
126744bfb21SJohn Baldwin.Nm
127744bfb21SJohn Baldwininterface and set random private key.
128744bfb21SJohn Baldwin.Bd -literal -offset indent
129744bfb21SJohn Baldwin# ifconfig wg0 create
130744bfb21SJohn Baldwin# wg genkey | wg set wg0 listen-port 54321 private-key /dev/stdin
131744bfb21SJohn Baldwin.Ed
132744bfb21SJohn Baldwin.Pp
133744bfb21SJohn BaldwinRetrieve the associated public key from a
134744bfb21SJohn Baldwin.Nm
135744bfb21SJohn Baldwininterface.
136744bfb21SJohn Baldwin.Bd -literal -offset indent
137744bfb21SJohn Baldwin$ wg show wg0 public-key
138744bfb21SJohn Baldwin.Ed
139744bfb21SJohn Baldwin.Pp
140744bfb21SJohn BaldwinConnect to a specific endpoint using its public-key and set the allowed IP address
141744bfb21SJohn Baldwin.Bd -literal -offset indent
142744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' endpoint 10.0.1.100:54321 allowed-ips 192.168.2.100/32
143744bfb21SJohn Baldwin.Ed
144744bfb21SJohn Baldwin.Pp
145744bfb21SJohn BaldwinRemove a peer
146744bfb21SJohn Baldwin.Bd -literal -offset indent
147744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' remove
148744bfb21SJohn Baldwin.Ed
149744bfb21SJohn Baldwin.Sh DIAGNOSTICS
150744bfb21SJohn BaldwinThe
151744bfb21SJohn Baldwin.Nm
152744bfb21SJohn Baldwininterface supports runtime debugging, which can be enabled with:
153744bfb21SJohn Baldwin.Pp
154744bfb21SJohn Baldwin.D1 Ic ifconfig Cm wg Ns Ar N Cm debug
155744bfb21SJohn Baldwin.Pp
156744bfb21SJohn BaldwinSome common error messages include:
157744bfb21SJohn Baldwin.Bl -diag
158744bfb21SJohn Baldwin.It "Handshake for peer X did not complete after 5 seconds, retrying"
159744bfb21SJohn BaldwinPeer X did not reply to our initiation packet, for example because:
160744bfb21SJohn Baldwin.Bl -bullet
161744bfb21SJohn Baldwin.It
162744bfb21SJohn BaldwinThe peer does not have the local interface configured as a peer.
163744bfb21SJohn BaldwinPeers must be able to mutually authenticate each other.
164744bfb21SJohn Baldwin.It
165744bfb21SJohn BaldwinThe peer endpoint IP address is incorrectly configured.
166744bfb21SJohn Baldwin.It
167744bfb21SJohn BaldwinThere are firewall rules preventing communication between hosts.
168744bfb21SJohn Baldwin.El
169744bfb21SJohn Baldwin.It "Invalid handshake initiation"
170744bfb21SJohn BaldwinThe incoming handshake packet could not be processed.
171744bfb21SJohn BaldwinThis is likely due to the local interface not containing
172744bfb21SJohn Baldwinthe correct public key for the peer.
173744bfb21SJohn Baldwin.It "Invalid initiation MAC"
174744bfb21SJohn BaldwinThe incoming handshake initiation packet had an invalid MAC.
175744bfb21SJohn BaldwinThis is likely because the initiation sender has the wrong public key
176744bfb21SJohn Baldwinfor the handshake receiver.
177744bfb21SJohn Baldwin.It "Packet has unallowed src IP from peer X"
178744bfb21SJohn BaldwinAfter decryption, an incoming data packet has a source IP address that
179744bfb21SJohn Baldwinis not assigned to the allowed IPs of Peer X.
180744bfb21SJohn Baldwin.El
181744bfb21SJohn Baldwin.Sh SEE ALSO
182744bfb21SJohn Baldwin.Xr inet 4 ,
183744bfb21SJohn Baldwin.Xr ip 4 ,
18419c03f4aSGordon Bergling.Xr ipsec 4 ,
185744bfb21SJohn Baldwin.Xr netintro 4 ,
18619c03f4aSGordon Bergling.Xr ovpn 4 ,
187744bfb21SJohn Baldwin.Xr ipf 5 ,
188744bfb21SJohn Baldwin.Xr pf.conf 5 ,
189744bfb21SJohn Baldwin.Xr ifconfig 8 ,
190744bfb21SJohn Baldwin.Xr ipfw 8 ,
191744bfb21SJohn Baldwin.Xr wg 8
192744bfb21SJohn Baldwin.Rs
193744bfb21SJohn Baldwin.%T WireGuard whitepaper
194744bfb21SJohn Baldwin.%U https://www.wireguard.com/papers/wireguard.pdf
195744bfb21SJohn Baldwin.Re
196744bfb21SJohn Baldwin.Sh HISTORY
197744bfb21SJohn BaldwinThe
198744bfb21SJohn Baldwin.Nm
199744bfb21SJohn Baldwindevice driver first appeared in
200001830eaSJohn Baldwin.Fx 13.2 .
201744bfb21SJohn Baldwin.Sh AUTHORS
20219c03f4aSGordon Bergling.An -nosplit
203744bfb21SJohn BaldwinThe
204744bfb21SJohn Baldwin.Nm
20519c03f4aSGordon Berglingdevice driver was written by
206744bfb21SJohn Baldwin.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com ,
207744bfb21SJohn Baldwin.An Matt Dunwoodie Aq Mt ncon@nconroy.net ,
2081dd6f95bSEd Maste.An Kyle Evans Aq Mt kevans@FreeBSD.org ,
209744bfb21SJohn Baldwinand
2101dd6f95bSEd Maste.An Matt Macy Aq Mt mmacy@FreeBSD.org .
211744bfb21SJohn Baldwin.Pp
212744bfb21SJohn BaldwinThis manual page was written by
213744bfb21SJohn Baldwin.An Gordon Bergling Aq Mt gbe@FreeBSD.org
214744bfb21SJohn Baldwinand is based on the
215744bfb21SJohn Baldwin.Ox
216744bfb21SJohn Baldwinmanual page written by
217744bfb21SJohn Baldwin.An David Gwynne Aq Mt dlg@openbsd.org .
218