xref: /dflybsd-src/share/man/man5/wg.conf.5 (revision 7569b845b44e7b650dc8cfeabaa5bb646fb69bff)
1451640b7SAaron LI.\" Copyright (c) 2024 The DragonFly Project.  All rights reserved.
2451640b7SAaron LI.\"
3451640b7SAaron LI.\" Redistribution and use in source and binary forms, with or without
4451640b7SAaron LI.\" modification, are permitted provided that the following conditions
5451640b7SAaron LI.\" are met:
6451640b7SAaron LI.\"
7451640b7SAaron LI.\" 1. Redistributions of source code must retain the above copyright
8451640b7SAaron LI.\"    notice, this list of conditions and the following disclaimer.
9451640b7SAaron LI.\" 2. Redistributions in binary form must reproduce the above copyright
10451640b7SAaron LI.\"    notice, this list of conditions and the following disclaimer in
11451640b7SAaron LI.\"    the documentation and/or other materials provided with the
12451640b7SAaron LI.\"    distribution.
13451640b7SAaron LI.\" 3. Neither the name of The DragonFly Project nor the names of its
14451640b7SAaron LI.\"    contributors may be used to endorse or promote products derived
15451640b7SAaron LI.\"    from this software without specific, prior written permission.
16451640b7SAaron LI.\"
17451640b7SAaron LI.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18451640b7SAaron LI.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19451640b7SAaron LI.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20451640b7SAaron LI.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
21451640b7SAaron LI.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22451640b7SAaron LI.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
23451640b7SAaron LI.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24451640b7SAaron LI.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25451640b7SAaron LI.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26451640b7SAaron LI.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27451640b7SAaron LI.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28451640b7SAaron LI.\" SUCH DAMAGE.
29451640b7SAaron LI.\"
30*7569b845SAaron LI.Dd August 20, 2024
31451640b7SAaron LI.Dt WG.CONF 5
32451640b7SAaron LI.Os
33451640b7SAaron LI.Sh NAME
34451640b7SAaron LI.Nm wg.conf
35451640b7SAaron LI.Nd WireGuard configuration file
36451640b7SAaron LI.Sh SYNOPSIS
37451640b7SAaron LI.Pa /etc/wireguard/ Ns Va ${ifname} Ns .conf
38451640b7SAaron LI.Sh DESCRIPTION
39451640b7SAaron LIThe
40451640b7SAaron LI.Nm
41451640b7SAaron LIfile is used by the WireGuard
42451640b7SAaron LI.Xr rc 8
43451640b7SAaron LIscript to manage a
44451640b7SAaron LI.Xr wg 4
45451640b7SAaron LIinterface.
46451640b7SAaron LIThe file format is very similar to that of the
47451640b7SAaron LI.Xr wg-quick 8
48451640b7SAaron LItool on Linux or
49451640b7SAaron LI.Fx ,
50451640b7SAaron LIbut has necessary differences and minor additions.
51451640b7SAaron LI.Pp
52451640b7SAaron LIThe format is based on INI.
53451640b7SAaron LIBlank lines and comment lines (i.e., the first non-blank character is
54451640b7SAaron LI.Sq #
55451640b7SAaron LIor
56451640b7SAaron LI.Sq \&; )
57451640b7SAaron LIare ignored;
58*7569b845SAaron LIhowever, in-line comments are not allowed.
59451640b7SAaron LIBackslash continuation is supported, so a long line may be split into
60451640b7SAaron LImultiple lines by ending the lines with a backslash
61451640b7SAaron LI.Pq Sq \e .
62451640b7SAaron LIThe section and field names are case-insensitive.
63451640b7SAaron LIThere must be one and only one
64451640b7SAaron LI.Va Interface
65451640b7SAaron LIsection, while there can be zero or more
66451640b7SAaron LI.Va Peer
67451640b7SAaron LIsections.
68451640b7SAaron LI.Pp
69451640b7SAaron LIThe
70451640b7SAaron LI.Va Interface
71451640b7SAaron LIsection may contain the following fields:
72451640b7SAaron LI.Bl -tag -width ".It Description" -offset indent
73451640b7SAaron LI.It Description
74451640b7SAaron LIA description string.
75451640b7SAaron LI.It PrivateKey
76451640b7SAaron LI.Pq required
77451640b7SAaron LIThe base64-encoded private key of the interface.
78451640b7SAaron LI.It ListenPort
79451640b7SAaron LIThe UDP port to listen on.
80451640b7SAaron LIIf not specified, it will be chosen automatically.
81451640b7SAaron LI.It Address
82451640b7SAaron LI.Pq required
83451640b7SAaron LIA comma-separated list of IPv4 or IPv6 addresses (optionally with CIDR masks)
84451640b7SAaron LIto be assigned to the interface.
85451640b7SAaron LIMay be specified multiple times.
86451640b7SAaron LI.\" TODO: uncomment this when ifconfig(8)'s wgcookie is ready ...
87451640b7SAaron LI.\" .It Cookie
88451640b7SAaron LI.\" A 32-bit unsigned integer to mark the packets going through the interface,
89451640b7SAaron LI.\" so that they can be easily manipulated in the kernel, e.g., by
90451640b7SAaron LI.\" .Xr ipfw 4
91451640b7SAaron LI.\" or
92451640b7SAaron LI.\" .Xr pf 4 .
93451640b7SAaron LI.It MTU
94451640b7SAaron LIThe explicit MTU to specify for the interface to override the default value.
95451640b7SAaron LI.It PreUp
96451640b7SAaron LIThe command to be executed by
97451640b7SAaron LI.Xr sh 1
98451640b7SAaron LIbefore bringing up the interface.
99451640b7SAaron LIThe special string
100451640b7SAaron LI.Dq %i
101451640b7SAaron LIwill be expanded to the name of the interface.
102451640b7SAaron LIIf the command execution fails (i.e., a non-zero return value),
103451640b7SAaron LIa warning message will be printed and the configuration procedure
104451640b7SAaron LIwill continue.
105451640b7SAaron LIMay be specified multiple times, in which case the commands are executed
106451640b7SAaron LIin the same order as specified.
107451640b7SAaron LI.It PostUp
108451640b7SAaron LISimilar to the
109451640b7SAaron LI.Va PreUp
110451640b7SAaron LIabove, but the commands will be executed after bringing up the interface.
111451640b7SAaron LIThis is most commonly used to configure custom routes, DNS resolvers,
112451640b7SAaron LIor firewall rules.
113451640b7SAaron LI.It PreDown
114451640b7SAaron LISimilar to the
115451640b7SAaron LI.Va PreUp
116451640b7SAaron LIabove, but the commands will be executed before bringing down the interface.
117451640b7SAaron LI.It PostDown
118451640b7SAaron LISimilar to the
119451640b7SAaron LI.Va PreUp
120451640b7SAaron LIabove, but the commands will be executed after bringing down the interface.
121451640b7SAaron LI.El
122451640b7SAaron LI.Pp
123451640b7SAaron LIThe
124451640b7SAaron LI.Va Peer
125451640b7SAaron LIsection may contain the following fields:
126451640b7SAaron LI.Bl -tag -width ".It PersistentKeepalive" -offset indent
127451640b7SAaron LI.It Enabled
128451640b7SAaron LIIf set to
129451640b7SAaron LI.Dq false
130451640b7SAaron LIor
131451640b7SAaron LI.Dq no ,
132451640b7SAaron LIthe peer is disabled and will be ignored.
133451640b7SAaron LI.It Description
134451640b7SAaron LIA description string.
135451640b7SAaron LI.It PublicKey
136451640b7SAaron LI.Pq required
137451640b7SAaron LIThe base64-encoded public key of the peer.
138451640b7SAaron LI.It PresharedKey
139451640b7SAaron LIThe base64-encoded pre-shared key, which can strengthen the
140451640b7SAaron LIDiffie-Hellman exchange.
141451640b7SAaron LI.It Endpoint
142451640b7SAaron LIThe endpoint address, which may be of formats
143451640b7SAaron LI.Dq domain:port ,
144451640b7SAaron LI.Dq ipv4:port ,
145451640b7SAaron LIor
146451640b7SAaron LI.Dq [ipv6]:port .
147451640b7SAaron LI.Sy Note:
148451640b7SAaron LIAt least one peer in each pair must specify the endpoint address.
149451640b7SAaron LI.It AllowedIPs
150451640b7SAaron LI.Pq required
151451640b7SAaron LIA comma-separated list of IPv4 or IPv6 addresses with CIDR masks,
152451640b7SAaron LIfrom which the incoming traffic to this peer is allowed,
153451640b7SAaron LIand to which the outgoing traffic from this peer is directed.
154451640b7SAaron LIMay be specified multiple times.
155451640b7SAaron LI.It PersistentKeepalive
156451640b7SAaron LIThe interval in seconds of keepalive packets to be sent to the peer,
157451640b7SAaron LIfor the purpose of keeping a stateful firewall or NAT mapping valid
158451640b7SAaron LIpersistently.
159451640b7SAaron LIIf unspecified or set to
160451640b7SAaron LI.Dq 0
161451640b7SAaron LIor
162451640b7SAaron LI.Dq off ,
163451640b7SAaron LIthis function is disabled.
164451640b7SAaron LI.El
165451640b7SAaron LI.Pp
166451640b7SAaron LI.Sy Note:
167451640b7SAaron LIThe WireGuard
168451640b7SAaron LI.Xr rc 8
169451640b7SAaron LIscript would not add/delete routes according to the peer's allowed IPs,
170451640b7SAaron LIbecause
171451640b7SAaron LI.Dx
172451640b7SAaron LIcurrently doesn't support multiple routing tables (or FIBs),
173451640b7SAaron LIwithout which it is hard to reliably generate the correct routes,
174451640b7SAaron LIespecially to override the default routes.
175451640b7SAaron LITherefore, users should manually determine the routes and
176451640b7SAaron LImanage them with the
177451640b7SAaron LI.Va PostUp
178451640b7SAaron LIand
179451640b7SAaron LI.Va PreDown
180451640b7SAaron LIhooks.
181451640b7SAaron LI.Sh FILES
182451640b7SAaron LI.Bl -tag -width "/etc/wireguard/${ifname}.conf" -compat
183451640b7SAaron LI.It Pa /etc/wireguard/ Ns Va ${ifname} Ns .conf
184451640b7SAaron LIThe configuration file for
185451640b7SAaron LI.Xr wg 4
186451640b7SAaron LIinterface named
187451640b7SAaron LI.Va ${ifname} .
188451640b7SAaron LI.It Pa /etc/rc.d/wg
189451640b7SAaron LIThe WireGuard
190451640b7SAaron LI.Xr rc 8
191451640b7SAaron LIscript.
192451640b7SAaron LI.El
193451640b7SAaron LI.Sh EXAMPLES
194451640b7SAaron LI.Ss Server Configuration
195451640b7SAaron LIThis example sets up a WireGuard peer as the server,
196451640b7SAaron LIto which the other peers (i.e., clients) can connect.
197451640b7SAaron LIThe allowed peers are specified with their public keys.
198451640b7SAaron LINote that we use
199451640b7SAaron LI.Dq /24
200451640b7SAaron LIand
201451640b7SAaron LI.Dq /64
202451640b7SAaron LIfor the interface's addresses, but use
203451640b7SAaron LI.Dq /32
204451640b7SAaron LIand
205451640b7SAaron LI.Dq /128
206451640b7SAaron LIfor the peers' allowed IPs.
207451640b7SAaron LIIn this way, with IP forwarding enabled, the server peer acts like
208451640b7SAaron LIan LAN switch and then all peers can communicate with each other.
209451640b7SAaron LI.Bd -literal -offset indent
210451640b7SAaron LI[Interface]
211451640b7SAaron LIPrivateKey = <private-key>
212451640b7SAaron LIAddress = 10.6.66.1/24
213451640b7SAaron LIAddress = fc00:6:66::1/64
214451640b7SAaron LIListenPort = 6666
215451640b7SAaron LIPostUp = sysctl net.inet.ip.forwarding=1
216451640b7SAaron LIPostUp = sysctl net.inet6.ip6.forwarding=1
217451640b7SAaron LI
218451640b7SAaron LI[Peer]
219451640b7SAaron LIDescription = my peer #1
220451640b7SAaron LIPublicKey = <public-key>
221451640b7SAaron LIAllowedIPs = 10.6.66.2/32, fc00:6:66::2/128
222451640b7SAaron LI
223451640b7SAaron LI[Peer]
224451640b7SAaron LIEnabled = false
225451640b7SAaron LIDescription = my peer #2
226451640b7SAaron LIPublicKey = <public-key>
227451640b7SAaron LIAllowedIPs = 10.6.66.3/32
228451640b7SAaron LI.Ed
229451640b7SAaron LI.Ss Client Configuration
230451640b7SAaron LIThe following example configures a WireGuard peer that connects to
231451640b7SAaron LIthe above server, which is assumed to have an address of
232451640b7SAaron LI.Dq wg.example.com .
233451640b7SAaron LINote that the peer's allowed IPs must be the LAN networks (e.g.,
234451640b7SAaron LI.Dq 10.6.66.0/24 )
235451640b7SAaron LIinstead of the specific IP addresses of the server peer (e.g.,
236451640b7SAaron LI.Dq 10.6.66.1/32 ) ;
237451640b7SAaron LIin this way, the system will auto-configure the routes
238451640b7SAaron LIfor such directly connected networks.
239451640b7SAaron LIIn addition, the persistent keepalive function is enabled to make
240451640b7SAaron LIthis peer always try to keep the connection, so that other peers
241451640b7SAaron LIcan connect to this peer anytime.
242451640b7SAaron LI.Bd -literal -offset indent
243451640b7SAaron LI[Interface]
244451640b7SAaron LIPrivateKey = <private-key>
245451640b7SAaron LIAddress = 10.6.66.2/24, fc00:6:66::2/64
246451640b7SAaron LI
247451640b7SAaron LI[Peer]
248451640b7SAaron LIPublicKey = <public-key>
249451640b7SAaron LIEndpoint = wg.example.com:6666
250451640b7SAaron LIAllowedIPs = 10.6.66.0/24
251451640b7SAaron LIAllowedIPs = fc00:6:66::/64
252451640b7SAaron LIPersistentKeepalive = 25
253451640b7SAaron LI.Ed
254451640b7SAaron LI.Pp
255451640b7SAaron LIThe following example configures a WireGuard peer that forwards all its
256451640b7SAaron LIIPv4 traffic to the other peer, which must have NAT configured,
257451640b7SAaron LIe.g., by using
258451640b7SAaron LI.Xr pf 4 .
259451640b7SAaron LIThe whole IPv4 network (i.e.,
260451640b7SAaron LI.Dq 0.0.0.0/0 )
261451640b7SAaron LIis split into
262451640b7SAaron LI.Dq 0.0.0.0/1
263451640b7SAaron LIand
264451640b7SAaron LI.Dq 128.0.0.0/1 ,
265451640b7SAaron LIso that the existing default route is kept intact.
266451640b7SAaron LI.Bd -literal -offset indent
267451640b7SAaron LI[Interface]
268451640b7SAaron LIPrivateKey = <private-key>
269451640b7SAaron LIAddress = 10.6.66.2/24
270451640b7SAaron LIPostUp = route add -host <peer-addr> \e
271451640b7SAaron LI	$(route get -inet default | awk '/gateway:/ { print $2 }')
272451640b7SAaron LIPostUp = route add -net 0.0.0.0/1 -interface %i
273451640b7SAaron LIPostUp = route add -net 128.0.0.0/1 -interface %i
274451640b7SAaron LIPreDown = route delete -host <peer-addr>
275451640b7SAaron LIPreDown = route delete -net 0.0.0.0/1
276451640b7SAaron LIPreDown = route delete -net 128.0.0.0/1
277451640b7SAaron LI
278451640b7SAaron LI[Peer]
279451640b7SAaron LIPublicKey = <public-key>
280451640b7SAaron LIEndpoint = <peer-addr>:<peer-port>
281451640b7SAaron LIAllowedIPs = 0.0.0.0/0
282451640b7SAaron LIPersistentKeepalive = 25
283451640b7SAaron LI.Ed
284451640b7SAaron LI.Ss Command-line Usage
285451640b7SAaron LISuppose the
286451640b7SAaron LI.Xr wg 4
287451640b7SAaron LIinterface is called
288451640b7SAaron LI.Sy mywg ,
289451640b7SAaron LIand its
290451640b7SAaron LI.Nm
291451640b7SAaron LIconfiguration file has been already prepared.
292451640b7SAaron LITo create and start the interface:
293451640b7SAaron LI.Pp
294451640b7SAaron LI.Dl $ /etc/rc.d/wg onestart mywg
295451640b7SAaron LI.Pp
296451640b7SAaron LIwhich is equivalent to
297451640b7SAaron LI.Ql wg-quick up mywg .
298451640b7SAaron LI.Pp
299451640b7SAaron LITo stop and destroy the interface:
300451640b7SAaron LI.Pp
301451640b7SAaron LI.Dl $ /etc/rc.d/wg onestop mywg
302451640b7SAaron LI.Pp
303451640b7SAaron LIwhich is equivalent to
304451640b7SAaron LI.Ql wg-quick down mywg .
305451640b7SAaron LI.Sh SEE ALSO
306451640b7SAaron LI.Xr wg 4 ,
307451640b7SAaron LI.Xr rc.conf 5 ,
308451640b7SAaron LI.Xr ifconfig 8
309451640b7SAaron LI.Sh HISTORY
310451640b7SAaron LIThe WireGuard
311451640b7SAaron LI.Xr rc 8
312451640b7SAaron LIscript was written by
313451640b7SAaron LI.An Aaron LI Aq Mt aly@aaronly.me
314451640b7SAaron LIand appeared in
315451640b7SAaron LI.Dx 6.5 .
316451640b7SAaron LI.Sh AUTHORS
317451640b7SAaron LI.An -nosplit
318451640b7SAaron LIThis manual page was written by
319451640b7SAaron LI.An Aaron LI Aq Mt aly@aaronly.me .
320