xref: /freebsd/share/man/man4/wg.4 (revision 74ae3f3e33b810248da19004c58b3581cd367843)
1.\" Copyright (c) 2020 Gordon Bergling <gbe@FreeBSD.org>
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.\" $FreeBSD$
25.\"
26.Dd March 12, 2021
27.Dt WG 4
28.Os
29.Sh NAME
30.Nm wg
31.Nd "WireGuard - pseudo-device"
32.Sh SYNOPSIS
33To load the driver as a module at boot time, place the following line in
34.Xr loader.conf 5 :
35.Bd -literal -offset indent
36if_wg_load="YES"
37.Ed
38.Sh DESCRIPTION
39The
40.Nm
41driver provides Virtual Private Network (VPN) interfaces for the secure
42exchange of layer 3 traffic with other WireGuard peers using the WireGuard
43protocol.
44.Pp
45A
46.Nm
47interface recognises one or more peers, establishes a secure tunnel with
48each on demand, and tracks each peer's UDP endpoint for exchanging encrypted
49traffic with.
50.Pp
51The interfaces can be created at runtime using the
52.Ic ifconfig Cm wg Ns Ar N Cm create
53command.
54The interface itself can be configured with
55.Xr ifconfig 8 .
56.Pp
57The following parameters are available:
58.Bl -tag -width indent
59.It Cm listen-port
60The listing port of the
61.Nm
62interface.
63.It Cm public-key
64The public key of the
65.Nm
66interface.
67.It Cm private-key
68The private key of the
69.Nm
70interface.
71.It Cm preshared-key
72Defines a pre-shared key for the
73.Nm
74interface.
75.It Cm allowed-ips
76A list of allowed IP addresses.
77.It Cm endpoint
78The IP address of the WiredGuard to connect to.
79.It Cm peers
80A list of peering IP addresses to connect to.
81.It Cm persistent-keepalive-interval
82Interval, in seconds, at which to send persistent keepalive packets.
83.El
84.Pp
85The
86.Nm
87interfaces support the following
88.Xr ioctl 2 Ns s :
89.Bl -tag -width Ds -offset indent
90.It Dv SIOCSWG Fa "struct  wg_device_io *"
91Set the device configuration.
92.It Dv SIOCGWG Fa "struct wg_device_io *"
93Get the device configuration.
94.El
95.Pp
96The following glossary provides a brief overview of WireGuard
97terminology:
98.Bl -tag -width indent -offset 3n
99.It Peer
100Peers exchange IPv4 or IPv6 traffic over secure tunnels.
101Each
102.Nm
103interface may be configured to recognise one or more peers.
104.It Key
105Each peer uses its private key and corresponding public key to
106identify itself to others.
107A peer configures a
108.Nm
109interface with its own private key and with the public keys of its peers.
110.It Pre-shared key
111In addition to the public keys, each peer pair may be configured with a
112unique pre-shared symmetric key.
113This is used in their handshake to guard against future compromise of the
114peers' encrypted tunnel if a quantum-computational attack on their
115Diffie-Hellman exchange becomes feasible.
116It is optional, but recommended.
117.It Allowed IPs
118A single
119.Nm
120interface may maintain concurrent tunnels connecting diverse networks.
121The interface therefore implements rudimentary routing and reverse-path
122filtering functions for its tunneled traffic.
123These functions reference a set of allowed IP ranges configured against
124each peer.
125.Pp
126The interface will route outbound tunneled traffic to the peer configured
127with the most specific matching allowed IP address range, or drop it
128if no such match exists.
129.Pp
130The interface will accept tunneled traffic only from the peer
131configured with the most specific matching allowed IP address range
132for the incoming traffic, or drop it if no such match exists.
133That is, tunneled traffic routed to a given peer cannot return through
134another peer of the same
135.Nm
136interface.
137This ensures that peers cannot spoof another's traffic.
138.It Handshake
139Two peers handshake to mutually authenticate each other and to
140establish a shared series of secret ephemeral encryption keys.
141Any peer may initiate a handshake.
142Handshakes occur only when there is traffic to send, and recur every
143two minutes during transfers.
144.It Connectionless
145Due to the handshake behavior, there is no connected or disconnected
146state.
147.El
148.Ss Keys
149Private keys for WireGuard can be generated from any sufficiently
150secure random source.
151The Curve25519 keys and the pre-shared keys are both 32 bytes
152long and are commonly encoded in base64 for ease of use.
153.Pp
154Keys can be generated with
155.Xr openssl 1
156as follows:
157.Pp
158.Dl $ openssl rand -base64 32
159.Pp
160Although a valid Curve25519 key must have 5 bits set to
161specific values, this is done by the interface and so it
162will accept any random 32-byte base64 string.
163.Pp
164When an interface has a private key set with
165.Nm public-key ,
166the corresponding
167public key is shown in the status output of the interface:
168.Bd -literal -offset indent
169# ifconfig wg0 | grep public-key
170       public-key:  7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=
171.Ed
172.Sh EXAMPLES
173Create a
174.Nm
175interface and set random private key.
176.Bd -literal -offset indent
177# ifconfig wg0 create listen-port 54321 private-key `openssl rand -base64 32`
178.Ed
179.Pp
180Retrieve the associated public key from a
181.Nm
182interface.
183.Bd -literal -offset indent
184$ ifconfig wg0 | awk '/public-key/ { print $2 }'`
185.Ed
186.Pp
187Connect to a specific endpoint using its public-key and set the allowed IP address
188.Bd -literal -offset indent
189# ifconfig wg0 peer public-key '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw=' endpoint 10.0.1.100:54321 allowed-ips 192.168.2.100/32
190.Ed
191.Pp
192Remove a peer
193.Bd -literal -offset indent
194# ifconfig wg0 -peer public-key '7lWtsDdqaGB3EY9WNxRN3hVaHMtu1zXw71+bOjNOVUw='
195.Ed
196.Sh DIAGNOSTICS
197The
198.Nm
199interface supports runtime debugging, which can be enabled with:
200.Pp
201.D1 Ic ifconfig Cm wg Ns Ar N Cm debug
202.Pp
203Some common error messages include:
204.Bl -diag
205.It "Handshake for peer X did not complete after 5 seconds, retrying"
206Peer X did not reply to our initiation packet, for example because:
207.Bl -bullet
208.It
209The peer does not have the local interface configured as a peer.
210Peers must be able to mutually authenticate each other.
211.It
212The peer endpoint IP address is incorrectly configured.
213.It
214There are firewall rules preventing communication between hosts.
215.El
216.It "Invalid handshake initiation"
217The incoming handshake packet could not be processed.
218This is likely due to the local interface not containing
219the correct public key for the peer.
220.It "Invalid initiation MAC"
221The incoming handshake initiation packet had an invalid MAC.
222This is likely because the initiation sender has the wrong public key
223for the handshake receiver.
224.It "Packet has unallowed src IP from peer X"
225After decryption, an incoming data packet has a source IP address that
226is not assigned to the allowed IPs of Peer X.
227.El
228.Sh SEE ALSO
229.Xr inet 4 ,
230.Xr ip 4 ,
231.Xr netintro 4 ,
232.Xr ipf 5 ,
233.Xr pf.conf 5 ,
234.Xr ifconfig 8 ,
235.Xr ipfw 8
236.Rs
237.%T WireGuard whitepaper
238.%U https://www.wireguard.com/papers/wireguard.pdf
239.Re
240.Sh HISTORY
241The
242.Nm
243device driver first appeared in
244.Fx 13.0 .
245.Sh AUTHORS
246The
247.Nm
248device driver written by
249.An Jason A. Donenfeld Aq Mt Jason@zx2c4.com ,
250.An Matt Dunwoodie Aq Mt ncon@nconroy.net ,
251and
252.An Kyle Evans Aq Mt kevans@FreeBSD.org .
253.Pp
254This manual page was written by
255.An Gordon Bergling Aq Mt gbe@FreeBSD.org
256and is based on the
257.Ox
258manual page written by
259.An David Gwynne Aq Mt dlg@openbsd.org .
260