xref: /freebsd/share/man/man4/wg.4 (revision 001830ea7aaf2f7de7afe85741f9662d9571e1ee)
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.\"
26744bfb21SJohn Baldwin.\" $FreeBSD$
27744bfb21SJohn Baldwin.\"
28*001830eaSJohn Baldwin.Dd November 11, 2022
29744bfb21SJohn Baldwin.Dt WG 4
30744bfb21SJohn Baldwin.Os
31744bfb21SJohn Baldwin.Sh NAME
32744bfb21SJohn Baldwin.Nm wg
3319c03f4aSGordon Bergling.Nd "WireGuard protocol driver"
34744bfb21SJohn Baldwin.Sh SYNOPSIS
35744bfb21SJohn BaldwinTo load the driver as a module at boot time, place the following line in
36744bfb21SJohn Baldwin.Xr loader.conf 5 :
37744bfb21SJohn Baldwin.Bd -literal -offset indent
38744bfb21SJohn Baldwinif_wg_load="YES"
39744bfb21SJohn Baldwin.Ed
40744bfb21SJohn Baldwin.Sh DESCRIPTION
41744bfb21SJohn BaldwinThe
42744bfb21SJohn Baldwin.Nm
43744bfb21SJohn Baldwindriver provides Virtual Private Network (VPN) interfaces for the secure
44744bfb21SJohn Baldwinexchange of layer 3 traffic with other WireGuard peers using the WireGuard
45744bfb21SJohn Baldwinprotocol.
46744bfb21SJohn Baldwin.Pp
47744bfb21SJohn BaldwinA
48744bfb21SJohn Baldwin.Nm
4919c03f4aSGordon Berglinginterface recognizes one or more peers, establishes a secure tunnel with
50744bfb21SJohn Baldwineach on demand, and tracks each peer's UDP endpoint for exchanging encrypted
51744bfb21SJohn Baldwintraffic with.
52744bfb21SJohn Baldwin.Pp
53744bfb21SJohn BaldwinThe interfaces can be created at runtime using the
54744bfb21SJohn Baldwin.Ic ifconfig Cm wg Ns Ar N Cm create
55744bfb21SJohn Baldwincommand.
56744bfb21SJohn BaldwinThe interface itself can be configured with
57744bfb21SJohn Baldwin.Xr wg 8 .
58744bfb21SJohn Baldwin.Pp
59744bfb21SJohn BaldwinThe following glossary provides a brief overview of WireGuard
60744bfb21SJohn Baldwinterminology:
61744bfb21SJohn Baldwin.Bl -tag -width indent -offset 3n
62744bfb21SJohn Baldwin.It Peer
63744bfb21SJohn BaldwinPeers exchange IPv4 or IPv6 traffic over secure tunnels.
64744bfb21SJohn BaldwinEach
65744bfb21SJohn Baldwin.Nm
66744bfb21SJohn Baldwininterface may be configured to recognise one or more peers.
67744bfb21SJohn Baldwin.It Key
68744bfb21SJohn BaldwinEach peer uses its private key and corresponding public key to
69744bfb21SJohn Baldwinidentify itself to others.
70744bfb21SJohn BaldwinA peer configures a
71744bfb21SJohn Baldwin.Nm
72744bfb21SJohn Baldwininterface with its own private key and with the public keys of its peers.
73744bfb21SJohn Baldwin.It Pre-shared key
74744bfb21SJohn BaldwinIn addition to the public keys, each peer pair may be configured with a
75744bfb21SJohn Baldwinunique pre-shared symmetric key.
76744bfb21SJohn BaldwinThis is used in their handshake to guard against future compromise of the
7719c03f4aSGordon Berglingpeers' encrypted tunnel if an attack on their
78744bfb21SJohn BaldwinDiffie-Hellman exchange becomes feasible.
79744bfb21SJohn BaldwinIt is optional, but recommended.
8019c03f4aSGordon Bergling.It Allowed IP addresses
81744bfb21SJohn BaldwinA single
82744bfb21SJohn Baldwin.Nm
83744bfb21SJohn Baldwininterface may maintain concurrent tunnels connecting diverse networks.
84744bfb21SJohn BaldwinThe interface therefore implements rudimentary routing and reverse-path
85744bfb21SJohn Baldwinfiltering functions for its tunneled traffic.
8619c03f4aSGordon BerglingThese functions reference a set of allowed IP address ranges configured
8719c03f4aSGordon Berglingagainst each peer.
88744bfb21SJohn Baldwin.Pp
89744bfb21SJohn BaldwinThe interface will route outbound tunneled traffic to the peer configured
90744bfb21SJohn Baldwinwith the most specific matching allowed IP address range, or drop it
91744bfb21SJohn Baldwinif no such match exists.
92744bfb21SJohn Baldwin.Pp
93744bfb21SJohn BaldwinThe interface will accept tunneled traffic only from the peer
94744bfb21SJohn Baldwinconfigured with the most specific matching allowed IP address range
95744bfb21SJohn Baldwinfor the incoming traffic, or drop it if no such match exists.
96744bfb21SJohn BaldwinThat is, tunneled traffic routed to a given peer cannot return through
97744bfb21SJohn Baldwinanother peer of the same
98744bfb21SJohn Baldwin.Nm
99744bfb21SJohn Baldwininterface.
10019c03f4aSGordon BerglingThis ensures that peers cannot spoof one another's traffic.
101744bfb21SJohn Baldwin.It Handshake
102744bfb21SJohn BaldwinTwo peers handshake to mutually authenticate each other and to
103744bfb21SJohn Baldwinestablish a shared series of secret ephemeral encryption keys.
10419c03f4aSGordon BerglingEither peer may initiate a handshake.
105744bfb21SJohn BaldwinHandshakes occur only when there is traffic to send, and recur every
106744bfb21SJohn Baldwintwo minutes during transfers.
107744bfb21SJohn Baldwin.It Connectionless
108744bfb21SJohn BaldwinDue to the handshake behavior, there is no connected or disconnected
109744bfb21SJohn Baldwinstate.
110744bfb21SJohn Baldwin.El
111744bfb21SJohn Baldwin.Ss Keys
112744bfb21SJohn BaldwinPrivate keys for WireGuard can be generated from any sufficiently
113744bfb21SJohn Baldwinsecure random source.
114744bfb21SJohn BaldwinThe Curve25519 keys and the pre-shared keys are both 32 bytes
115744bfb21SJohn Baldwinlong and are commonly encoded in base64 for ease of use.
116744bfb21SJohn Baldwin.Pp
117744bfb21SJohn BaldwinKeys can be generated with
118744bfb21SJohn Baldwin.Xr wg 8
119744bfb21SJohn Baldwinas follows:
120744bfb21SJohn Baldwin.Pp
121744bfb21SJohn Baldwin.Dl $ wg genkey
122744bfb21SJohn Baldwin.Pp
123744bfb21SJohn BaldwinAlthough a valid Curve25519 key must have 5 bits set to
124744bfb21SJohn Baldwinspecific values, this is done by the interface and so it
125744bfb21SJohn Baldwinwill accept any random 32-byte base64 string.
126744bfb21SJohn Baldwin.Sh EXAMPLES
127744bfb21SJohn BaldwinCreate a
128744bfb21SJohn Baldwin.Nm
129744bfb21SJohn Baldwininterface and set random private key.
130744bfb21SJohn Baldwin.Bd -literal -offset indent
131744bfb21SJohn Baldwin# ifconfig wg0 create
132744bfb21SJohn Baldwin# wg genkey | wg set wg0 listen-port 54321 private-key /dev/stdin
133744bfb21SJohn Baldwin.Ed
134744bfb21SJohn Baldwin.Pp
135744bfb21SJohn BaldwinRetrieve the associated public key from a
136744bfb21SJohn Baldwin.Nm
137744bfb21SJohn Baldwininterface.
138744bfb21SJohn Baldwin.Bd -literal -offset indent
139744bfb21SJohn Baldwin$ wg show wg0 public-key
140744bfb21SJohn Baldwin.Ed
141744bfb21SJohn Baldwin.Pp
142744bfb21SJohn BaldwinConnect to a specific endpoint using its public-key and set the allowed IP address
143744bfb21SJohn Baldwin.Bd -literal -offset indent
144744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' endpoint 10.0.1.100:54321 allowed-ips 192.168.2.100/32
145744bfb21SJohn Baldwin.Ed
146744bfb21SJohn Baldwin.Pp
147744bfb21SJohn BaldwinRemove a peer
148744bfb21SJohn Baldwin.Bd -literal -offset indent
149744bfb21SJohn Baldwin# wg set wg0 peer '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' remove
150744bfb21SJohn Baldwin.Ed
151744bfb21SJohn Baldwin.Sh DIAGNOSTICS
152744bfb21SJohn BaldwinThe
153744bfb21SJohn Baldwin.Nm
154744bfb21SJohn Baldwininterface supports runtime debugging, which can be enabled with:
155744bfb21SJohn Baldwin.Pp
156744bfb21SJohn Baldwin.D1 Ic ifconfig Cm wg Ns Ar N Cm debug
157744bfb21SJohn Baldwin.Pp
158744bfb21SJohn BaldwinSome common error messages include:
159744bfb21SJohn Baldwin.Bl -diag
160744bfb21SJohn Baldwin.It "Handshake for peer X did not complete after 5 seconds, retrying"
161744bfb21SJohn BaldwinPeer X did not reply to our initiation packet, for example because:
162744bfb21SJohn Baldwin.Bl -bullet
163744bfb21SJohn Baldwin.It
164744bfb21SJohn BaldwinThe peer does not have the local interface configured as a peer.
165744bfb21SJohn BaldwinPeers must be able to mutually authenticate each other.
166744bfb21SJohn Baldwin.It
167744bfb21SJohn BaldwinThe peer endpoint IP address is incorrectly configured.
168744bfb21SJohn Baldwin.It
169744bfb21SJohn BaldwinThere are firewall rules preventing communication between hosts.
170744bfb21SJohn Baldwin.El
171744bfb21SJohn Baldwin.It "Invalid handshake initiation"
172744bfb21SJohn BaldwinThe incoming handshake packet could not be processed.
173744bfb21SJohn BaldwinThis is likely due to the local interface not containing
174744bfb21SJohn Baldwinthe correct public key for the peer.
175744bfb21SJohn Baldwin.It "Invalid initiation MAC"
176744bfb21SJohn BaldwinThe incoming handshake initiation packet had an invalid MAC.
177744bfb21SJohn BaldwinThis is likely because the initiation sender has the wrong public key
178744bfb21SJohn Baldwinfor the handshake receiver.
179744bfb21SJohn Baldwin.It "Packet has unallowed src IP from peer X"
180744bfb21SJohn BaldwinAfter decryption, an incoming data packet has a source IP address that
181744bfb21SJohn Baldwinis not assigned to the allowed IPs of Peer X.
182744bfb21SJohn Baldwin.El
183744bfb21SJohn Baldwin.Sh SEE ALSO
184744bfb21SJohn Baldwin.Xr inet 4 ,
185744bfb21SJohn Baldwin.Xr ip 4 ,
18619c03f4aSGordon Bergling.Xr ipsec 4 ,
187744bfb21SJohn Baldwin.Xr netintro 4 ,
18819c03f4aSGordon Bergling.Xr ovpn 4 ,
189744bfb21SJohn Baldwin.Xr ipf 5 ,
190744bfb21SJohn Baldwin.Xr pf.conf 5 ,
191744bfb21SJohn Baldwin.Xr ifconfig 8 ,
192744bfb21SJohn Baldwin.Xr ipfw 8 ,
193744bfb21SJohn Baldwin.Xr wg 8
194744bfb21SJohn Baldwin.Rs
195744bfb21SJohn Baldwin.%T WireGuard whitepaper
196744bfb21SJohn Baldwin.%U https://www.wireguard.com/papers/wireguard.pdf
197744bfb21SJohn Baldwin.Re
198744bfb21SJohn Baldwin.Sh HISTORY
199744bfb21SJohn BaldwinThe
200744bfb21SJohn Baldwin.Nm
201744bfb21SJohn Baldwindevice driver first appeared in
202*001830eaSJohn Baldwin.Fx 13.2 .
203744bfb21SJohn Baldwin.Sh AUTHORS
20419c03f4aSGordon Bergling.An -nosplit
205744bfb21SJohn BaldwinThe
206744bfb21SJohn Baldwin.Nm
20719c03f4aSGordon Berglingdevice driver was written by
208744bfb21SJohn Baldwin.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com ,
209744bfb21SJohn Baldwin.An Matt Dunwoodie Aq Mt ncon@nconroy.net ,
210744bfb21SJohn Baldwinand
211744bfb21SJohn Baldwin.An Kyle Evans Aq Mt kevans@FreeBSD.org .
212744bfb21SJohn Baldwin.Pp
213744bfb21SJohn BaldwinThis manual page was written by
214744bfb21SJohn Baldwin.An Gordon Bergling Aq Mt gbe@FreeBSD.org
215744bfb21SJohn Baldwinand is based on the
216744bfb21SJohn Baldwin.Ox
217744bfb21SJohn Baldwinmanual page written by
218744bfb21SJohn Baldwin.An David Gwynne Aq Mt dlg@openbsd.org .
219