Try harder to connect to unreachable nodes.
[tinc] / doc / tinc.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename tinc.info
4 @settitle tinc Manual
5 @setchapternewpage odd
6 @c %**end of header
7
8 @include tincinclude.texi
9
10 @ifinfo
11 @dircategory Networking tools
12 @direntry
13 * tinc: (tinc).              The tinc Manual.
14 @end direntry
15
16 This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon.
17
18 Copyright @copyright{} 1998-2018 Ivo Timmermans,
19 Guus Sliepen <guus@@tinc-vpn.org> and
20 Wessel Dankers <wsl@@tinc-vpn.org>.
21
22 Permission is granted to make and distribute verbatim copies of this
23 manual provided the copyright notice and this permission notice are
24 preserved on all copies.
25
26 Permission is granted to copy and distribute modified versions of this
27 manual under the conditions for verbatim copying, provided that the
28 entire resulting derived work is distributed under the terms of a
29 permission notice identical to this one.
30
31 @end ifinfo
32
33 @afourpaper
34 @paragraphindent none
35 @finalout
36
37 @titlepage
38 @title tinc Manual
39 @subtitle Setting up a Virtual Private Network with tinc
40 @author Ivo Timmermans and Guus Sliepen
41
42 @page
43 @vskip 0pt plus 1filll
44 This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon.
45
46 Copyright @copyright{} 1998-2018 Ivo Timmermans,
47 Guus Sliepen <guus@@tinc-vpn.org> and
48 Wessel Dankers <wsl@@tinc-vpn.org>.
49
50 Permission is granted to make and distribute verbatim copies of this
51 manual provided the copyright notice and this permission notice are
52 preserved on all copies.
53
54 Permission is granted to copy and distribute modified versions of this
55 manual under the conditions for verbatim copying, provided that the
56 entire resulting derived work is distributed under the terms of a
57 permission notice identical to this one.
58
59 @end titlepage
60
61 @ifnottex
62 @c ==================================================================
63 @node Top
64 @top Top
65
66 @menu
67 * Introduction::
68 * Preparations::
69 * Installation::
70 * Configuration::
71 * Running tinc::
72 * Controlling tinc::
73 * Invitations::
74 * Technical information::
75 * Platform specific information::
76 * About us::
77 * Concept Index::               All used terms explained
78 @end menu
79 @end ifnottex
80
81 @c ==================================================================
82 @node    Introduction
83 @chapter Introduction
84
85 @cindex tinc
86 Tinc is a Virtual Private Network (VPN) daemon that uses tunneling and
87 encryption to create a secure private network between hosts on the
88 Internet.
89
90 Because the tunnel appears to the IP level network code as a normal
91 network device, there is no need to adapt any existing software.
92 The encrypted tunnels allows VPN sites to share information with each other
93 over the Internet without exposing any information to others.
94
95 This document is the manual for tinc.  Included are chapters on how to
96 configure your computer to use tinc, as well as the configuration
97 process of tinc itself.
98
99 @menu
100 * Virtual Private Networks::
101 * tinc::                        About tinc
102 * Supported platforms::
103 @end menu
104
105 @c ==================================================================
106 @node    Virtual Private Networks
107 @section Virtual Private Networks
108
109 @cindex VPN
110 A Virtual Private Network or VPN is a network that can only be accessed
111 by a few elected computers that participate.  This goal is achievable in
112 more than just one way.
113
114 @cindex private
115 Private networks can consist of a single stand-alone Ethernet LAN.  Or
116 even two computers hooked up using a null-modem cable.  In these cases,
117 it is
118 obvious that the network is @emph{private}, no one can access it from the
119 outside.  But if your computers are linked to the Internet, the network
120 is not private anymore, unless one uses firewalls to block all private
121 traffic.  But then, there is no way to send private data to trusted
122 computers on the other end of the Internet.
123
124 @cindex virtual
125 This problem can be solved by using @emph{virtual} networks.  Virtual
126 networks can live on top of other networks, but they use encapsulation to
127 keep using their private address space so they do not interfere with
128 the Internet.  Mostly, virtual networks appear like a single LAN, even though
129 they can span the entire world.  But virtual networks can't be secured
130 by using firewalls, because the traffic that flows through it has to go
131 through the Internet, where other people can look at it.
132
133 As is the case with either type of VPN, anybody could eavesdrop.  Or
134 worse, alter data.  Hence it's probably advisable to encrypt the data
135 that flows over the network.
136
137 When one introduces encryption, we can form a true VPN.  Other people may
138 see encrypted traffic, but if they don't know how to decipher it (they
139 need to know the key for that), they cannot read the information that flows
140 through the VPN.  This is what tinc was made for.
141
142
143 @c ==================================================================
144 @node    tinc
145 @section tinc
146
147 @cindex vpnd
148 I really don't quite remember what got us started, but it must have been
149 Guus' idea.  He wrote a simple implementation (about 50 lines of C) that
150 used the ethertap device that Linux knows of since somewhere
151 about kernel 2.1.60.  It didn't work immediately and he improved it a
152 bit.  At this stage, the project was still simply called "vpnd".
153
154 Since then, a lot has changed---to say the least.
155
156 @cindex tincd
157 Tinc now supports encryption, it consists of a single daemon (tincd) for
158 both the receiving and sending end, it has become largely
159 runtime-configurable---in short, it has become a full-fledged
160 professional package.
161
162 @cindex traditional VPNs
163 @cindex scalability
164 Tinc also allows more than two sites to connect to each other and form a single VPN.
165 Traditionally VPNs are created by making tunnels, which only have two endpoints.
166 Larger VPNs with more sites are created by adding more tunnels.
167 Tinc takes another approach: only endpoints are specified,
168 the software itself will take care of creating the tunnels.
169 This allows for easier configuration and improved scalability.
170
171 A lot can---and will be---changed. We have a number of things that we would like to
172 see in the future releases of tinc.  Not everything will be available in
173 the near future.  Our first objective is to make tinc work perfectly as
174 it stands, and then add more advanced features.
175
176 Meanwhile, we're always open-minded towards new ideas.  And we're
177 available too.
178
179
180 @c ==================================================================
181 @node    Supported platforms
182 @section Supported platforms
183
184 @cindex platforms
185 Tinc has been verified to work under Linux, FreeBSD, OpenBSD, NetBSD, MacOS/X (Darwin), Solaris, and Windows,
186 with various hardware architectures.  These are some of the platforms
187 that are supported by the universal tun/tap device driver or other virtual network device drivers.
188 Without such a driver, tinc will most
189 likely compile and run, but it will not be able to send or receive data
190 packets.
191
192 @cindex release
193 For an up to date list of supported platforms, please check the list on
194 our website:
195 @uref{https://www.tinc-vpn.org/platforms/}.
196
197 @c
198 @c
199 @c
200 @c
201 @c
202 @c
203 @c       Preparing your system
204 @c
205 @c
206 @c
207 @c
208 @c
209
210 @c ==================================================================
211 @node    Preparations
212 @chapter Preparations
213
214 This chapter contains information on how to prepare your system to
215 support tinc.
216
217 @menu
218 * Configuring the kernel::
219 * Libraries::
220 @end menu
221
222
223 @c ==================================================================
224 @node    Configuring the kernel
225 @section Configuring the kernel
226
227 @menu
228 * Configuration of Linux kernels::
229 * Configuration of FreeBSD kernels::
230 * Configuration of OpenBSD kernels::
231 * Configuration of NetBSD kernels::
232 * Configuration of Solaris kernels::
233 * Configuration of Darwin (MacOS/X) kernels::
234 * Configuration of Windows::
235 @end menu
236
237
238 @c ==================================================================
239 @node       Configuration of Linux kernels
240 @subsection Configuration of Linux kernels
241
242 @cindex Universal tun/tap
243 For tinc to work, you need a kernel that supports the Universal tun/tap device.
244 Most distributions come with kernels that already support this.
245 Here are the options you have to turn on when configuring a new kernel:
246
247 @example
248 Code maturity level options
249 [*] Prompt for development and/or incomplete code/drivers
250 Network device support
251 <M> Universal tun/tap device driver support
252 @end example
253
254 It's not necessary to compile this driver as a module, even if you are going to
255 run more than one instance of tinc.
256
257 If you decide to build the tun/tap driver as a kernel module, add these lines
258 to @file{/etc/modules.conf}:
259
260 @example
261 alias char-major-10-200 tun
262 @end example
263
264
265 @c ==================================================================
266 @node       Configuration of FreeBSD kernels
267 @subsection Configuration of FreeBSD kernels
268
269 For FreeBSD version 4.1 and higher, tun and tap drivers are included in the default kernel configuration.
270 The tap driver can be loaded with @code{kldload if_tap}, or by adding @code{if_tap_load="YES"} to @file{/boot/loader.conf}.
271
272
273 @c ==================================================================
274 @node       Configuration of OpenBSD kernels
275 @subsection Configuration of OpenBSD kernels
276
277 Recent versions of OpenBSD come with both tun and tap devices enabled in the default kernel configuration.
278
279
280 @c ==================================================================
281 @node       Configuration of NetBSD kernels
282 @subsection Configuration of NetBSD kernels
283
284 For NetBSD version 1.5.2 and higher,
285 the tun driver is included in the default kernel configuration.
286
287 Tunneling IPv6 may not work on NetBSD's tun device.
288
289
290 @c ==================================================================
291 @node       Configuration of Solaris kernels
292 @subsection Configuration of Solaris kernels
293
294 For Solaris 8 (SunOS 5.8) and higher,
295 the tun driver may or may not be included in the default kernel configuration.
296 If it isn't, the source can be downloaded from @uref{http://vtun.sourceforge.net/tun/}.
297 For x86 and sparc64 architectures, precompiled versions can be found at @uref{https://www.monkey.org/~dugsong/fragroute/}.
298 If the @file{net/if_tun.h} header file is missing, install it from the source package.
299
300
301 @c ==================================================================
302 @node       Configuration of Darwin (MacOS/X) kernels
303 @subsection Configuration of Darwin (MacOS/X) kernels
304
305 Tinc on Darwin relies on a tunnel driver for its data acquisition from the kernel.
306 OS X version 10.6.8 and later have a built-in tun driver called "utun".
307 Tinc also supports the driver from @uref{http://tuntaposx.sourceforge.net/},
308 which supports both tun and tap style devices,
309
310 By default, tinc expects the tuntaposx driver to be installed.
311 To use the utun driver, set add @code{Device = utunX} to @file{tinc.conf},
312 where X is the desired number for the utun interface.
313 You can also omit the number, in which case the first free number will be chosen.
314
315
316 @c ==================================================================
317 @node       Configuration of Windows
318 @subsection Configuration of Windows
319
320 You will need to install the latest TAP-Win32 driver from OpenVPN.
321 You can download it from @uref{https://openvpn.net/index.php/open-source/downloads.html}.
322 Using the Network Connections control panel,
323 configure the TAP-Win32 network interface in the same way as you would do from the tinc-up script,
324 as explained in the rest of the documentation.
325
326
327 @c ==================================================================
328 @node    Libraries
329 @section Libraries
330
331 @cindex requirements
332 @cindex libraries
333 Before you can configure or build tinc, you need to have the LibreSSL or OpenSSL, zlib,
334 LZO, curses and readline libraries installed on your system.  If you try to
335 configure tinc without having them installed, configure will give you an error
336 message, and stop.
337
338 @menu
339 * LibreSSL/OpenSSL::
340 * zlib::
341 * LZO::
342 * libcurses::
343 * libreadline::
344 @end menu
345
346
347 @c ==================================================================
348 @node       LibreSSL/OpenSSL
349 @subsection LibreSSL/OpenSSL
350
351 @cindex LibreSSL
352 @cindex OpenSSL
353 For all cryptography-related functions, tinc uses the functions provided
354 by the LibreSSL or the OpenSSL library.
355
356 If this library is not installed, you will get an error when configuring
357 tinc for build.  Support for running tinc with other cryptographic libraries
358 installed @emph{may} be added in the future.
359
360 You can use your operating system's package manager to install this if
361 available.  Make sure you install the development AND runtime versions
362 of this package.
363
364 If your operating system comes neither with LibreSSL or OpenSSL, you have to
365 install one manually.  It is recommended that you get the latest version of
366 LibreSSL from @url{https://www.libressl.org/}.  Instructions on how to
367 configure, build and install this package are included within the package.
368 Please make sure you build development and runtime libraries (which is the
369 default).
370
371 If you installed the LibreSSL or OpenSSL libraries from source, it may be necessary
372 to let configure know where they are, by passing configure one of the
373 --with-openssl-* parameters. Note that you even have to use --with-openssl-* if you
374 are using LibreSSL.
375
376 @example
377 --with-openssl=DIR      LibreSSL/OpenSSL library and headers prefix
378 --with-openssl-include=DIR LibreSSL/OpenSSL headers directory
379                         (Default is OPENSSL_DIR/include)
380 --with-openssl-lib=DIR  LibreSSL/OpenSSL library directory
381                         (Default is OPENSSL_DIR/lib)
382 @end example
383
384
385 @subsubheading License
386
387 @cindex license
388 The complete source code of tinc is covered by the GNU GPL version 2.
389 Since the license under which OpenSSL is distributed is not directly
390 compatible with the terms of the GNU GPL
391 @uref{https://www.openssl.org/support/faq.html#LEGAL2}, we
392 include an exemption to the GPL (see also the file COPYING.README) to allow
393 everyone to create a statically or dynamically linked executable:
394
395 @quotation
396 This program is released under the GPL with the additional exemption
397 that compiling, linking, and/or using OpenSSL is allowed.  You may
398 provide binary packages linked to the OpenSSL libraries, provided that
399 all other requirements of the GPL are met.
400 @end quotation
401
402 Since the LZO library used by tinc is also covered by the GPL,
403 we also present the following exemption:
404
405 @quotation
406 Hereby I grant a special exception to the tinc VPN project
407 (https://www.tinc-vpn.org/) to link the LZO library with the OpenSSL library
408 (https://www.openssl.org).
409
410 Markus F.X.J. Oberhumer
411 @end quotation
412
413
414 @c ==================================================================
415 @node       zlib
416 @subsection zlib
417
418 @cindex zlib
419 For the optional compression of UDP packets, tinc uses the functions provided
420 by the zlib library.
421
422 If this library is not installed, you will get an error when running the
423 configure script.  You can either install the zlib library, or disable support
424 for zlib compression by using the "--disable-zlib" option when running the
425 configure script. Note that if you disable support for zlib, the resulting
426 binary will not work correctly on VPNs where zlib compression is used.
427
428 You can use your operating system's package manager to install this if
429 available.  Make sure you install the development AND runtime versions
430 of this package.
431
432 If you have to install zlib manually, you can get the source code
433 from @url{https://zlib.net/}.  Instructions on how to configure,
434 build and install this package are included within the package.  Please
435 make sure you build development and runtime libraries (which is the
436 default).
437
438
439 @c ==================================================================
440 @node       LZO
441 @subsection LZO
442
443 @cindex LZO
444 Another form of compression is offered using the LZO library.
445
446 If this library is not installed, you will get an error when running the
447 configure script.  You can either install the LZO library, or disable support
448 for LZO compression by using the "--disable-lzo" option when running the
449 configure script. Note that if you disable support for LZO, the resulting
450 binary will not work correctly on VPNs where LZO compression is used.
451
452 You can use your operating system's package manager to install this if
453 available.  Make sure you install the development AND runtime versions
454 of this package.
455
456 If you have to install LZO manually, you can get the source code
457 from @url{https://www.oberhumer.com/opensource/lzo/}.  Instructions on how to configure,
458 build and install this package are included within the package.  Please
459 make sure you build development and runtime libraries (which is the
460 default).
461
462
463 @c ==================================================================
464 @node       libcurses
465 @subsection libcurses
466
467 @cindex libcurses
468 For the "tinc top" command, tinc requires a curses library.
469
470 If this library is not installed, you will get an error when running the
471 configure script.  You can either install a suitable curses library, or disable
472 all functionality that depends on a curses library by using the
473 "--disable-curses" option when running the configure script.
474
475 There are several curses libraries. It is recommended that you install
476 "ncurses" (@url{https://invisible-island.net/ncurses/}),
477 however other curses libraries should also work.
478 In particular, "PDCurses" (@url{https://pdcurses.sourceforge.io/})
479 is recommended if you want to compile tinc for Windows.
480
481 You can use your operating system's package manager to install this if
482 available. Make sure you install the development AND runtime versions
483 of this package.
484
485
486 @c ==================================================================
487 @node       libreadline
488 @subsection libreadline
489
490 @cindex libreadline
491 For the "tinc" command's shell functionality, tinc uses the readline library.
492
493 If this library is not installed, you will get an error when running the
494 configure script.  You can either install a suitable readline library, or
495 disable all functionality that depends on a readline library by using the
496 "--disable-readline" option when running the configure script.
497
498 You can use your operating system's package manager to install this if
499 available.  Make sure you install the development AND runtime versions
500 of this package.
501
502 If you have to install libreadline manually, you can get the source code from
503 @url{https://www.gnu.org/software/readline/}. Instructions on how to configure,
504 build and install this package are included within the package.  Please make
505 sure you build development and runtime libraries (which is the default).
506
507
508 @c
509 @c
510 @c
511 @c      Installing tinc
512 @c
513 @c
514 @c
515 @c
516
517 @c ==================================================================
518 @node    Installation
519 @chapter Installation
520
521 If you use Debian, you may want to install one of the
522 precompiled packages for your system.  These packages are equipped with
523 system startup scripts and sample configurations.
524
525 If you cannot use one of the precompiled packages, or you want to compile tinc
526 for yourself, you can use the source.  The source is distributed under
527 the GNU General Public License (GPL).  Download the source from the
528 @uref{https://www.tinc-vpn.org/download/, download page}.
529
530 Tinc comes in a convenient autoconf/automake package, which you can just
531 treat the same as any other package.  Which is just untar it, type
532 `./configure' and then `make'.
533 More detailed instructions are in the file @file{INSTALL}, which is
534 included in the source distribution.
535
536 @menu
537 * Building and installing tinc::
538 * System files::
539 @end menu
540
541
542 @c ==================================================================
543 @node    Building and installing tinc
544 @section Building and installing tinc
545
546 Detailed instructions on configuring the source, building tinc and installing tinc
547 can be found in the file called @file{INSTALL}.
548
549 @cindex binary package
550 If you happen to have a binary package for tinc for your distribution,
551 you can use the package management tools of that distribution to install tinc.
552 The documentation that comes along with your distribution will tell you how to do that.
553
554 @menu
555 * Darwin (MacOS/X) build environment::
556 * MinGW (Windows) build environment::
557 @end menu
558
559
560 @c ==================================================================
561 @node       Darwin (MacOS/X) build environment
562 @subsection Darwin (MacOS/X) build environment
563
564 In order to build tinc on Darwin, you need to install Xcode from @uref{https://developer.apple.com/xcode/}.
565 It might also help to install a recent version of Fink from @uref{http://www.finkproject.org/}.
566
567 You need to download and install LibreSSL (or OpenSSL) and LZO,
568 either directly from their websites (see @ref{Libraries}) or using Fink.
569
570 @c ==================================================================
571 @node       MinGW (Windows) build environment
572 @subsection MinGW (Windows) build environment
573
574 You will need to install the MinGW environment from @uref{http://www.mingw.org}.
575 You also need to download and install LibreSSL (or OpenSSL) and LZO.
576
577 When tinc is compiled using MinGW it runs natively under Windows,
578 it is not necessary to keep MinGW installed.
579
580 When detaching, tinc will install itself as a service,
581 which will be restarted automatically after reboots.
582
583
584 @c ==================================================================
585 @node    System files
586 @section System files
587
588 Before you can run tinc, you must make sure you have all the needed
589 files on your system.
590
591 @menu
592 * Device files::
593 * Other files::
594 @end menu
595
596
597 @c ==================================================================
598 @node       Device files
599 @subsection Device files
600
601 @cindex device files
602 Most operating systems nowadays come with the necessary device files by default,
603 or they have a mechanism to create them on demand.
604
605 If you use Linux and do not have udev installed,
606 you may need to create the following device file if it does not exist:
607
608 @example
609 mknod -m 600 /dev/net/tun c 10 200
610 @end example
611
612
613 @c ==================================================================
614 @node       Other files
615 @subsection Other files
616
617 @subsubheading @file{/etc/networks}
618
619 You may add a line to @file{/etc/networks} so that your VPN will get a
620 symbolic name.  For example:
621
622 @example
623 myvpn 10.0.0.0
624 @end example
625
626 @subsubheading @file{/etc/services}
627
628 @cindex port numbers
629 You may add this line to @file{/etc/services}.  The effect is that you
630 may supply a @samp{tinc} as a valid port number to some programs.  The
631 number 655 is registered with the IANA.
632
633 @example
634 tinc            655/tcp    TINC
635 tinc            655/udp    TINC
636 #                          Ivo Timmermans <ivo@@tinc-vpn.org>
637 @end example
638
639
640 @c
641 @c
642 @c
643 @c
644 @c         Configuring tinc
645 @c
646 @c
647 @c
648 @c
649
650
651 @c ==================================================================
652 @node    Configuration
653 @chapter Configuration
654
655 @menu
656 * Configuration introduction::
657 * Multiple networks::
658 * How connections work::
659 * Configuration files::
660 * Network interfaces::
661 * Example configuration::
662 @end menu
663
664 @c ==================================================================
665 @node    Configuration introduction
666 @section Configuration introduction
667
668 Before actually starting to configure tinc and editing files,
669 make sure you have read this entire section so you know what to expect.
670 Then, make it clear to yourself how you want to organize your VPN:
671 What are the nodes (computers running tinc)?
672 What IP addresses/subnets do they have?
673 What is the network mask of the entire VPN?
674 Do you need special firewall rules?
675 Do you have to set up masquerading or forwarding rules?
676 Do you want to run tinc in router mode or switch mode?
677 These questions can only be answered by yourself,
678 you will not find the answers in this documentation.
679 Make sure you have an adequate understanding of networks in general.
680 @cindex Network Administrators Guide
681 A good resource on networking is the
682 @uref{https://www.tldp.org/LDP/nag2/, Linux Network Administrators Guide}.
683
684 If you have everything clearly pictured in your mind,
685 proceed in the following order:
686 First, create the initial configuration files and public/private keypairs using the following command:
687 @example
688 tinc -n @var{NETNAME} init @var{NAME}
689 @end example
690 Second, use @samp{tinc -n @var{NETNAME} add ...} to further configure tinc.
691 Finally, export your host configuration file using @samp{tinc -n @var{NETNAME} export} and send it to those
692 people or computers you want tinc to connect to.
693 They should send you their host configuration file back, which you can import using @samp{tinc -n @var{NETNAME} import}.
694
695 These steps are described in the subsections below.
696
697
698 @c ==================================================================
699 @node    Multiple networks
700 @section Multiple networks
701
702 @cindex multiple networks
703 @cindex netname
704
705 In order to allow you to run more than one tinc daemon on one computer,
706 for instance if your computer is part of more than one VPN,
707 you can assign a @var{netname} to your VPN.
708 It is not required if you only run one tinc daemon,
709 it doesn't even have to be the same on all the nodes of your VPN,
710 but it is recommended that you choose one anyway.
711
712 We will assume you use a netname throughout this document.
713 This means that you call tinc with the -n argument,
714 which will specify the netname.
715
716 The effect of this option is that tinc will set its configuration
717 root to @file{@value{sysconfdir}/tinc/@var{netname}/}, where @var{netname} is your argument to the -n option.
718 You will also notice that log messages it appears in syslog as coming from @file{tinc.@var{netname}},
719 and on Linux, unless specified otherwise, the name of the virtual network interface will be the same as the network name.
720
721 However, it is not strictly necessary that you call tinc with the -n
722 option. If you do not use it, the network name will just be empty, and
723 tinc will look for files in @file{@value{sysconfdir}/tinc/} instead of
724 @file{@value{sysconfdir}/tinc/@var{netname}/};
725 the configuration file will then be @file{@value{sysconfdir}/tinc/tinc.conf},
726 and the host configuration files are expected to be in @file{@value{sysconfdir}/tinc/hosts/}.
727
728
729 @c ==================================================================
730 @node    How connections work
731 @section How connections work
732
733 When tinc starts up, it parses the command-line options and then
734 reads in the configuration file tinc.conf.
735 It will then start listening for incoming connection from other daemons,
736 and will by default also automatically try to connect to known peers.
737 By default, tinc will try to keep at least 3 working meta-connections alive at all times.
738
739 @cindex client
740 @cindex server
741 There is no real distinction between a server and a client in tinc.
742 If you wish, you can view a tinc daemon without a `ConnectTo' statement in tinc.conf and `AutoConnect = no' as a server,
743 and one which does have one or more `ConnectTo' statements or `Autoconnect = yes' (which is the default) as a client.
744 It does not matter if two tinc daemons have a `ConnectTo' value pointing to each other however.
745
746 Connections specified using `ConnectTo' are so-called meta-connections.
747 Tinc daemons exchange information about all other daemon they know about via these meta-connections.
748 After learning about all the daemons in the VPN,
749 tinc will create other connections as necessary in order to communicate with them.
750 For example, if there are three daemons named A, B and C, and A has @samp{ConnectTo = B} in its tinc.conf file,
751 and C has @samp{ConnectTo = B} in its tinc.conf file, then A will learn about C from B,
752 and will be able to exchange VPN packets with C without the need to have @samp{ConnectTo = C} in its tinc.conf file.
753
754 It could be that some daemons are located behind a Network Address Translation (NAT) device, or behind a firewall.
755 In the above scenario with three daemons, if A and C are behind a NAT,
756 B will automatically help A and C punch holes through their NAT,
757 in a way similar to the STUN protocol, so that A and C can still communicate with each other directly.
758 It is not always possible to do this however, and firewalls might also prevent direct communication.
759 In that case, VPN packets between A and C will be forwarded by B.
760
761 In effect, all nodes in the VPN will be able to talk to each other, as long as
762 there is a path of meta-connections between them, and whenever possible, two
763 nodes will communicate with each other directly.
764
765
766 @c ==================================================================
767 @node    Configuration files
768 @section Configuration files
769
770 The actual configuration of the daemon is done in the file
771 @file{@value{sysconfdir}/tinc/@var{netname}/tinc.conf} and at least one other file in the directory
772 @file{@value{sysconfdir}/tinc/@var{netname}/hosts/}.
773
774 An optional directory @file{@value{sysconfdir}/tinc/@var{netname}/conf.d} can be added from which
775 any .conf file will be read.
776
777 These file consists of comments (lines started with a #) or assignments
778 in the form of
779
780 @example
781 Variable = Value.
782 @end example
783
784 The variable names are case insensitive, and any spaces, tabs, newlines
785 and carriage returns are ignored.  Note: it is not required that you put
786 in the `=' sign, but doing so improves readability.  If you leave it
787 out, remember to replace it with at least one space character.
788
789 The server configuration is complemented with host specific configuration (see
790 the next section). Although all host configuration options for the local node
791 listed in this document can also be put in
792 @file{@value{sysconfdir}/tinc/@var{netname}/tinc.conf}, it is recommended to
793 put host specific configuration options in the host configuration file, as this
794 makes it easy to exchange with other nodes.
795
796 You can edit the config file manually, but it is recommended that you use
797 the tinc command to change configuration variables for you.
798
799 In the following two subsections all valid variables are listed in alphabetical order.
800 The default value is given between parentheses,
801 other comments are between square brackets.
802
803 @menu
804 * Main configuration variables::
805 * Host configuration variables::
806 * Scripts::
807 * How to configure::
808 @end menu
809
810
811 @c ==================================================================
812 @node       Main configuration variables
813 @subsection Main configuration variables
814
815 @table @asis
816 @cindex AddressFamily
817 @item AddressFamily = <ipv4|ipv6|any> (any)
818 This option affects the address family of listening and outgoing sockets.
819 If any is selected, then depending on the operating system
820 both IPv4 and IPv6 or just IPv6 listening sockets will be created.
821
822 @cindex AutoConnect
823 @item AutoConnect = <yes|no> (yes)
824 If set to yes, tinc will automatically set up meta connections to other nodes,
825 without requiring @var{ConnectTo} variables.
826
827 @cindex BindToAddress
828 @item BindToAddress = <@var{address}> [<@var{port}>]
829 This is the same as ListenAddress, however the address given with the BindToAddress option
830 will also be used for outgoing connections.
831 This is useful if your computer has more than one IPv4 or IPv6 address,
832 and you want tinc to only use a specific one for outgoing packets.
833
834 @cindex BindToInterface
835 @item BindToInterface = <@var{interface}> [experimental]
836 If you have more than one network interface in your computer, tinc will
837 by default listen on all of them for incoming connections.  It is
838 possible to bind tinc to a single interface like eth0 or ppp0 with this
839 variable.
840
841 This option may not work on all platforms.
842 Also, on some platforms it will not actually bind to an interface,
843 but rather to the address that the interface has at the moment a socket is created.
844
845 @cindex Broadcast
846 @item Broadcast = <no | mst | direct> (mst) [experimental]
847 This option selects the way broadcast packets are sent to other daemons.
848 @emph{NOTE: all nodes in a VPN must use the same Broadcast mode, otherwise routing loops can form.}
849
850 @table @asis
851 @item no
852 Broadcast packets are never sent to other nodes.
853
854 @item mst
855 Broadcast packets are sent and forwarded via the VPN's Minimum Spanning Tree.
856 This ensures broadcast packets reach all nodes.
857
858 @item direct
859 Broadcast packets are sent directly to all nodes that can be reached directly.
860 Broadcast packets received from other nodes are never forwarded.
861 If the IndirectData option is also set, broadcast packets will only be sent to nodes which we have a meta connection to.
862 @end table
863
864 @cindex BroadcastSubnet
865 @item BroadcastSubnet = @var{address}[/@var{prefixlength}]
866 Declares a broadcast subnet.
867 Any packet with a destination address falling into such a subnet will be routed as a broadcast
868 (provided all nodes have it declared).
869 This is most useful to declare subnet broadcast addresses (e.g. 10.42.255.255),
870 otherwise tinc won't know what to do with them.
871
872 Note that global broadcast addresses (MAC ff:ff:ff:ff:ff:ff, IPv4 255.255.255.255),
873 as well as multicast space (IPv4 224.0.0.0/4, IPv6 ff00::/8)
874 are always considered broadcast addresses and don't need to be declared.
875
876 @cindex ConnectTo
877 @item ConnectTo = <@var{name}>
878 Specifies which other tinc daemon to connect to on startup.
879 Multiple ConnectTo variables may be specified,
880 in which case outgoing connections to each specified tinc daemon are made.
881 The names should be known to this tinc daemon
882 (i.e., there should be a host configuration file for the name on the ConnectTo line).
883
884 If you don't specify a host with ConnectTo and have disabled AutoConnect,
885 tinc won't try to connect to other daemons at all,
886 and will instead just listen for incoming connections.
887
888 @cindex DecrementTTL
889 @item DecrementTTL = <yes | no> (no) [experimental]
890 When enabled, tinc will decrement the Time To Live field in IPv4 packets, or the Hop Limit field in IPv6 packets,
891 before forwarding a received packet to the virtual network device or to another node,
892 and will drop packets that have a TTL value of zero,
893 in which case it will send an ICMP Time Exceeded packet back.
894
895 Do not use this option if you use switch mode and want to use IPv6.
896
897 @cindex Device
898 @item Device = <@var{device}> (@file{/dev/tap0}, @file{/dev/net/tun} or other depending on platform)
899 The virtual network device to use.
900 Tinc will automatically detect what kind of device it is.
901 Note that you can only use one device per daemon.
902 Under Windows, use @var{Interface} instead of @var{Device}.
903 Note that you can only use one device per daemon.
904 See also @ref{Device files}.
905
906 @cindex DeviceStandby
907 @item DeviceStandby = <yes | no> (no)
908 When disabled, tinc calls @file{tinc-up} on startup, and @file{tinc-down} on shutdown.
909 When enabled, tinc will only call @file{tinc-up} when at least one node is reachable,
910 and will call @file{tinc-down} as soon as no nodes are reachable.
911 On Windows, this also determines when the virtual network interface "cable" is "plugged".
912
913 @cindex DeviceType
914 @item DeviceType = <@var{type}> (platform dependent)
915 The type of the virtual network device.
916 Tinc will normally automatically select the right type of tun/tap interface, and this option should not be used.
917 However, this option can be used to select one of the special interface types, if support for them is compiled in.
918
919 @table @asis
920 @cindex dummy
921 @item dummy
922 Use a dummy interface.
923 No packets are ever read or written to a virtual network device.
924 Useful for testing, or when setting up a node that only forwards packets for other nodes.
925
926 @cindex raw_socket
927 @item raw_socket
928 Open a raw socket, and bind it to a pre-existing
929 @var{Interface} (eth0 by default).
930 All packets are read from this interface.
931 Packets received for the local node are written to the raw socket.
932 However, at least on Linux, the operating system does not process IP packets destined for the local host.
933
934 @cindex multicast
935 @item multicast
936 Open a multicast UDP socket and bind it to the address and port (separated by spaces) and optionally a TTL value specified using @var{Device}.
937 Packets are read from and written to this multicast socket.
938 This can be used to connect to UML, QEMU or KVM instances listening on the same multicast address.
939 Do NOT connect multiple tinc daemons to the same multicast address, this will very likely cause routing loops.
940 Also note that this can cause decrypted VPN packets to be sent out on a real network if misconfigured.
941
942 @cindex fd
943 @item fd
944 Use a file descriptor.
945 All packets are read from this interface.
946 Packets received for the local node are written to it.
947
948 @cindex UML
949 @item uml (not compiled in by default)
950 Create a UNIX socket with the filename specified by
951 @var{Device}, or @file{@value{runstatedir}/@var{netname}.umlsocket}
952 if not specified.
953 Tinc will wait for a User Mode Linux instance to connect to this socket.
954
955 @cindex VDE
956 @item vde (not compiled in by default)
957 Uses the libvdeplug library to connect to a Virtual Distributed Ethernet switch,
958 using the UNIX socket specified by
959 @var{Device}, or @file{@value{runstatedir}/vde.ctl}
960 if not specified.
961 @end table
962
963 Also, in case tinc does not seem to correctly interpret packets received from the virtual network device,
964 it can be used to change the way packets are interpreted:
965
966 @table @asis
967 @item tun (BSD and Linux)
968 Set type to tun.
969 Depending on the platform, this can either be with or without an address family header (see below).
970
971 @cindex tunnohead
972 @item tunnohead (BSD)
973 Set type to tun without an address family header.
974 Tinc will expect packets read from the virtual network device to start with an IP header.
975 On some platforms IPv6 packets cannot be read from or written to the device in this mode.
976
977 @cindex tunifhead
978 @item tunifhead (BSD)
979 Set type to tun with an address family header.
980 Tinc will expect packets read from the virtual network device
981 to start with a four byte header containing the address family,
982 followed by an IP header.
983 This mode should support both IPv4 and IPv6 packets.
984
985 @cindex utun
986 @item utun (OS X)
987 Set type to utun.
988 This is only supported on OS X version 10.6.8 and higher, but doesn't require the tuntaposx module.
989 This mode should support both IPv4 and IPv6 packets.
990
991 @item tap (BSD and Linux)
992 Set type to tap.
993 Tinc will expect packets read from the virtual network device
994 to start with an Ethernet header.
995 @end table
996
997 @cindex DirectOnly
998 @item DirectOnly = <yes|no> (no) [experimental]
999 When this option is enabled, packets that cannot be sent directly to the destination node,
1000 but which would have to be forwarded by an intermediate node, are dropped instead.
1001 When combined with the IndirectData option,
1002 packets for nodes for which we do not have a meta connection with are also dropped.
1003
1004 @cindex Ed25519PrivateKeyFile
1005 @item Ed25519PrivateKeyFile = <@var{path}> (@file{@value{sysconfdir}/tinc/@var{netname}/ed25519_key.priv})
1006 The file in which the private Ed25519 key of this tinc daemon resides.
1007 This is only used if ExperimentalProtocol is enabled.
1008
1009 @cindex ExperimentalProtocol
1010 @item ExperimentalProtocol = <yes|no> (yes)
1011 When this option is enabled, the SPTPS protocol will be used when connecting to nodes that also support it.
1012 Ephemeral ECDH will be used for key exchanges,
1013 and Ed25519 will be used instead of RSA for authentication.
1014 When enabled, an Ed25519 key must have been generated before with
1015 @samp{tinc generate-ed25519-keys}.
1016
1017 @cindex Forwarding
1018 @item Forwarding = <off|internal|kernel> (internal) [experimental]
1019 This option selects the way indirect packets are forwarded.
1020
1021 @table @asis
1022 @item off
1023 Incoming packets that are not meant for the local node,
1024 but which should be forwarded to another node, are dropped.
1025
1026 @item internal
1027 Incoming packets that are meant for another node are forwarded by tinc internally.
1028
1029 This is the default mode, and unless you really know you need another forwarding mode, don't change it.
1030
1031 @item kernel
1032 Incoming packets using the legacy protocol are always sent to the TUN/TAP device,
1033 even if the packets are not for the local node.
1034 This is less efficient, but allows the kernel to apply its routing and firewall rules on them,
1035 and can also help debugging.
1036 Incoming packets using the SPTPS protocol are dropped, since they are end-to-end encrypted.
1037 @end table
1038
1039 @cindex FWMark
1040 @item FWMark = <@var{value}> (0) [experimental]
1041 When set to a non-zero value, all TCP and UDP sockets created by tinc will use the given value as the firewall mark.
1042 This can be used for mark-based routing or for packet filtering.
1043 This option is currently only supported on Linux.
1044
1045 @cindex Hostnames
1046 @item Hostnames = <yes|no> (no)
1047 This option selects whether IP addresses (both real and on the VPN)
1048 should be resolved.  Since DNS lookups are blocking, it might affect
1049 tinc's efficiency, even stopping the daemon for a few seconds every time
1050 it does a lookup if your DNS server is not responding.
1051
1052 This does not affect resolving hostnames to IP addresses from the
1053 configuration file, but whether hostnames should be resolved while logging.
1054
1055 @cindex Interface
1056 @item Interface = <@var{interface}>
1057 Defines the name of the interface corresponding to the virtual network device.
1058 Depending on the operating system and the type of device this may or may not actually set the name of the interface.
1059 Under Windows, this variable is used to select which network interface will be used.
1060 If you specified a Device, this variable is almost always already correctly set.
1061
1062 @cindex ListenAddress
1063 @item ListenAddress = <@var{address}> [<@var{port}>]
1064 If your computer has more than one IPv4 or IPv6 address, tinc
1065 will by default listen on all of them for incoming connections.
1066 This option can be used to restrict which addresses tinc listens on.
1067 Multiple ListenAddress variables may be specified,
1068 in which case listening sockets for each specified address are made.
1069
1070 If no @var{port} is specified, the socket will listen on the port specified by the Port option,
1071 or to port 655 if neither is given.
1072 To only listen on a specific port but not to a specific address, use "*" for the @var{address}.
1073
1074 @cindex LocalDiscovery
1075 @item LocalDiscovery = <yes | no> (no)
1076 When enabled, tinc will try to detect peers that are on the same local network.
1077 This will allow direct communication using LAN addresses, even if both peers are behind a NAT
1078 and they only ConnectTo a third node outside the NAT,
1079 which normally would prevent the peers from learning each other's LAN address.
1080
1081 Currently, local discovery is implemented by sending some packets to the local address of the node during UDP discovery.
1082 This will not work with old nodes that don't transmit their local address.
1083
1084 @cindex LogLevel
1085 @item LogLevel = <@var{level}> (0)
1086 This option controls the verbosity of the logging.
1087 See @ref{Debug levels}.
1088
1089 @cindex Mode
1090 @item Mode = <router|switch|hub> (router)
1091 This option selects the way packets are routed to other daemons.
1092
1093 @table @asis
1094 @cindex router
1095 @item router
1096 In this mode Subnet
1097 variables in the host configuration files will be used to form a routing table.
1098 Only packets of routable protocols (IPv4 and IPv6) are supported in this mode.
1099
1100 This is the default mode, and unless you really know you need another mode, don't change it.
1101
1102 @cindex switch
1103 @item switch
1104 In this mode the MAC addresses of the packets on the VPN will be used to
1105 dynamically create a routing table just like an Ethernet switch does.
1106 Unicast, multicast and broadcast packets of every protocol that runs over Ethernet are supported in this mode
1107 at the cost of frequent broadcast ARP requests and routing table updates.
1108
1109 This mode is primarily useful if you want to bridge Ethernet segments.
1110
1111 @cindex hub
1112 @item hub
1113 This mode is almost the same as the switch mode, but instead
1114 every packet will be broadcast to the other daemons
1115 while no routing table is managed.
1116 @end table
1117
1118 @cindex InvitationExpire
1119 @item InvitationExpire = <@var{seconds}> (604800)
1120 This option controls the time invitations are valid.
1121
1122 @cindex KeyExpire
1123 @item KeyExpire = <@var{seconds}> (3600)
1124 This option controls the time the encryption keys used to encrypt the data
1125 are valid.  It is common practice to change keys at regular intervals to
1126 make it even harder for crackers, even though it is thought to be nearly
1127 impossible to crack a single key.
1128
1129 @cindex MACExpire
1130 @item MACExpire = <@var{seconds}> (600)
1131 This option controls the amount of time MAC addresses are kept before they are removed.
1132 This only has effect when Mode is set to "switch".
1133
1134 @cindex MaxConnectionBurst
1135 @item MaxConnectionBurst = <@var{count}> (100)
1136 This option controls how many connections tinc accepts in quick succession.
1137 If there are more connections than the given number in a short time interval,
1138 tinc will reduce the number of accepted connections to only one per second,
1139 until the burst has passed.
1140
1141 @cindex Name
1142 @item Name = <@var{name}> [required]
1143 This is a symbolic name for this connection.
1144 The name must consist only of alfanumeric and underscore characters (a-z, A-Z, 0-9 and _), and is case sensitive.
1145
1146 If Name starts with a $, then the contents of the environment variable that follows will be used.
1147 In that case, invalid characters will be converted to underscores.
1148 If Name is $HOST, but no such environment variable exist,
1149 the hostname will be read using the gethostname() system call.
1150
1151 @cindex PingInterval
1152 @item PingInterval = <@var{seconds}> (60)
1153 The number of seconds of inactivity that tinc will wait before sending a
1154 probe to the other end.
1155
1156 @cindex PingTimeout
1157 @item PingTimeout = <@var{seconds}> (5)
1158 The number of seconds to wait for a response to pings or to allow meta
1159 connections to block. If the other end doesn't respond within this time,
1160 the connection is terminated, and the others will be notified of this.
1161
1162 @cindex PriorityInheritance
1163 @item PriorityInheritance = <yes|no> (no) [experimental]
1164 When this option is enabled the value of the TOS field of tunneled IPv4 packets
1165 will be inherited by the UDP packets that are sent out.
1166
1167 @cindex PrivateKey
1168 @item PrivateKey = <@var{key}> [obsolete]
1169 This is the RSA private key for tinc. However, for safety reasons it is
1170 advised to store private keys of any kind in separate files. This prevents
1171 accidental eavesdropping if you are editing the configuration file.
1172
1173 @cindex PrivateKeyFile
1174 @item PrivateKeyFile = <@var{path}> (@file{@value{sysconfdir}/tinc/@var{netname}/rsa_key.priv})
1175 This is the full path name of the RSA private key file that was
1176 generated by @samp{tinc generate-keys}.  It must be a full path, not a
1177 relative directory.
1178
1179 @cindex ProcessPriority
1180 @item ProcessPriority = <low|normal|high>
1181 When this option is used the priority of the tincd process will be adjusted.
1182 Increasing the priority may help to reduce latency and packet loss on the VPN.
1183
1184 @cindex Proxy
1185 @item Proxy = socks4 | socks5 | http | exec @var{...} [experimental]
1186 Use a proxy when making outgoing connections.
1187 The following proxy types are currently supported:
1188
1189 @table @asis
1190 @cindex socks4
1191 @item socks4 <@var{address}> <@var{port}> [<@var{username}>]
1192 Connects to the proxy using the SOCKS version 4 protocol.
1193 Optionally, a @var{username} can be supplied which will be passed on to the proxy server.
1194
1195 @cindex socks5
1196 @item socks5 <@var{address}> <@var{port}> [<@var{username}> <@var{password}>]
1197 Connect to the proxy using the SOCKS version 5 protocol.
1198 If a @var{username} and @var{password} are given, basic username/password authentication will be used,
1199 otherwise no authentication will be used.
1200
1201 @cindex http
1202 @item http <@var{address}> <@var{port}>
1203 Connects to the proxy and sends a HTTP CONNECT request.
1204
1205 @cindex exec
1206 @item exec <@var{command}>
1207 Executes the given command which should set up the outgoing connection.
1208 The environment variables @env{NAME}, @env{NODE}, @env{REMOTEADDRES} and @env{REMOTEPORT} are available.
1209 @end table
1210
1211 @cindex ReplayWindow
1212 @item ReplayWindow = <bytes> (32)
1213 This is the size of the replay tracking window for each remote node, in bytes.
1214 The window is a bitfield which tracks 1 packet per bit, so for example
1215 the default setting of 32 will track up to 256 packets in the window. In high
1216 bandwidth scenarios, setting this to a higher value can reduce packet loss from
1217 the interaction of replay tracking with underlying real packet loss and/or
1218 reordering. Setting this to zero will disable replay tracking completely and
1219 pass all traffic, but leaves tinc vulnerable to replay-based attacks on your
1220 traffic.
1221
1222 @cindex StrictSubnets
1223 @item StrictSubnets = <yes|no> (no) [experimental]
1224 When this option is enabled tinc will only use Subnet statements which are
1225 present in the host config files in the local
1226 @file{@value{sysconfdir}/tinc/@var{netname}/hosts/} directory.
1227 Subnets learned via connections to other nodes and which are not
1228 present in the local host config files are ignored.
1229
1230 @cindex TunnelServer
1231 @item TunnelServer = <yes|no> (no) [experimental]
1232 When this option is enabled tinc will no longer forward information between other tinc daemons,
1233 and will only allow connections with nodes for which host config files are present in the local
1234 @file{@value{sysconfdir}/tinc/@var{netname}/hosts/} directory.
1235 Setting this options also implicitly sets StrictSubnets.
1236
1237 @cindex UDPDiscovey
1238 @item UDPDiscovery = <yes|no> (yes)
1239 When this option is enabled tinc will try to establish UDP connectivity to nodes,
1240 using TCP while it determines if a node is reachable over UDP. If it is disabled,
1241 tinc always assumes a node is reachable over UDP.
1242 Note that tinc will never use UDP with nodes that have TCPOnly enabled.
1243
1244 @cindex UDPDiscoveryKeepaliveInterval
1245 @item UDPDiscoveryKeepaliveInterval = <seconds> (9)
1246 The minimum amount of time between sending UDP ping datagrams to check UDP connectivity once it has been established.
1247 Note that these pings are large, since they are used to verify link MTU as well.
1248
1249 @cindex UDPDiscoveryInterval
1250 @item UDPDiscoveryInterval = <seconds> (2)
1251 The minimum amount of time between sending UDP ping datagrams to try to establish UDP connectivity.
1252
1253 @cindex UDPDiscoveryTimeout
1254 @item UDPDiscoveryTimeout = <seconds> (30)
1255 If tinc doesn't receive any UDP ping replies over the specified interval,
1256 it will assume UDP communication is broken and will fall back to TCP.
1257
1258 @cindex UDPInfoInterval
1259 @item UDPInfoInterval = <seconds> (5)
1260 The minimum amount of time between sending periodic updates about UDP addresses, which are mostly useful for UDP hole punching.
1261
1262 @cindex UDPRcvBuf
1263 @item UDPRcvBuf = <bytes> (1048576)
1264 Sets the socket receive buffer size for the UDP socket, in bytes.
1265 If set to zero, the default buffer size will be used by the operating system.
1266 Note: this setting can have a significant impact on performance, especially raw throughput.
1267
1268 @cindex UDPSndBuf
1269 @item UDPSndBuf = <bytes> (1048576)
1270 Sets the socket send buffer size for the UDP socket, in bytes.
1271 If set to zero, the default buffer size will be used by the operating system.
1272 Note: this setting can have a significant impact on performance, especially raw throughput.
1273
1274 @cindex UPnP
1275 @item UPnP = <yes|udponly|no> (no)
1276 If this option is enabled then tinc will search for UPnP-IGD devices on the local network.
1277 It will then create and maintain port mappings for tinc's listening TCP and UDP ports.
1278 If set to "udponly", tinc will only create a mapping for its UDP (data) port, not for its TCP (metaconnection) port.
1279 Note that tinc must have been built with miniupnpc support for this feature to be available.
1280 Furthermore, be advised that enabling this can have security implications, because the miniupnpc library that
1281 tinc uses might not be well-hardened with regard to malicious UPnP replies.
1282
1283 @cindex UPnPDiscoverWait
1284 @item UPnPDiscoverWait = <seconds> (5)
1285 The amount of time to wait for replies when probing the local network for UPnP devices.
1286
1287 @cindex UPnPRefreshPeriod
1288 @item UPnPRefreshPeriod = <seconds> (5)
1289 How often tinc will re-add the port mapping, in case it gets reset on the UPnP device.
1290 This also controls the duration of the port mapping itself, which will be set to twice that duration.
1291
1292 @end table
1293
1294
1295 @c ==================================================================
1296 @node       Host configuration variables
1297 @subsection Host configuration variables
1298
1299 @table @asis
1300 @cindex Address
1301 @item Address = <@var{IP address}|@var{hostname}> [<port>] [recommended]
1302 This variable is only required if you want to connect to this host.  It
1303 must resolve to the external IP address where the host can be reached,
1304 not the one that is internal to the VPN.
1305 If no port is specified, the default Port is used.
1306 Multiple Address variables can be specified, in which case each address will be
1307 tried until a working connection has been established.
1308
1309 @cindex Cipher
1310 @item Cipher = <@var{cipher}> (blowfish)
1311 The symmetric cipher algorithm used to encrypt UDP packets using the legacy protocol.
1312 Any cipher supported by LibreSSL or OpenSSL is recognized.
1313 Furthermore, specifying "none" will turn off packet encryption.
1314 It is best to use only those ciphers which support CBC mode.
1315 This option has no effect for connections using the SPTPS protocol, which always use AES-256-CTR.
1316
1317 @cindex ClampMSS
1318 @item ClampMSS = <yes|no> (yes)
1319 This option specifies whether tinc should clamp the maximum segment size (MSS)
1320 of TCP packets to the path MTU. This helps in situations where ICMP
1321 Fragmentation Needed or Packet too Big messages are dropped by firewalls.
1322
1323 @cindex Compression
1324 @item Compression = <@var{level}> (0)
1325 This option sets the level of compression used for UDP packets.
1326 Possible values are 0 (off), 1 (fast zlib) and any integer up to 9 (best zlib),
1327 10 (fast LZO) and 11 (best LZO).
1328
1329 @cindex Digest
1330 @item Digest = <@var{digest}> (sha1)
1331 The digest algorithm used to authenticate UDP packets using the legacy protocol.
1332 Any digest supported by LibreSSL or OpenSSL is recognized.
1333 Furthermore, specifying "none" will turn off packet authentication.
1334 This option has no effect for connections using the SPTPS protocol, which always use HMAC-SHA-256.
1335
1336 @cindex IndirectData
1337 @item IndirectData = <yes|no> (no)
1338 When set to yes, other nodes which do not already have a meta connection to you
1339 will not try to establish direct communication with you.
1340 It is best to leave this option out or set it to no.
1341
1342 @cindex MACLength
1343 @item MACLength = <@var{bytes}> (4)
1344 The length of the message authentication code used to authenticate UDP packets using the legacy protocol.
1345 Can be anything from 0
1346 up to the length of the digest produced by the digest algorithm.
1347 This option has no effect for connections using the SPTPS protocol, which never truncate MACs.
1348
1349 @cindex PMTU
1350 @item PMTU = <@var{mtu}> (1514)
1351 This option controls the initial path MTU to this node.
1352
1353 @cindex PMTUDiscovery
1354 @item PMTUDiscovery = <yes|no> (yes)
1355 When this option is enabled, tinc will try to discover the path MTU to this node.
1356 After the path MTU has been discovered, it will be enforced on the VPN.
1357
1358 @cindex MTUInfoInterval
1359 @item MTUInfoInterval = <seconds> (5)
1360 The minimum amount of time between sending periodic updates about relay path MTU. Useful for quickly determining MTU to indirect nodes.
1361
1362 @cindex Port
1363 @item Port = <@var{port}> (655)
1364 This is the port this tinc daemon listens on.
1365 You can use decimal portnumbers or symbolic names (as listed in @file{/etc/services}).
1366
1367 @cindex PublicKey
1368 @item PublicKey = <@var{key}> [obsolete]
1369 This is the RSA public key for this host.
1370
1371 @cindex PublicKeyFile
1372 @item PublicKeyFile = <@var{path}> [obsolete]
1373 This is the full path name of the RSA public key file that was generated
1374 by @samp{tinc generate-keys}.  It must be a full path, not a relative
1375 directory.
1376
1377 @cindex PEM format
1378 From version 1.0pre4 on tinc will store the public key directly into the
1379 host configuration file in PEM format, the above two options then are not
1380 necessary. Either the PEM format is used, or exactly
1381 @strong{one of the above two options} must be specified
1382 in each host configuration file, if you want to be able to establish a
1383 connection with that host.
1384
1385 @cindex Subnet
1386 @item Subnet = <@var{address}[/@var{prefixlength}[#@var{weight}]]>
1387 The subnet which this tinc daemon will serve.
1388 Tinc tries to look up which other daemon it should send a packet to by searching the appropriate subnet.
1389 If the packet matches a subnet,
1390 it will be sent to the daemon who has this subnet in his host configuration file.
1391 Multiple subnet lines can be specified for each daemon.
1392
1393 Subnets can either be single MAC, IPv4 or IPv6 addresses,
1394 in which case a subnet consisting of only that single address is assumed,
1395 or they can be a IPv4 or IPv6 network address with a prefixlength.
1396 For example, IPv4 subnets must be in a form like 192.168.1.0/24,
1397 where 192.168.1.0 is the network address and 24 is the number of bits set in the netmask.
1398 Note that subnets like 192.168.1.1/24 are invalid!
1399 Read a networking HOWTO/FAQ/guide if you don't understand this.
1400 IPv6 subnets are notated like fec0:0:0:1::/64.
1401 MAC addresses are notated like 0:1a:2b:3c:4d:5e.
1402
1403 @cindex CIDR notation
1404 Prefixlength is the number of bits set to 1 in the netmask part; for
1405 example: netmask 255.255.255.0 would become /24, 255.255.252.0 becomes
1406 /22. This conforms to standard CIDR notation as described in
1407 @uref{https://www.ietf.org/rfc/rfc1519.txt, RFC1519}
1408
1409 A Subnet can be given a weight to indicate its priority over identical Subnets
1410 owned by different nodes. The default weight is 10. Lower values indicate
1411 higher priority. Packets will be sent to the node with the highest priority,
1412 unless that node is not reachable, in which case the node with the next highest
1413 priority will be tried, and so on.
1414
1415 @cindex TCPonly
1416 @item TCPonly = <yes|no> (no)
1417 If this variable is set to yes, then the packets are tunnelled over a
1418 TCP connection instead of a UDP connection.  This is especially useful
1419 for those who want to run a tinc daemon from behind a masquerading
1420 firewall, or if UDP packet routing is disabled somehow.
1421 Setting this options also implicitly sets IndirectData.
1422
1423 @cindex Weight
1424 @item Weight = <weight>
1425 If this variable is set, it overrides the weight given to connections made with
1426 another host. A higher weight means a lower priority is given to this
1427 connection when broadcasting or forwarding packets.
1428 @end table
1429
1430
1431 @c ==================================================================
1432 @node       Scripts
1433 @subsection Scripts
1434
1435 @cindex scripts
1436 Apart from reading the server and host configuration files,
1437 tinc can also run scripts at certain moments.
1438 Below is a list of filenames of scripts and a description of when they are run.
1439 A script is only run if it exists and if it is executable.
1440
1441 Scripts are run synchronously;
1442 this means that tinc will temporarily stop processing packets until the called script finishes executing.
1443 This guarantees that scripts will execute in the exact same order as the events that trigger them.
1444 If you need to run commands asynchronously, you have to ensure yourself that they are being run in the background.
1445
1446 Under Windows, the scripts should have the extension @file{.bat} or @file{.cmd}.
1447
1448 @table @file
1449 @cindex tinc-up
1450 @item @value{sysconfdir}/tinc/@var{netname}/tinc-up
1451 This is the most important script.
1452 If it is present it will be executed right after the tinc daemon has been
1453 started and has connected to the virtual network device.
1454 It should be used to set up the corresponding network interface,
1455 but can also be used to start other things.
1456
1457 Under Windows you can use the Network Connections control panel instead of creating this script.
1458
1459 @cindex tinc-down
1460 @item @value{sysconfdir}/tinc/@var{netname}/tinc-down
1461 This script is started right before the tinc daemon quits.
1462
1463 @item @value{sysconfdir}/tinc/@var{netname}/hosts/@var{host}-up
1464 This script is started when the tinc daemon with name @var{host} becomes reachable.
1465
1466 @item @value{sysconfdir}/tinc/@var{netname}/hosts/@var{host}-down
1467 This script is started when the tinc daemon with name @var{host} becomes unreachable.
1468
1469 @item @value{sysconfdir}/tinc/@var{netname}/host-up
1470 This script is started when any host becomes reachable.
1471
1472 @item @value{sysconfdir}/tinc/@var{netname}/host-down
1473 This script is started when any host becomes unreachable.
1474
1475 @item @value{sysconfdir}/tinc/@var{netname}/subnet-up
1476 This script is started when a Subnet becomes reachable.
1477 The Subnet and the node it belongs to are passed in environment variables.
1478
1479 @item @value{sysconfdir}/tinc/@var{netname}/subnet-down
1480 This script is started when a Subnet becomes unreachable.
1481
1482 @item @value{sysconfdir}/tinc/@var{netname}/invitation-created
1483 This script is started when a new invitation has been created.
1484
1485 @item @value{sysconfdir}/tinc/@var{netname}/invitation-accepted
1486 This script is started when an invitation has been used.
1487
1488 @end table
1489
1490 @cindex environment variables
1491 The scripts are started without command line arguments,
1492 but can make use of certain environment variables.
1493 Under UNIX like operating systems the names of environment variables must be preceded by a $ in scripts.
1494 Under Windows, in @file{.bat} or @file{.cmd} files, they have to be put between % signs.
1495
1496 @table @env
1497 @cindex NETNAME
1498 @item NETNAME
1499 If a netname was specified, this environment variable contains it.
1500
1501 @cindex NAME
1502 @item NAME
1503 Contains the name of this tinc daemon.
1504
1505 @cindex DEVICE
1506 @item DEVICE
1507 Contains the name of the virtual network device that tinc uses.
1508
1509 @cindex INTERFACE
1510 @item INTERFACE
1511 Contains the name of the virtual network interface that tinc uses.
1512 This should be used for commands like ifconfig.
1513
1514 @cindex NODE
1515 @item NODE
1516 When a host becomes (un)reachable, this is set to its name.
1517 If a subnet becomes (un)reachable, this is set to the owner of that subnet.
1518
1519 @cindex REMOTEADDRESS
1520 @item REMOTEADDRESS
1521 When a host becomes (un)reachable, this is set to its real address.
1522
1523 @cindex REMOTEPORT
1524 @item REMOTEPORT
1525 When a host becomes (un)reachable,
1526 this is set to the port number it uses for communication with other tinc daemons.
1527
1528 @cindex SUBNET
1529 @item SUBNET
1530 When a subnet becomes (un)reachable, this is set to the subnet.
1531
1532 @cindex WEIGHT
1533 @item WEIGHT
1534 When a subnet becomes (un)reachable, this is set to the subnet weight.
1535
1536 @cindex INVITATION_FILE
1537 @item INVITATION_FILE
1538 When the @file{invitation-created} script is called,
1539 this is set to the file where the invitation details will be stored.
1540
1541 @cindex INVITATION_URL
1542 @item INVITATION_URL
1543 When the @file{invitation-created} script is called,
1544 this is set to the invitation URL that has been created.
1545 @end table
1546
1547 Do not forget that under UNIX operating systems,
1548 you have to make the scripts executable, using the command @samp{chmod a+x script}.
1549
1550
1551 @c ==================================================================
1552 @node       How to configure
1553 @subsection How to configure
1554
1555 @subsubheading Step 1.  Creating initial configuration files.
1556
1557 The initial directory structure, configuration files and public/private keypairs are created using the following command:
1558
1559 @example
1560 tinc -n @var{netname} init @var{name}
1561 @end example
1562
1563 (You will need to run this as root, or use "sudo".)
1564 This will create the configuration directory @file{@value{sysconfdir}/tinc/@var{netname}.},
1565 and inside it will create another directory named @file{hosts/}.
1566 In the configuration directory, it will create the file @file{tinc.conf} with the following contents:
1567
1568 @example
1569 Name = @var{name}
1570 @end example
1571
1572 It will also create private RSA and Ed25519 keys, which will be stored in the files @file{rsa_key.priv} and @file{ed25519_key.priv}.
1573 It will also create a host configuration file @file{hosts/@var{name}},
1574 which will contain the corresponding public RSA and Ed25519 keys.
1575
1576 Finally, on UNIX operating systems, it will create an executable script @file{tinc-up},
1577 which will initially not do anything except warning that you should edit it.
1578
1579 @subsubheading Step 2.  Modifying the initial configuration.
1580
1581 Unless you want to use tinc in switch mode,
1582 you should now configure which range of addresses you will use on the VPN.
1583 Let's assume you will be part of a VPN which uses the address range 192.168.0.0/16,
1584 and you yourself have a smaller portion of that range: 192.168.2.0/24.
1585 Then you should run the following command:
1586
1587 @example
1588 tinc -n @var{netname} add subnet 192.168.2.0/24
1589 @end example
1590
1591 This will add a Subnet statement to your host configuration file.
1592 Try opening the file @file{@value{sysconfdir}/tinc/@var{netname}/hosts/@var{name}} in an editor.
1593 You should now see a file containing the public RSA and Ed25519 keys (which looks like a bunch of random characters),
1594 and the following line at the bottom:
1595
1596 @example
1597 Subnet = 192.168.2.0/24
1598 @end example
1599
1600 If you will use more than one address range, you can add more Subnets.
1601 For example, if you also use the IPv6 subnet fec0:0:0:2::/64, you can add it as well:
1602
1603 @example
1604 tinc -n @var{netname} add subnet fec0:0:0:2::/24
1605 @end example
1606
1607 This will add another line to the file @file{hosts/@var{name}}.
1608 If you make a mistake, you can undo it by simply using @samp{del} instead of @samp{add}.
1609
1610 If you want other tinc daemons to create meta-connections to your daemon,
1611 you should add your public IP address or hostname to your host configuration file.
1612 For example, if your hostname is foo.example.org, run:
1613
1614 @example
1615 tinc -n @var{netname} add address foo.example.org
1616 @end example
1617
1618 @subsubheading Step 2.  Exchanging configuration files.
1619
1620 In order for two tinc daemons to be able to connect to each other,
1621 they each need the other's host configuration files.
1622 So if you want foo to be able to connect with bar,
1623 You should send @file{hosts/@var{name}} to bar, and bar should send you his file which you should move to @file{hosts/bar}.
1624 If you are on a UNIX platform, you can easily send an email containing the necessary information using the following command
1625 (assuming the owner of bar has the email address bar@@example.org):
1626
1627 @example
1628 tinc -n @var{netname} export | mail -s "My config file" bar@@example.org
1629 @end example
1630
1631 If the owner of bar does the same to send his host configuration file to you,
1632 you can probably pipe his email through the following command,
1633 or you can just start this command in a terminal and copy&paste the email:
1634
1635 @example
1636 tinc -n @var{netname} import
1637 @end example
1638
1639 If you are the owner of bar yourself, and you have SSH access to that computer,
1640 you can also swap the host configuration files using the following command:
1641
1642 @example
1643 tinc -n @var{netname} export \
1644     | ssh bar.example.org tinc -n @var{netname} exchange \
1645     | tinc -n @var{netname} import
1646 @end example
1647
1648 You can repeat this for a few other nodes as well.
1649 It is not necessary to manually exchange host config files between all nodes;
1650 after the initial connections are made tinc will learn about all the other nodes in the VPN,
1651 and will automatically make other connections as necessary.
1652
1653
1654 @c ==================================================================
1655 @node    Network interfaces
1656 @section Network interfaces
1657
1658 Before tinc can start transmitting data over the tunnel, it must
1659 set up the virtual network interface.
1660
1661 First, decide which IP addresses you want to have associated with these
1662 devices, and what network mask they must have.
1663
1664 Tinc will open a virtual network device (@file{/dev/tun}, @file{/dev/tap0} or similar),
1665 which will also create a network interface called something like @samp{tun0}, @samp{tap0}.
1666 If you are using the Linux tun/tap driver, the network interface will by default have the same name as the @var{netname}.
1667 Under Windows you can change the name of the network interface from the Network Connections control panel.
1668
1669 @cindex tinc-up
1670 You can configure the network interface by putting ordinary ifconfig, route, and other commands
1671 to a script named @file{@value{sysconfdir}/tinc/@var{netname}/tinc-up}.
1672 When tinc starts, this script will be executed. When tinc exits, it will execute the script named
1673 @file{@value{sysconfdir}/tinc/@var{netname}/tinc-down}, but normally you don't need to create that script.
1674 You can manually open the script in an editor, or use the following command:
1675
1676 @example
1677 tinc -n @var{netname} edit tinc-up
1678 @end example
1679
1680 An example @file{tinc-up} script, that would be appropriate for the scenario in the previous section, is:
1681
1682 @example
1683 #!/bin/sh
1684 ifconfig $INTERFACE 192.168.2.1 netmask 255.255.0.0
1685 ip addr add fec0:0:0:2::/48 dev $INTERFACE
1686 @end example
1687
1688 The first command gives the interface an IPv4 address and a netmask.
1689 The kernel will also automatically add an IPv4 route to this interface, so normally you don't need
1690 to add route commands to the @file{tinc-up} script.
1691 The kernel will also bring the interface up after this command.
1692 @cindex netmask
1693 The netmask is the mask of the @emph{entire} VPN network, not just your
1694 own subnet.
1695 The second command gives the interface an IPv6 address and netmask,
1696 which will also automatically add an IPv6 route.
1697 If you only want to use "ip addr" commands on Linux, don't forget that it doesn't bring the interface up, unlike ifconfig,
1698 so you need to add @samp{ip link set $INTERFACE up} in that case.
1699
1700 The exact syntax of the ifconfig and route commands differs from platform to platform.
1701 You can look up the commands for setting addresses and adding routes in @ref{Platform specific information},
1702 but it is best to consult the manpages of those utilities on your platform.
1703
1704
1705 @c ==================================================================
1706 @node    Example configuration
1707 @section Example configuration
1708
1709
1710 @cindex example
1711 Imagine the following situation.  Branch A of our example `company' wants to connect
1712 three branch offices in B, C and D using the Internet.  All four offices
1713 have a 24/7 connection to the Internet.
1714
1715 A is going to serve as the center of the network.  B and C will connect
1716 to A, and D will connect to C.  Each office will be assigned their own IP
1717 network, 10.x.0.0.
1718
1719 @example
1720 A: net 10.1.0.0 mask 255.255.0.0 gateway 10.1.54.1 internet IP 1.2.3.4
1721 B: net 10.2.0.0 mask 255.255.0.0 gateway 10.2.1.12 internet IP 2.3.4.5
1722 C: net 10.3.0.0 mask 255.255.0.0 gateway 10.3.69.254 internet IP 3.4.5.6
1723 D: net 10.4.0.0 mask 255.255.0.0 gateway 10.4.3.32 internet IP 4.5.6.7
1724 @end example
1725
1726 Here, ``gateway'' is the VPN IP address of the machine that is running the
1727 tincd, and ``internet IP'' is the IP address of the firewall, which does not
1728 need to run tincd, but it must do a port forwarding of TCP and UDP on port
1729 655 (unless otherwise configured).
1730
1731 In this example, it is assumed that eth0 is the interface that points to
1732 the inner (physical) LAN of the office, although this could also be the
1733 same as the interface that leads to the Internet.  The configuration of
1734 the real interface is also shown as a comment, to give you an idea of
1735 how these example host is set up. All branches use the netname `company'
1736 for this particular VPN.
1737
1738 Each branch is set up using the @samp{tinc init} and @samp{tinc config} commands,
1739 here we just show the end results:
1740
1741 @subsubheading For Branch A
1742
1743 @emph{BranchA} would be configured like this:
1744
1745 In @file{@value{sysconfdir}/tinc/company/tinc-up}:
1746
1747 @example
1748 #!/bin/sh
1749
1750 # Real interface of internal network:
1751 # ifconfig eth0 10.1.54.1 netmask 255.255.0.0
1752
1753 ifconfig $INTERFACE 10.1.54.1 netmask 255.0.0.0
1754 @end example
1755
1756 and in @file{@value{sysconfdir}/tinc/company/tinc.conf}:
1757
1758 @example
1759 Name = BranchA
1760 @end example
1761
1762 On all hosts, @file{@value{sysconfdir}/tinc/company/hosts/BranchA} contains:
1763
1764 @example
1765 Subnet = 10.1.0.0/16
1766 Address = 1.2.3.4
1767
1768 -----BEGIN RSA PUBLIC KEY-----
1769 ...
1770 -----END RSA PUBLIC KEY-----
1771 @end example
1772
1773 Note that the IP addresses of eth0 and the VPN interface are the same.
1774 This is quite possible, if you make sure that the netmasks of the interfaces are different.
1775 It is in fact recommended to give both real internal network interfaces and VPN interfaces the same IP address,
1776 since that will make things a lot easier to remember and set up.
1777
1778
1779 @subsubheading For Branch B
1780
1781 In @file{@value{sysconfdir}/tinc/company/tinc-up}:
1782
1783 @example
1784 #!/bin/sh
1785
1786 # Real interface of internal network:
1787 # ifconfig eth0 10.2.43.8 netmask 255.255.0.0
1788
1789 ifconfig $INTERFACE 10.2.1.12 netmask 255.0.0.0
1790 @end example
1791
1792 and in @file{@value{sysconfdir}/tinc/company/tinc.conf}:
1793
1794 @example
1795 Name = BranchB
1796 @end example
1797
1798 Note here that the internal address (on eth0) doesn't have to be the
1799 same as on the VPN interface.
1800
1801 On all hosts, in @file{@value{sysconfdir}/tinc/company/hosts/BranchB}:
1802
1803 @example
1804 Subnet = 10.2.0.0/16
1805 Address = 2.3.4.5
1806
1807 -----BEGIN RSA PUBLIC KEY-----
1808 ...
1809 -----END RSA PUBLIC KEY-----
1810 @end example
1811
1812
1813 @subsubheading For Branch C
1814
1815 In @file{@value{sysconfdir}/tinc/company/tinc-up}:
1816
1817 @example
1818 #!/bin/sh
1819
1820 # Real interface of internal network:
1821 # ifconfig eth0 10.3.69.254 netmask 255.255.0.0
1822
1823 ifconfig $INTERFACE 10.3.69.254 netmask 255.0.0.0
1824 @end example
1825
1826 and in @file{@value{sysconfdir}/tinc/company/tinc.conf}:
1827
1828 @example
1829 Name = BranchC
1830 @end example
1831
1832 C already has another daemon that runs on port 655, so they have to
1833 reserve another port for tinc. It knows the portnumber it has to listen on
1834 from it's own host configuration file.
1835
1836 On all hosts, in @file{@value{sysconfdir}/tinc/company/hosts/BranchC}:
1837
1838 @example
1839 Address = 3.4.5.6
1840 Subnet = 10.3.0.0/16
1841 Port = 2000
1842
1843 -----BEGIN RSA PUBLIC KEY-----
1844 ...
1845 -----END RSA PUBLIC KEY-----
1846 @end example
1847
1848
1849 @subsubheading For Branch D
1850
1851 In @file{@value{sysconfdir}/tinc/company/tinc-up}:
1852
1853 @example
1854 #!/bin/sh
1855
1856 # Real interface of internal network:
1857 # ifconfig eth0 10.4.3.32 netmask 255.255.0.0
1858
1859 ifconfig $INTERFACE 10.4.3.32 netmask 255.0.0.0
1860 @end example
1861
1862 and in @file{@value{sysconfdir}/tinc/company/tinc.conf}:
1863
1864 @example
1865 Name = BranchD
1866 @end example
1867
1868 D will be connecting to C, which has a tincd running for this network on
1869 port 2000. It knows the port number from the host configuration file.
1870
1871 On all hosts, in @file{@value{sysconfdir}/tinc/company/hosts/BranchD}:
1872
1873 @example
1874 Subnet = 10.4.0.0/16
1875 Address = 4.5.6.7
1876
1877 -----BEGIN RSA PUBLIC KEY-----
1878 ...
1879 -----END RSA PUBLIC KEY-----
1880 @end example
1881
1882 @subsubheading Key files
1883
1884 A, B, C and D all have their own public/private keypairs:
1885
1886 The private RSA key is stored in @file{@value{sysconfdir}/tinc/company/rsa_key.priv},
1887 the private Ed25519 key is stored in @file{@value{sysconfdir}/tinc/company/ed25519_key.priv},
1888 and the public RSA and Ed25519 keys are put into the host configuration file in the @file{@value{sysconfdir}/tinc/company/hosts/} directory.
1889
1890 @subsubheading Starting
1891
1892 After each branch has finished configuration and they have distributed
1893 the host configuration files amongst them, they can start their tinc daemons.
1894 They don't necessarily have to wait for the other branches to have started
1895 their daemons, tinc will try connecting until they are available.
1896
1897
1898 @c ==================================================================
1899 @node    Running tinc
1900 @chapter Running tinc
1901
1902 If everything else is done, you can start tinc by typing the following command:
1903
1904 @example
1905 tinc -n @var{netname} start
1906 @end example
1907
1908 @cindex daemon
1909 Tinc will detach from the terminal and continue to run in the background like a good daemon.
1910 If there are any problems however you can try to increase the debug level
1911 and look in the syslog to find out what the problems are.
1912
1913 @menu
1914 * Runtime options::
1915 * Signals::
1916 * Debug levels::
1917 * Solving problems::
1918 * Error messages::
1919 * Sending bug reports::
1920 @end menu
1921
1922
1923 @c ==================================================================
1924 @node    Runtime options
1925 @section Runtime options
1926
1927 Besides the settings in the configuration file, tinc also accepts some
1928 command line options.
1929
1930 @cindex command line
1931 @cindex runtime options
1932 @cindex options
1933 @c from the manpage
1934 @table @option
1935 @item -c, --config=@var{path}
1936 Read configuration options from the directory @var{path}.  The default is
1937 @file{@value{sysconfdir}/tinc/@var{netname}/}.
1938
1939 @item -D, --no-detach
1940 Don't fork and detach.
1941 This will also disable the automatic restart mechanism for fatal errors.
1942
1943 @cindex debug level
1944 @item -d, --debug=@var{level}
1945 Set debug level to @var{level}.  The higher the debug level, the more gets
1946 logged.  Everything goes via syslog.
1947
1948 @item -n, --net=@var{netname}
1949 Use configuration for net @var{netname}.
1950 This will let tinc read all configuration files from
1951 @file{@value{sysconfdir}/tinc/@var{netname}/}.
1952 Specifying . for @var{netname} is the same as not specifying any @var{netname}.
1953 @xref{Multiple networks}.
1954
1955 @item --pidfile=@var{filename}
1956 Store a cookie in @var{filename} which allows tinc to authenticate.
1957 If unspecified, the default is
1958 @file{@value{runstatedir}/tinc.@var{netname}.pid}.
1959
1960 @item -o, --option=[@var{HOST}.]@var{KEY}=@var{VALUE}
1961 Without specifying a @var{HOST}, this will set server configuration variable @var{KEY} to @var{VALUE}.
1962 If specified as @var{HOST}.@var{KEY}=@var{VALUE},
1963 this will set the host configuration variable @var{KEY} of the host named @var{HOST} to @var{VALUE}.
1964 This option can be used more than once to specify multiple configuration variables.
1965
1966 @item -L, --mlock
1967 Lock tinc into main memory.
1968 This will prevent sensitive data like shared private keys to be written to the system swap files/partitions.
1969
1970 This option is not supported on all platforms.
1971
1972 @item --logfile[=@var{file}]
1973 Write log entries to a file instead of to the system logging facility.
1974 If @var{file} is omitted, the default is @file{@value{localstatedir}/log/tinc.@var{netname}.log}.
1975
1976 @item --pidfile=@var{file}
1977 Write PID to @var{file} instead of @file{@value{runstatedir}/tinc.@var{netname}.pid}.
1978
1979 @item --bypass-security
1980 Disables encryption and authentication.
1981 Only useful for debugging.
1982
1983 @item -R, --chroot
1984 Change process root directory to the directory where the config file is
1985 located (@file{@value{sysconfdir}/tinc/@var{netname}/} as determined by
1986 -n/--net option or as given by -c/--config option), for added security.
1987 The chroot is performed after all the initialization is done, after
1988 writing pid files and opening network sockets.
1989
1990 This option is best used in combination with the -U/--user option described below.
1991
1992 You will need to ensure the chroot environment contains all the files necessary
1993 for tinc to run correctly.
1994 Most importantly, for tinc to be able to resolve hostnames inside the chroot environment,
1995 you must copy @file{/etc/resolv.conf} into the chroot directory.
1996 If you want to be able to run scripts other than @file{tinc-up} in the chroot,
1997 you must ensure the appropriate shell is also installed in the chroot, along with all its dependencies.
1998
1999 This option is not supported on all platforms.
2000 @item -U, --user=@var{user}
2001 Switch to the given @var{user} after initialization, at the same time as
2002 chroot is performed (see --chroot above).  With this option tinc drops
2003 privileges, for added security.
2004
2005 This option is not supported on all platforms.
2006
2007 @item --help
2008 Display a short reminder of these runtime options and terminate.
2009
2010 @item --version
2011 Output version information and exit.
2012
2013 @end table
2014
2015 @c ==================================================================
2016 @node    Signals
2017 @section Signals
2018
2019 @cindex signals
2020 You can also send the following signals to a running tincd process:
2021
2022 @c from the manpage
2023 @table @samp
2024
2025 @item ALRM
2026 Forces tinc to try to connect to all uplinks immediately.
2027 Usually tinc attempts to do this itself,
2028 but increases the time it waits between the attempts each time it failed,
2029 and if tinc didn't succeed to connect to an uplink the first time after it started,
2030 it defaults to the maximum time of 15 minutes.
2031
2032 @item HUP
2033 Partially rereads configuration files.
2034 Connections to hosts whose host config file are removed are closed.
2035 New outgoing connections specified in @file{tinc.conf} will be made.
2036 If the --logfile option is used, this will also close and reopen the log file,
2037 useful when log rotation is used.
2038
2039 @end table
2040
2041 @c ==================================================================
2042 @node    Debug levels
2043 @section Debug levels
2044
2045 @cindex debug levels
2046 The tinc daemon can send a lot of messages to the syslog.
2047 The higher the debug level, the more messages it will log.
2048 Each level inherits all messages of the previous level:
2049
2050 @c from the manpage
2051 @table @samp
2052
2053 @item 0
2054 This will log a message indicating tinc has started along with a version number.
2055 It will also log any serious error.
2056
2057 @item 1
2058 This will log all connections that are made with other tinc daemons.
2059
2060 @item 2
2061 This will log status and error messages from scripts and other tinc daemons.
2062
2063 @item 3
2064 This will log all requests that are exchanged with other tinc daemons. These include
2065 authentication, key exchange and connection list updates.
2066
2067 @item 4
2068 This will log a copy of everything received on the meta socket.
2069
2070 @item 5
2071 This will log all network traffic over the virtual private network.
2072
2073 @end table
2074
2075 @c ==================================================================
2076 @node    Solving problems
2077 @section Solving problems
2078
2079 If tinc starts without problems, but if the VPN doesn't work, you will have to find the cause of the problem.
2080 The first thing to do is to start tinc with a high debug level in the foreground,
2081 so you can directly see everything tinc logs:
2082
2083 @example
2084 tincd -n @var{netname} -d5 -D
2085 @end example
2086
2087 If tinc does not log any error messages, then you might want to check the following things:
2088
2089 @itemize
2090 @item @file{tinc-up} script
2091 Does this script contain the right commands?
2092 Normally you must give the interface the address of this host on the VPN, and the netmask must be big enough so that the entire VPN is covered.
2093
2094 @item Subnet
2095 Does the Subnet (or Subnets) in the host configuration file of this host match the portion of the VPN that belongs to this host?
2096
2097 @item Firewalls and NATs
2098 Do you have a firewall or a NAT device (a masquerading firewall or perhaps an ADSL router that performs masquerading)?
2099 If so, check that it allows TCP and UDP traffic on port 655.
2100 If it masquerades and the host running tinc is behind it, make sure that it forwards TCP and UDP traffic to port 655 to the host running tinc.
2101 You can add @samp{TCPOnly = yes} to your host config file to force tinc to only use a single TCP connection,
2102 this works through most firewalls and NATs.
2103
2104 @end itemize
2105
2106
2107 @c ==================================================================
2108 @node    Error messages
2109 @section Error messages
2110
2111 What follows is a list of the most common error messages you might find in the logs.
2112 Some of them will only be visible if the debug level is high enough.
2113
2114 @table @samp
2115 @item Could not open /dev/tap0: No such device
2116
2117 @itemize
2118 @item You forgot to `modprobe netlink_dev' or `modprobe ethertap'.
2119 @item You forgot to compile `Netlink device emulation' in the kernel.
2120 @end itemize
2121
2122 @item Can't write to /dev/net/tun: No such device
2123
2124 @itemize
2125 @item You forgot to `modprobe tun'.
2126 @item You forgot to compile `Universal TUN/TAP driver' in the kernel.
2127 @item The tun device is located somewhere else in @file{/dev/}.
2128 @end itemize
2129
2130 @item Network address and prefix length do not match!
2131
2132 @itemize
2133 @item The Subnet field must contain a @emph{network} address, trailing bits should be 0.
2134 @item If you only want to use one IP address, set the netmask to /32.
2135 @end itemize
2136
2137 @item Error reading RSA key file `rsa_key.priv': No such file or directory
2138
2139 @itemize
2140 @item You forgot to create a public/private keypair.
2141 @item Specify the complete pathname to the private key file with the @samp{PrivateKeyFile} option.
2142 @end itemize
2143
2144 @item Warning: insecure file permissions for RSA private key file `rsa_key.priv'!
2145
2146 @itemize
2147 @item The private key file is readable by users other than root.
2148 Use chmod to correct the file permissions.
2149 @end itemize
2150
2151 @item Creating metasocket failed: Address family not supported
2152
2153 @itemize
2154 @item By default tinc tries to create both IPv4 and IPv6 sockets.
2155 On some platforms this might not be implemented.
2156 If the logs show @samp{Ready} later on, then at least one metasocket was created,
2157 and you can ignore this message.
2158 You can add @samp{AddressFamily = ipv4} to @file{tinc.conf} to prevent this from happening.
2159 @end itemize
2160
2161 @item Cannot route packet: unknown IPv4 destination 1.2.3.4
2162
2163 @itemize
2164 @item You try to send traffic to a host on the VPN for which no Subnet is known.
2165 @item If it is a broadcast address (ending in .255), it probably is a samba server or a Windows host sending broadcast packets.
2166 You can ignore it.
2167 @end itemize
2168
2169 @item Cannot route packet: ARP request for unknown address 1.2.3.4
2170
2171 @itemize
2172 @item You try to send traffic to a host on the VPN for which no Subnet is known.
2173 @end itemize
2174
2175 @item Packet with destination 1.2.3.4 is looping back to us!
2176
2177 @itemize
2178 @item Something is not configured right. Packets are being sent out to the
2179 virtual network device, but according to the Subnet directives in your host configuration
2180 file, those packets should go to your own host. Most common mistake is that
2181 you have a Subnet line in your host configuration file with a prefix length which is
2182 just as large as the prefix of the virtual network interface. The latter should in almost all
2183 cases be larger. Rethink your configuration.
2184 Note that you will only see this message if you specified a debug
2185 level of 5 or higher!
2186 @item Chances are that a @samp{Subnet = ...} line in the host configuration file of this tinc daemon is wrong.
2187 Change it to a subnet that is accepted locally by another interface,
2188 or if that is not the case, try changing the prefix length into /32.
2189 @end itemize
2190
2191 @item Node foo (1.2.3.4) is not reachable
2192
2193 @itemize
2194 @item Node foo does not have a connection anymore, its tinc daemon is not running or its connection to the Internet is broken.
2195 @end itemize
2196
2197 @item Received UDP packet from unknown source 1.2.3.4 (port 12345)
2198
2199 @itemize
2200 @item If you see this only sporadically, it is harmless and caused by a node sending packets using an old key.
2201 @item If you see this often and another node is not reachable anymore, then a NAT (masquerading firewall) is changing the source address of UDP packets.
2202 You can add @samp{TCPOnly = yes} to host configuration files to force all VPN traffic to go over a TCP connection.
2203 @end itemize
2204
2205 @item Got bad/bogus/unauthorized REQUEST from foo (1.2.3.4 port 12345)
2206
2207 @itemize
2208 @item Node foo does not have the right public/private keypair.
2209 Generate new keypairs and distribute them again.
2210 @item An attacker tries to gain access to your VPN.
2211 @item A network error caused corruption of metadata sent from foo.
2212 @end itemize
2213
2214 @end table
2215
2216 @c ==================================================================
2217 @node    Sending bug reports
2218 @section Sending bug reports
2219
2220 If you really can't find the cause of a problem, or if you suspect tinc is not working right,
2221 you can send us a bugreport, see @ref{Contact information}.
2222 Be sure to include the following information in your bugreport:
2223
2224 @itemize
2225 @item A clear description of what you are trying to achieve and what the problem is.
2226 @item What platform (operating system, version, hardware architecture) and which version of tinc you use.
2227 @item If compiling tinc fails, a copy of @file{config.log} and the error messages you get.
2228 @item Otherwise, a copy of @file{tinc.conf}, @file{tinc-up} and all files in the @file{hosts/} directory.
2229 @item The output of the commands @samp{ifconfig -a} and @samp{route -n} (or @samp{netstat -rn} if that doesn't work).
2230 @item The output of any command that fails to work as it should (like ping or traceroute).
2231 @end itemize
2232
2233 @c ==================================================================
2234 @node    Controlling tinc
2235 @chapter Controlling tinc
2236
2237 @cindex command line interface
2238 You can start, stop, control and inspect a running tincd through the tinc
2239 command. A quick example:
2240
2241 @example
2242 tinc -n @var{netname} reload
2243 @end example
2244
2245 @cindex shell
2246 If tinc is started without a command, it will act as a shell; it will display a
2247 prompt, and commands can be entered on the prompt. If tinc is compiled with
2248 libreadline, history and command completion are available on the prompt. One
2249 can also pipe a script containing commands through tinc. In that case, lines
2250 starting with a # symbol will be ignored.
2251
2252 @menu
2253 * tinc runtime options::
2254 * tinc environment variables::
2255 * tinc commands::
2256 * tinc examples::
2257 * tinc top::
2258 @end menu
2259
2260
2261 @c ==================================================================
2262 @node    tinc runtime options
2263 @section tinc runtime options
2264
2265 @c from the manpage
2266 @table @option
2267 @item -c, --config=@var{path}
2268 Read configuration options from the directory @var{path}.  The default is
2269 @file{@value{sysconfdir}/tinc/@var{netname}/}.
2270
2271 @item -n, --net=@var{netname}
2272 Use configuration for net @var{netname}. @xref{Multiple networks}.
2273
2274 @item --pidfile=@var{filename}
2275 Use the cookie from @var{filename} to authenticate with a running tinc daemon.
2276 If unspecified, the default is
2277 @file{@value{runstatedir}/tinc.@var{netname}.pid}.
2278
2279 @cindex batch
2280 @item -b, --batch
2281 Don't ask for anything (non-interactive mode).
2282
2283 @item --force
2284 Force some commands to work despite warnings.
2285
2286 @item --help
2287 Display a short reminder of runtime options and commands, then terminate.
2288
2289 @item --version
2290 Output version information and exit.
2291
2292 @end table
2293
2294 @c ==================================================================
2295 @node    tinc environment variables
2296 @section tinc environment variables
2297
2298 @table @env
2299 @cindex NETNAME
2300 @item NETNAME
2301 If no netname is specified on the command line with the @option{-n} option,
2302 the value of this environment variable is used.
2303 @end table
2304
2305 @c ==================================================================
2306 @node    tinc commands
2307 @section tinc commands
2308
2309 @c from the manpage
2310 @table @code
2311
2312 @cindex init
2313 @item init [@var{name}]
2314 Create initial configuration files and RSA and Ed25519 keypairs with default length.
2315 If no @var{name} for this node is given, it will be asked for.
2316
2317 @cindex get
2318 @item get @var{variable}
2319 Print the current value of configuration variable @var{variable}.
2320 If more than one variable with the same name exists,
2321 the value of each of them will be printed on a separate line.
2322
2323 @cindex set
2324 @item set @var{variable} @var{value}
2325 Set configuration variable @var{variable} to the given @var{value}.
2326 All previously existing configuration variables with the same name are removed.
2327 To set a variable for a specific host, use the notation @var{host}.@var{variable}.
2328
2329 @cindex add
2330 @item add @var{variable} @var{value}
2331 As above, but without removing any previously existing configuration variables.
2332 If the variable already exists with the given value, nothing happens.
2333
2334 @cindex del
2335 @item del @var{variable} [@var{value}]
2336 Remove configuration variables with the same name and @var{value}.
2337 If no @var{value} is given, all configuration variables with the same name will be removed.
2338
2339 @cindex edit
2340 @item edit @var{filename}
2341 Start an editor for the given configuration file.
2342 You do not need to specify the full path to the file.
2343
2344 @cindex export
2345 @item export
2346 Export the host configuration file of the local node to standard output.
2347
2348 @cindex export-all
2349 @item export-all
2350 Export all host configuration files to standard output.
2351
2352 @cindex import
2353 @item import
2354 Import host configuration file(s) generated by the tinc export command from standard input.
2355 Already existing host configuration files are not overwritten unless the option --force is used.
2356
2357 @cindex exchange
2358 @item exchange
2359 The same as export followed by import.
2360
2361 @cindex exchange-all
2362 @item exchange-all
2363 The same as export-all followed by import.
2364
2365 @cindex invite
2366 @item invite @var{name}
2367 Prepares an invitation for a new node with the given @var{name},
2368 and prints a short invitation URL that can be used with the join command.
2369
2370 @cindex join
2371 @item join [@var{URL}]
2372 Join an existing VPN using an invitation URL created using the invite command.
2373 If no @var{URL} is given, it will be read from standard input.
2374
2375 @cindex start
2376 @item start [tincd options]
2377 Start @samp{tincd}, optionally with the given extra options.
2378
2379 @cindex stop
2380 @item stop
2381 Stop @samp{tincd}.
2382
2383 @cindex restart
2384 @item restart [tincd options]
2385 Restart @samp{tincd}, optionally with the given extra options.
2386
2387 @cindex reload
2388 @item reload
2389 Partially rereads configuration files. Connections to hosts whose host
2390 config files are removed are closed. New outgoing connections specified
2391 in @file{tinc.conf} will be made.
2392
2393 @cindex pid
2394 @item pid
2395 Shows the PID of the currently running @samp{tincd}.
2396
2397 @cindex generate-keys
2398 @item generate-keys [@var{bits}]
2399 Generate both RSA and Ed25519 keypairs (see below) and exit.
2400 tinc will ask where you want to store the files, but will default to the
2401 configuration directory (you can use the -c or -n option).
2402
2403 @cindex generate-ed25519-keys
2404 @item generate-ed25519-keys
2405 Generate public/private Ed25519 keypair and exit.
2406
2407 @cindex generate-rsa-keys
2408 @item generate-rsa-keys [@var{bits}]
2409 Generate public/private RSA keypair and exit.  If @var{bits} is omitted, the
2410 default length will be 2048 bits.  When saving keys to existing files, tinc
2411 will not delete the old keys; you have to remove them manually.
2412
2413 @cindex dump
2414 @item dump [reachable] nodes
2415 Dump a list of all known nodes in the VPN.
2416 If the reachable keyword is used, only lists reachable nodes.
2417
2418 @item dump edges
2419 Dump a list of all known connections in the VPN.
2420
2421 @item dump subnets
2422 Dump a list of all known subnets in the VPN.
2423
2424 @item dump connections
2425 Dump a list of all meta connections with ourself.
2426
2427 @cindex graph
2428 @item dump graph | digraph
2429 Dump a graph of the VPN in dotty format.
2430 Nodes are colored according to their reachability:
2431 red nodes are unreachable, orange nodes are indirectly reachable, green nodes are directly reachable.
2432 Black nodes are either directly or indirectly reachable, but direct reachability has not been tried yet.
2433
2434 @item dump invitations
2435 Dump a list of outstanding invitations.
2436 The filename of the invitation, as well as the name of the node that is being invited is shown for each invitation.
2437
2438 @cindex info
2439 @item info @var{node} | @var{subnet} | @var{address}
2440 Show information about a particular @var{node}, @var{subnet} or @var{address}.
2441 If an @var{address} is given, any matching subnet will be shown.
2442
2443 @cindex purge
2444 @item purge
2445 Purges all information remembered about unreachable nodes.
2446
2447 @cindex debug
2448 @item debug @var{level}
2449 Sets debug level to @var{level}.
2450
2451 @cindex log
2452 @item log [@var{level}]
2453 Capture log messages from a running tinc daemon.
2454 An optional debug level can be given that will be applied only for log messages sent to tinc.
2455
2456 @cindex retry
2457 @item retry
2458 Forces tinc to try to connect to all uplinks immediately.
2459 Usually tinc attempts to do this itself,
2460 but increases the time it waits between the attempts each time it failed,
2461 and if tinc didn't succeed to connect to an uplink the first time after it started,
2462 it defaults to the maximum time of 15 minutes.
2463
2464 @cindex disconnect
2465 @item disconnect @var{node}
2466 Closes the meta connection with the given @var{node}.
2467
2468 @cindex top
2469 @item top
2470 If tinc is compiled with libcurses support, this will display live traffic statistics for all the known nodes,
2471 similar to the UNIX top command.
2472 See below for more information.
2473
2474 @cindex pcap
2475 @item pcap
2476 Dump VPN traffic going through the local tinc node in pcap-savefile format to standard output,
2477 from where it can be redirected to a file or piped through a program that can parse it directly,
2478 such as tcpdump.
2479
2480 @cindex network
2481 @item network [@var{netname}]
2482 If @var{netname} is given, switch to that network.
2483 Otherwise, display a list of all networks for which configuration files exist.
2484
2485 @cindex fsck
2486 @item fsck
2487 This will check the configuration files for possible problems,
2488 such as unsafe file permissions, missing executable bit on script,
2489 unknown and obsolete configuration variables, wrong public and/or private keys, and so on.
2490
2491 When problems are found, this will be printed on a line with WARNING or ERROR in front of it.
2492 Most problems must be corrected by the user itself, however in some cases (like file permissions and missing public keys),
2493 tinc will ask if it should fix the problem.
2494
2495 @cindex sign
2496 @item sign [@var{filename}]
2497 Sign a file with the local node's private key.
2498 If no @var{filename} is given, the file is read from standard input.
2499 The signed file is written to standard output.
2500
2501 @cindex verify
2502 @item verify @var{name} [@var{filename}]
2503
2504 Check the signature of a file against a node's public key.
2505 The @var{name} of the node must be given,
2506 or can be "." to check against the local node's public key,
2507 or "*" to allow a signature from any node whose public key is known.
2508 If no @var{filename} is given, the file is read from standard input.
2509 If the verification is successful, a copy of the input with the signature removed is written to standard output, and the exit code will be zero.
2510 If the verification failed, nothing will be written to standard output, and the exit code will be non-zero.
2511
2512 @end table
2513
2514 @c ==================================================================
2515 @node    tinc examples
2516 @section tinc examples
2517
2518 Examples of some commands:
2519
2520 @example
2521 tinc -n vpn dump graph | circo -Txlib
2522 tinc -n vpn pcap | tcpdump -r -
2523 tinc -n vpn top
2524 @end example
2525
2526 Examples of changing the configuration using tinc:
2527
2528 @example
2529 tinc -n vpn init foo
2530 tinc -n vpn add Subnet 192.168.1.0/24
2531 tinc -n vpn add bar.Address bar.example.com
2532 tinc -n vpn set Mode switch
2533 tinc -n vpn export | gpg --clearsign | mail -s "My config" vpnmaster@@example.com
2534 @end example
2535
2536 @c ==================================================================
2537 @node    tinc top
2538 @section tinc top
2539
2540 @cindex top
2541 The top command connects to a running tinc daemon and repeatedly queries its per-node traffic counters.
2542 It displays a list of all the known nodes in the left-most column,
2543 and the amount of bytes and packets read from and sent to each node in the other columns.
2544 By default, the information is updated every second.
2545 The behaviour of the top command can be changed using the following keys:
2546
2547 @table @key
2548
2549 @item s
2550 Change the interval between updates.
2551 After pressing the @key{s} key, enter the desired interval in seconds, followed by enter.
2552 Fractional seconds are honored.
2553 Intervals lower than 0.1 seconds are not allowed.
2554
2555 @item c
2556 Toggle between displaying current traffic rates (in packets and bytes per second)
2557 and cumulative traffic (total packets and bytes since the tinc daemon started).
2558
2559 @item n
2560 Sort the list of nodes by name.
2561
2562 @item i
2563 Sort the list of nodes by incoming amount of bytes.
2564
2565 @item I
2566 Sort the list of nodes by incoming amount of packets.
2567
2568 @item o
2569 Sort the list of nodes by outgoing amount of bytes.
2570
2571 @item O
2572 Sort the list of nodes by outgoing amount of packets.
2573
2574 @item t
2575 Sort the list of nodes by sum of incoming and outgoing amount of bytes.
2576
2577 @item T
2578 Sort the list of nodes by sum of incoming and outgoing amount of packets.
2579
2580 @item b
2581 Show amount of traffic in bytes.
2582
2583 @item k
2584 Show amount of traffic in kilobytes.
2585
2586 @item M
2587 Show amount of traffic in megabytes.
2588
2589 @item G
2590 Show amount of traffic in gigabytes.
2591
2592 @item q
2593 Quit.
2594
2595 @end table
2596
2597
2598 @c ==================================================================
2599 @node    Invitations
2600 @chapter Invitations
2601
2602 Invitations are an easy way to add new nodes to an existing VPN.  Invitations
2603 can be created on an existing node using the @code{tinc invite} command, which
2604 generates a relatively short URL which can be given to someone else, who uses
2605 the @code{tinc join} command to automatically set up tinc so it can connect to
2606 the inviting node.  The next sections describe how invitations actually work,
2607 and how to further automate the invitations.
2608
2609 @menu
2610 * How invitations work::
2611 * Invitation file format::
2612 * Writing an invitation-created script::
2613 @end menu
2614
2615
2616 @c ==================================================================
2617 @node    How invitations work
2618 @section How invitations work
2619
2620 When an invitation is created on a node (which from now on we will call the
2621 server) using the @code{tinc invite} command, an invitation file is created
2622 that contains all the information necessary for the invitee (which we will call
2623 the client) to create its configuration files. The invitation file is stays on
2624 the server, but a URL is generated that has enough information for the client
2625 to contact the server and to retrieve the invitation file. The whole URL is
2626 around 80 characters long and looks like this:
2627
2628 @example
2629 server.example.org:12345/cW1NhLHS-1WPFlcFio8ztYHvewTTKYZp8BjEKg3vbMtDz7w4
2630 @end example
2631
2632 It is composed of four parts:
2633
2634 @example
2635 hostname : port / keyhash cookie
2636 @end example
2637
2638 The hostname and port tell the client how to reach the tinc daemon on the server.
2639 The part after the slash looks like one blob, but is composed of two parts.
2640 The keyhash is the hash of the public key of the server.
2641 The cookie is a shared secret that identifies the client to the server.
2642
2643 When the client connects to the server in order to join the VPN, the client and
2644 server will exchange temporary public keys. The client verifies that the hash
2645 of the server's public key matches the keyhash from the invitation URL. If
2646 not, it will immediately exit with an error. Otherwise, an ECDH exchange will
2647 happen so the client and server can communicate privately with each other. The
2648 client will then present the cookie to the server. The server uses this to
2649 look up the corresponding invitation file it generated earlier. If it exists,
2650 it will send the invitation file to the client. The client will also create a
2651 permanent public key, and send it to the server. After the exchange is
2652 completed, the connection is broken. The server creates a host config file for
2653 the client containing the client's permanent public key, and the client creates
2654 tinc.conf, host config files and possibly a tinc-up script based on the
2655 information in the invitation file.
2656
2657 It is important that the invitation URL is kept secret until it is used; if
2658 another person gets a copy of the invitation URL before the real client runs
2659 the @code{tinc join} command, then that other person can try to join the VPN.
2660
2661
2662 @c ==================================================================
2663 @node    Invitation file format
2664 @section Invitation file format
2665
2666 The contents of an invitation file that is generated by the @code{tinc invite}
2667 command looks like this:
2668
2669 @example
2670 Name = client
2671 Netname = vpn
2672 ConnectTo = server
2673 #-------------------------------------#
2674 Name = server
2675 Ed25519PublicKey = augbnwegoij123587...
2676 Address = server.example.com
2677 @end example
2678
2679 The file is basically a concatenation of several host config blocks. Each host
2680 config block starts with @code{Name = ...}.  Lines that look like @code{#---#}
2681 are not important, it just makes it easier for humans to read the file.
2682 However, the first line of an invitation file @emph{must} always start with
2683 @code{Name = ...}.
2684
2685 The first host config block is always the one representing the invitee. So the
2686 first Name statement determines the name that the invitee will get. From the
2687 first block, the @file{tinc.conf} and @file{hosts/client} files will be
2688 generated; the @code{tinc join} command on the client will automatically
2689 separate statements based on whether they should be in @file{tinc.conf} or in a
2690 host config file. Some statements are special and are treated differently:
2691
2692 @table @asis
2693 @item Netname = <@var{netname}>
2694 This is a hint to the invitee which netname to use for the VPN.  It is used if
2695 the invitee did not already specify a netname, and if there is no pre-existing
2696 configuration with the same netname.
2697
2698 @cindex Ifconfig
2699 @item Ifconfig = <@var{address}[/@var{netmask}] | dhcp | dhcp6 | slaac>
2700 This is a hint for generating a @file{tinc-up} script.
2701 If an address is specified, a command will be added to @file{tinc-up} so the VPN interface will be configured to have the given address.
2702 If it is the word "dhcp", a command will be added to start a DHCP client on the VPN interface.
2703 If it is the word dhcpv6, it will be a DHCPv6 client.
2704 If it is "slaac", then it will add commands to enable IPv6 stateless address autoconfiguration.
2705 It is also possible to specify a MAC address, in which case a command will be added to set the MAC address of the VPN interface.
2706
2707 The exact commands added to the @file{tinc-up} script depends on the operating system the client is using.
2708 Multiple Ifconfig statements can be specified, however one should only use one Ifconfig statement per address family.
2709
2710 @cindex Route
2711 @item Route = <@var{address}[/@var{netmask}]> [<@var{gateway}>]
2712 This is a hint for generating a @file{tinc-up} script.
2713 Route statements are similar to Ifconfig statements, but add routes instead of addresses.
2714 These only allow IPv4 and IPv6 routes.
2715 If no gateway address is specified, the route is directed to the VPN interface.
2716 In general, a gateway is only necessary when running tinc in switch mode.
2717 @end table
2718
2719 Subsequent host config blocks are copied verbatim into their respective files
2720 in @file{hosts/}. The invitation file generated by @code{tinc invite} will
2721 normally only contain two blocks; one for the client and one for the server.
2722
2723
2724 @c ==================================================================
2725 @node    Writing an invitation-created script
2726 @section Writing an invitation-created script
2727
2728 When an invitation is generated, the "invitation-created" script is called (if
2729 it exists) right after the invitation file is written, but before the URL has
2730 been written to stdout. This allows one to change the invitation file
2731 automatically before the invitation URL is passed to the invitee. Here is an
2732 example shell script that approximately recreates the default invitation file:
2733
2734 @example
2735 #!/bin/sh
2736
2737 cat >$INVITATION_FILE <<EOF
2738 Name = $NODE
2739 Netname = $NETNAME
2740 ConnectTo = $NAME
2741 #----------------#
2742 EOF
2743
2744 tinc export >>$INVITATION_FILE
2745 @end example
2746
2747 You can add more ConnectTo statements, and change `tinc export` to `tinc
2748 export-all` for example. But you can also use the script to automatically hand
2749 out a Subnet to the invitee. Note that the script doesn't have to be a shell script,
2750 you can use any language, it just has to be executable.
2751
2752
2753 @c ==================================================================
2754 @node    Technical information
2755 @chapter Technical information
2756
2757
2758 @menu
2759 * The connection::
2760 * The meta-protocol::
2761 * Security::
2762 @end menu
2763
2764
2765 @c ==================================================================
2766 @node    The connection
2767 @section The connection
2768
2769 @cindex connection
2770 Tinc is a daemon that takes VPN data and transmit that to another host
2771 computer over the existing Internet infrastructure.
2772
2773 @menu
2774 * The UDP tunnel::
2775 * The meta-connection::
2776 @end menu
2777
2778
2779 @c ==================================================================
2780 @node    The UDP tunnel
2781 @subsection The UDP tunnel
2782
2783 @cindex virtual network device
2784 @cindex frame type
2785 The data itself is read from a character device file, the so-called
2786 @emph{virtual network device}.  This device is associated with a network
2787 interface.  Any data sent to this interface can be read from the device,
2788 and any data written to the device gets sent from the interface.
2789 There are two possible types of virtual network devices:
2790 `tun' style, which are point-to-point devices which can only handle IPv4 and/or IPv6 packets,
2791 and `tap' style, which are Ethernet devices and handle complete Ethernet frames.
2792
2793 So when tinc reads an Ethernet frame from the device, it determines its
2794 type. When tinc is in it's default routing mode, it can handle IPv4 and IPv6
2795 packets. Depending on the Subnet lines, it will send the packets off to their destination IP address.
2796 In the `switch' and `hub' mode, tinc will use broadcasts and MAC address discovery
2797 to deduce the destination of the packets.
2798 Since the latter modes only depend on the link layer information,
2799 any protocol that runs over Ethernet is supported (for instance IPX and Appletalk).
2800 However, only `tap' style devices provide this information.
2801
2802 After the destination has been determined,
2803 the packet will be compressed (optionally),
2804 a sequence number will be added to the packet,
2805 the packet will then be encrypted
2806 and a message authentication code will be appended.
2807
2808 @cindex encapsulating
2809 @cindex UDP
2810 When that is done, time has come to actually transport the
2811 packet to the destination computer.  We do this by sending the packet
2812 over an UDP connection to the destination host.  This is called
2813 @emph{encapsulating}, the VPN packet (though now encrypted) is
2814 encapsulated in another IP datagram.
2815
2816 When the destination receives this packet, the same thing happens, only
2817 in reverse.  So it checks the message authentication code, decrypts the contents of the UDP datagram,
2818 checks the sequence number
2819 and writes the decrypted information to its own virtual network device.
2820
2821 If the virtual network device is a `tun' device (a point-to-point tunnel),
2822 there is no problem for the kernel to accept a packet.
2823 However, if it is a `tap' device (this is the only available type on FreeBSD),
2824 the destination MAC address must match that of the virtual network interface.
2825 If tinc is in it's default routing mode, ARP does not work, so the correct destination MAC
2826 can not be known by the sending host.
2827 Tinc solves this by letting the receiving end detect the MAC address of its own virtual network interface
2828 and overwriting the destination MAC address of the received packet.
2829
2830 In switch or hub modes ARP does work so the sender already knows the correct destination MAC address.
2831 In those modes every interface should have a unique MAC address, so make sure they are not the same.
2832 Because switch and hub modes rely on MAC addresses to function correctly,
2833 these modes cannot be used on the following operating systems which don't have a `tap' style virtual network device:
2834 NetBSD, Darwin and Solaris.
2835
2836
2837 @c ==================================================================
2838 @node    The meta-connection
2839 @subsection The meta-connection
2840
2841 Having only a UDP connection available is not enough.  Though suitable
2842 for transmitting data, we want to be able to reliably send other
2843 information, such as routing and session key information to somebody.
2844
2845 @cindex TCP
2846 TCP is a better alternative, because it already contains protection
2847 against information being lost, unlike UDP.
2848
2849 So we establish two connections.  One for the encrypted VPN data, and one
2850 for other information, the meta-data.  Hence, we call the second
2851 connection the meta-connection.  We can now be sure that the
2852 meta-information doesn't get lost on the way to another computer.
2853
2854 @cindex data-protocol
2855 @cindex meta-protocol
2856 Like with any communication, we must have a protocol, so that everybody
2857 knows what everything stands for, and how she should react.  Because we
2858 have two connections, we also have two protocols.  The protocol used for
2859 the UDP data is the ``data-protocol,'' the other one is the
2860 ``meta-protocol.''
2861
2862 The reason we don't use TCP for both protocols is that UDP is much
2863 better for encapsulation, even while it is less reliable.  The real
2864 problem is that when TCP would be used to encapsulate a TCP stream
2865 that's on the private network, for every packet sent there would be
2866 three ACKs sent instead of just one.  Furthermore, if there would be
2867 a timeout, both TCP streams would sense the timeout, and both would
2868 start re-sending packets.
2869
2870
2871 @c ==================================================================
2872 @node    The meta-protocol
2873 @section The meta-protocol
2874
2875 The meta protocol is used to tie all tinc daemons together, and
2876 exchange information about which tinc daemon serves which virtual
2877 subnet.
2878
2879 The meta protocol consists of requests that can be sent to the other
2880 side.  Each request has a unique number and several parameters.  All
2881 requests are represented in the standard ASCII character set.  It is
2882 possible to use tools such as telnet or netcat to connect to a tinc
2883 daemon started with the --bypass-security option
2884 and to read and write requests by hand, provided that one
2885 understands the numeric codes sent.
2886
2887 The authentication scheme is described in @ref{Security}. After a
2888 successful authentication, the server and the client will exchange all the
2889 information about other tinc daemons and subnets they know of, so that both
2890 sides (and all the other tinc daemons behind them) have their information
2891 synchronised.
2892
2893 @cindex ADD_EDGE
2894 @cindex ADD_SUBNET
2895 @example
2896 message
2897 ------------------------------------------------------------------
2898 ADD_EDGE node1 node2 21.32.43.54 655 222 0
2899           |     |        |       |   |  +-> options
2900           |     |        |       |   +----> weight
2901           |     |        |       +--------> UDP port of node2
2902           |     |        +----------------> real address of node2
2903           |     +-------------------------> name of destination node
2904           +-------------------------------> name of source node
2905
2906 ADD_SUBNET node 192.168.1.0/24
2907             |         |     +--> prefixlength
2908             |         +--------> network address
2909             +------------------> owner of this subnet
2910 ------------------------------------------------------------------
2911 @end example
2912
2913 The ADD_EDGE messages are to inform other tinc daemons that a connection between
2914 two nodes exist. The address of the destination node is available so that
2915 VPN packets can be sent directly to that node.
2916
2917 The ADD_SUBNET messages inform other tinc daemons that certain subnets belong
2918 to certain nodes. tinc will use it to determine to which node a VPN packet has
2919 to be sent.
2920
2921 @cindex DEL_EDGE
2922 @cindex DEL_SUBNET
2923 @example
2924 message
2925 ------------------------------------------------------------------
2926 DEL_EDGE node1 node2
2927            |     +----> name of destination node
2928            +----------> name of source node
2929
2930 DEL_SUBNET node 192.168.1.0/24
2931              |         |     +--> prefixlength
2932              |         +--------> network address
2933              +------------------> owner of this subnet
2934 ------------------------------------------------------------------
2935 @end example
2936
2937 In case a connection between two daemons is closed or broken, DEL_EDGE messages
2938 are sent to inform the other daemons of that fact. Each daemon will calculate a
2939 new route to the the daemons, or mark them unreachable if there isn't any.
2940
2941 @cindex REQ_KEY
2942 @cindex ANS_KEY
2943 @cindex KEY_CHANGED
2944 @example
2945 message
2946 ------------------------------------------------------------------
2947 REQ_KEY origin destination
2948            |       +--> name of the tinc daemon it wants the key from
2949            +----------> name of the daemon that wants the key
2950
2951 ANS_KEY origin destination 4ae0b0a82d6e0078 91 64 4
2952            |       |       \______________/ |  |  +--> MAC length
2953            |       |               |        |  +-----> digest algorithm
2954            |       |               |        +--------> cipher algorithm
2955            |       |               +--> 128 bits key
2956            |       +--> name of the daemon that wants the key
2957            +----------> name of the daemon that uses this key
2958
2959 KEY_CHANGED origin
2960               +--> daemon that has changed it's packet key
2961 ------------------------------------------------------------------
2962 @end example
2963
2964 The keys used to encrypt VPN packets are not sent out directly. This is
2965 because it would generate a lot of traffic on VPNs with many daemons, and
2966 chances are that not every tinc daemon will ever send a packet to every
2967 other daemon. Instead, if a daemon needs a key it sends a request for it
2968 via the meta connection of the nearest hop in the direction of the
2969 destination.
2970
2971 @cindex PING
2972 @cindex PONG
2973 @example
2974 daemon  message
2975 ------------------------------------------------------------------
2976 origin  PING
2977 dest.   PONG
2978 ------------------------------------------------------------------
2979 @end example
2980
2981 There is also a mechanism to check if hosts are still alive. Since network
2982 failures or a crash can cause a daemon to be killed without properly
2983 shutting down the TCP connection, this is necessary to keep an up to date
2984 connection list. PINGs are sent at regular intervals, except when there
2985 is also some other traffic. A little bit of salt (random data) is added
2986 with each PING and PONG message, to make sure that long sequences of PING/PONG
2987 messages without any other traffic won't result in known plaintext.
2988
2989 This basically covers what is sent over the meta connection by tinc.
2990
2991
2992 @c ==================================================================
2993 @node    Security
2994 @section Security
2995
2996 @cindex TINC
2997 @cindex Cabal
2998 Tinc got its name from ``TINC,'' short for @emph{There Is No Cabal}; the
2999 alleged Cabal was/is an organisation that was said to keep an eye on the
3000 entire Internet.  As this is exactly what you @emph{don't} want, we named
3001 the tinc project after TINC.
3002
3003 @cindex SVPN
3004 But in order to be ``immune'' to eavesdropping, you'll have to encrypt
3005 your data. Because tinc is a @emph{Secure} VPN (SVPN) daemon, it does
3006 exactly that: encrypt.
3007 However, encryption in itself does not prevent an attacker from modifying the encrypted data.
3008 Therefore, tinc also authenticates the data.
3009 Finally, tinc uses sequence numbers (which themselves are also authenticated) to prevent an attacker from replaying valid packets.
3010
3011 Since version 1.1pre3, tinc has two protocols used to protect your data; the legacy protocol, and the new Simple Peer-to-Peer Security (SPTPS) protocol.
3012 The SPTPS protocol is designed to address some weaknesses in the legacy protocol.
3013 The new authentication protocol is used when two nodes connect to each other that both have the ExperimentalProtocol option set to yes,
3014 otherwise the legacy protocol will be used.
3015
3016 @menu
3017 * Legacy authentication protocol::
3018 * Simple Peer-to-Peer Security::
3019 * Encryption of network packets::
3020 * Security issues::
3021 @end menu
3022
3023
3024 @c ==================================================================
3025 @node       Legacy authentication protocol
3026 @subsection Legacy authentication protocol
3027
3028 @cindex legacy authentication protocol
3029
3030 @cindex ID
3031 @cindex META_KEY
3032 @cindex CHALLENGE
3033 @cindex CHAL_REPLY
3034 @cindex ACK
3035 @example
3036 daemon  message
3037 --------------------------------------------------------------------------
3038 client  <attempts connection>
3039
3040 server  <accepts connection>
3041
3042 client  ID client 17.2
3043               |   |  +-> minor protocol version
3044               |   +----> major protocol version
3045               +--------> name of tinc daemon
3046
3047 server  ID server 17.2
3048               |   |  +-> minor protocol version
3049               |   +----> major protocol version
3050               +--------> name of tinc daemon
3051
3052 client  META_KEY 94 64 0 0 5f0823a93e35b69e...7086ec7866ce582b
3053                  |  |  | | \_________________________________/
3054                  |  |  | |                 +-> RSAKEYLEN bits totally random string S1,
3055                  |  |  | |                     encrypted with server's public RSA key
3056                  |  |  | +-> compression level
3057                  |  |  +---> MAC length
3058                  |  +------> digest algorithm NID
3059                  +---------> cipher algorithm NID
3060
3061 server  META_KEY 94 64 0 0 6ab9c1640388f8f0...45d1a07f8a672630
3062                  |  |  | | \_________________________________/
3063                  |  |  | |                 +-> RSAKEYLEN bits totally random string S2,
3064                  |  |  | |                     encrypted with client's public RSA key
3065                  |  |  | +-> compression level
3066                  |  |  +---> MAC length
3067                  |  +------> digest algorithm NID
3068                  +---------> cipher algorithm NID
3069 --------------------------------------------------------------------------
3070 @end example
3071
3072 The protocol allows each side to specify encryption algorithms and parameters,
3073 but in practice they are always fixed, since older versions of tinc did not
3074 allow them to be different from the default values. The cipher is always
3075 Blowfish in OFB mode, the digest is SHA1, but the MAC length is zero and no
3076 compression is used.
3077
3078 From now on:
3079 @itemize
3080 @item the client will symmetrically encrypt outgoing traffic using S1
3081 @item the server will symmetrically encrypt outgoing traffic using S2
3082 @end itemize
3083
3084 @example
3085 --------------------------------------------------------------------------
3086 client  CHALLENGE da02add1817c1920989ba6ae2a49cecbda0
3087                   \_________________________________/
3088                                  +-> CHALLEN bits totally random string H1
3089
3090 server  CHALLENGE 57fb4b2ccd70d6bb35a64c142f47e61d57f
3091                   \_________________________________/
3092                                  +-> CHALLEN bits totally random string H2
3093
3094 client  CHAL_REPLY 816a86
3095                       +-> 160 bits SHA1 of H2
3096
3097 server  CHAL_REPLY 928ffe
3098                       +-> 160 bits SHA1 of H1
3099
3100 After the correct challenge replies are received, both ends have proved
3101 their identity. Further information is exchanged.
3102
3103 client  ACK 655 123 0
3104              |   |  +-> options
3105              |   +----> estimated weight
3106              +--------> listening port of client
3107
3108 server  ACK 655 321 0
3109              |   |  +-> options
3110              |   +----> estimated weight
3111              +--------> listening port of server
3112 --------------------------------------------------------------------------
3113 @end example
3114
3115 This legacy authentication protocol has several weaknesses, pointed out by security export Peter Gutmann.
3116 First, data is encrypted with RSA without padding.
3117 Padding schemes are designed to prevent attacks when the size of the plaintext is not equal to the size of the RSA key.
3118 Tinc always encrypts random nonces that have the same size as the RSA key, so we do not believe this leads to a break of the security.
3119 There might be timing or other side-channel attacks against RSA encryption and decryption, tinc does not employ any protection against those.
3120 Furthermore, both sides send identical messages to each other, there is no distinction between server and client,
3121 which could make a MITM attack easier.
3122 However, no exploit is known in which a third party who is not already trusted by other nodes in the VPN could gain access.
3123 Finally, the RSA keys are used to directly encrypt the session keys, which means that if the RSA keys are compromised, it is possible to decrypt all previous VPN traffic.
3124 In other words, the legacy protocol does not provide perfect forward secrecy.
3125
3126 @c ==================================================================
3127 @node       Simple Peer-to-Peer Security
3128 @subsection Simple Peer-to-Peer Security
3129 @cindex SPTPS
3130
3131 The SPTPS protocol is designed to address the weaknesses in the legacy protocol.
3132 SPTPS is based on TLS 1.2, but has been simplified: there is no support for exchanging public keys, and there is no cipher suite negotiation.
3133 Instead, SPTPS always uses a very strong cipher suite:
3134 peers authenticate each other using 521 bits ECC keys,
3135 Diffie-Hellman using ephemeral 521 bits ECC keys is used to provide perfect forward secrecy (PFS),
3136 AES-256-CTR is used for encryption, and HMAC-SHA-256 for message authentication.
3137
3138 Similar to TLS, messages are split up in records.
3139 A complete logical record contains the following information:
3140
3141 @itemize
3142 @item uint32_t seqno (network byte order)
3143 @item uint16_t length (network byte order)
3144 @item uint8_t type
3145 @item opaque data[length]
3146 @item opaque hmac[HMAC_SIZE] (HMAC over all preceding fields)
3147 @end itemize
3148
3149 Depending on whether SPTPS records are sent via TCP or UDP, either the seqno or the length field is omitted on the wire
3150 (but they are still included in the calculation of the HMAC);
3151 for TCP packets are guaranteed to arrive in-order so we can infer the seqno, but packets can be split or merged, so we still need the length field to determine the boundaries between records;
3152 for UDP packets we know that there is exactly one record per packet, and we know the length of a packet, but packets can be dropped, duplicated and/or reordered, so we need to include the seqno.
3153
3154 The type field is used to distinguish between application records or handshake records.
3155 Types 0 to 127 are application records, type 128 is a handshake record, and types 129 to 255 are reserved.
3156
3157 Before the initial handshake, no fields are encrypted, and the HMAC field is not present.
3158 After the authentication handshake, the length (if present), type and data fields are encrypted, and the HMAC field is present.
3159 For UDP packets, the seqno field is not encrypted, as it is used to determine the value of the counter used for encryption.
3160
3161 The authentication consists of an exchange of Key EXchange, SIGnature and ACKnowledge messages, transmitted using type 128 records.
3162
3163 Overview:
3164
3165 @example
3166 Initiator   Responder
3167 ---------------------
3168 KEX ->
3169             <- KEX
3170 SIG ->
3171             <- SIG
3172
3173 ...encrypt and HMAC using session keys from now on...
3174
3175 App ->
3176             <- App
3177 ...
3178             ...
3179
3180 ...key renegotiation starts here...
3181
3182 KEX ->
3183             <- KEX
3184 SIG ->
3185             <- SIG
3186 ACK ->
3187             <- ACK
3188
3189 ...encrypt and HMAC using new session keys from now on...
3190
3191 App ->
3192             <- App
3193 ...
3194             ...
3195 ---------------------
3196 @end example
3197
3198 Note that the responder does not need to wait before it receives the first KEX message,
3199 it can immediately send its own once it has accepted an incoming connection.
3200
3201 Key EXchange message:
3202
3203 @itemize
3204 @item uint8_t kex_version (always 0 in this version of SPTPS)
3205 @item opaque nonce[32] (random number)
3206 @item opaque ecdh_key[ECDH_SIZE]
3207 @end itemize
3208
3209 SIGnature message:
3210
3211 @itemize
3212 @item opaque ecdsa_signature[ECDSA_SIZE]
3213 @end itemize
3214
3215 ACKnowledge message:
3216
3217 @itemize
3218 @item empty (only sent after key renegotiation)
3219 @end itemize
3220
3221 Remarks:
3222
3223 @itemize
3224 @item At the start, both peers generate a random nonce and an Elliptic Curve public key and send it to the other in the KEX message.
3225 @item After receiving the other's KEX message, both KEX messages are concatenated (see below),
3226   and the result is signed using ECDSA.
3227   The result is sent to the other.
3228 @item After receiving the other's SIG message, the signature is verified.
3229   If it is correct, the shared secret is calculated from the public keys exchanged in the KEX message using the Elliptic Curve Diffie-Helman algorithm.
3230 @item The shared secret key is expanded using a PRF.
3231   Both nonces and the application specific label are also used as input for the PRF.
3232 @item An ACK message is sent only when doing key renegotiation, and is sent using the old encryption keys.
3233 @item The expanded key is used to key the encryption and HMAC algorithms.
3234 @end itemize
3235
3236 The signature is calculated over this string:
3237
3238 @itemize
3239 @item uint8_t initiator (0 = local peer, 1 = remote peer is initiator)
3240 @item opaque remote_kex_message[1 + 32 + ECDH_SIZE]
3241 @item opaque local_kex_message[1 + 32 + ECDH_SIZE]
3242 @item opaque label[label_length]
3243 @end itemize
3244
3245 The PRF is calculated as follows:
3246
3247 @itemize
3248 @item A HMAC using SHA512 is used, the shared secret is used as the key.
3249 @item For each block of 64 bytes, a HMAC is calculated. For block n: hmac[n] =
3250   HMAC_SHA512(hmac[n - 1] + seed)
3251 @item For the first block (n = 1), hmac[0] is given by HMAC_SHA512(zeroes + seed),
3252   where zeroes is a block of 64 zero bytes.
3253 @end itemize
3254
3255 The seed is as follows:
3256
3257 @itemize
3258 @item const char[13] "key expansion"
3259 @item opaque responder_nonce[32]
3260 @item opaque initiator_nonce[32]
3261 @item opaque label[label_length]
3262 @end itemize
3263
3264 The expanded key is used as follows:
3265
3266 @itemize
3267 @item opaque responder_cipher_key[CIPHER_KEYSIZE]
3268 @item opaque responder_digest_key[DIGEST_KEYSIZE]
3269 @item opaque initiator_cipher_key[CIPHER_KEYSIZE]
3270 @item opaque initiator_digest_key[DIGEST_KEYSIZE]
3271 @end itemize
3272
3273 Where initiator_cipher_key is the key used by session initiator to encrypt
3274 messages sent to the responder.
3275
3276 When using 256 bits Ed25519 keys, the AES-256-CTR cipher and HMAC-SHA-256 digest algorithm,
3277 the sizes are as follows:
3278
3279 @example
3280 ECDH_SIZE:       32 (= 256/8)
3281 ECDSA_SIZE:      64 (= 2 * 256/8)
3282 CIPHER_KEYSIZE:  48 (= 256/8 + 128/8)
3283 DIGEST_KEYSIZE:  32 (= 256/8)
3284 @end example
3285
3286 Note that the cipher key also includes the initial value for the counter.
3287
3288 @c ==================================================================
3289 @node       Encryption of network packets
3290 @subsection Encryption of network packets
3291 @cindex encryption
3292
3293 A data packet can only be sent if the encryption key is known to both
3294 parties, and the connection is  activated. If the encryption key is not
3295 known, a request is sent to the destination using the meta connection
3296 to retrieve it.
3297
3298 @cindex UDP
3299 The UDP packets can be either encrypted with the legacy protocol or with SPTPS.
3300 In case of the legacy protocol, the UDP packet containing the network packet from the VPN has the following layout:
3301
3302 @example
3303 ... | IP header | UDP header | seqno | VPN packet | MAC | UDP trailer
3304                              \___________________/\_____/
3305                                        |             |
3306                                        V             +---> digest algorithm
3307                          Encrypted with symmetric cipher
3308 @end example
3309
3310
3311
3312
3313 So, the entire VPN packet is encrypted using a symmetric cipher, including a 32 bits
3314 sequence number that is added in front of the actual VPN packet, to act as a unique
3315 IV for each packet and to prevent replay attacks. A message authentication code
3316 is added to the UDP packet to prevent alteration of packets.
3317 Tinc by default encrypts network packets using Blowfish with 128 bit keys in CBC mode
3318 and uses 4 byte long message authentication codes to make sure
3319 eavesdroppers cannot get and cannot change any information at all from the
3320 packets they can intercept. The encryption algorithm and message authentication
3321 algorithm can be changed in the configuration. The length of the message
3322 authentication codes is also adjustable. The length of the key for the
3323 encryption algorithm is always the default length used by LibreSSL/OpenSSL.
3324
3325 The SPTPS protocol is described in @ref{Simple Peer-to-Peer Security}.
3326 For comparison, this is how SPTPS UDP packets look:
3327
3328 @example
3329 ... | IP header | UDP header | seqno | type | VPN packet | MAC | UDP trailer
3330                                      \__________________/\_____/
3331                                                |            |
3332                                                V            +---> digest algorithm
3333                                  Encrypted with symmetric cipher
3334 @end example
3335
3336 The difference is that the seqno is not encrypted, since the encryption cipher is used in CTR mode,
3337 and therefore the seqno must be known before the packet can be decrypted.
3338 Furthermore, the MAC is never truncated.
3339 The SPTPS protocol always uses the AES-256-CTR cipher and HMAC-SHA-256 digest,
3340 this cannot be changed.
3341
3342
3343 @c ==================================================================
3344 @node    Security issues
3345 @subsection Security issues
3346
3347 In August 2000, we discovered the existence of a security hole in all versions
3348 of tinc up to and including 1.0pre2. This had to do with the way we exchanged
3349 keys. Since then, we have been working on a new authentication scheme to make
3350 tinc as secure as possible. The current version uses the LibreSSL or OpenSSL library and
3351 uses strong authentication with RSA keys.
3352
3353 On the 29th of December 2001, Jerome Etienne posted a security analysis of tinc
3354 1.0pre4. Due to a lack of sequence numbers and a message authentication code
3355 for each packet, an attacker could possibly disrupt certain network services or
3356 launch a denial of service attack by replaying intercepted packets. The current
3357 version adds sequence numbers and message authentication codes to prevent such
3358 attacks.
3359
3360 On the 15th of September 2003, Peter Gutmann posted a security analysis of tinc
3361 1.0.1. He argues that the 32 bit sequence number used by tinc is not a good IV,
3362 that tinc's default length of 4 bytes for the MAC is too short, and he doesn't
3363 like tinc's use of RSA during authentication. We do not know of a security hole
3364 in the legacy protocol of tinc, but it is not as strong as TLS or IPsec.
3365
3366 The Sweet32 attack affects versions of tinc prior to 1.0.30.
3367
3368 On September 6th, 2018, Michael Yonly contacted us and provided
3369 proof-of-concept code that allowed a remote attacker to create an
3370 authenticated, one-way connection with a node, and also that there was a
3371 possibility for a man-in-the-middle to force UDP packets from a node to be sent
3372 in plaintext. The first issue was trivial to exploit on tinc versions prior to
3373 1.0.30, but the changes in 1.0.30 to mitigate the Sweet32 attack made this
3374 weakness much harder to exploit. These issues have been fixed in tinc 1.0.35.
3375
3376 This version of tinc comes with an improved protocol, called Simple
3377 Peer-to-Peer Security (SPTPS), which aims to be as strong as TLS with one of
3378 the strongest cipher suites.  None of the above security issues affected SPTPS.
3379 However, be aware that SPTPS is only used between nodes running tinc 1.1pre* or
3380 later, and in a VPN with nodes running different versions, the security might
3381 only be as good as that of the oldest version.
3382
3383 Cryptography is a hard thing to get right. We cannot make any
3384 guarantees. Time, review and feedback are the only things that can
3385 prove the security of any cryptographic product. If you wish to review
3386 tinc or give us feedback, you are strongly encouraged to do so.
3387
3388
3389 @c ==================================================================
3390 @node    Platform specific information
3391 @chapter Platform specific information
3392
3393 @menu
3394 * Interface configuration::
3395 * Routes::
3396 * Automatically starting tinc::
3397 @end menu
3398
3399 @c ==================================================================
3400 @node    Interface configuration
3401 @section Interface configuration
3402
3403 When configuring an interface, one normally assigns it an address and a
3404 netmask.  The address uniquely identifies the host on the network attached to
3405 the interface.  The netmask, combined with the address, forms a subnet.  It is
3406 used to add a route to the routing table instructing the kernel to send all
3407 packets which fall into that subnet to that interface.  Because all packets for
3408 the entire VPN should go to the virtual network interface used by tinc, the
3409 netmask should be such that it encompasses the entire VPN.
3410
3411 For IPv4 addresses:
3412
3413 @multitable {Darwin (MacOS/X)} {ifconfig route add -bla network address netmask netmask prefixlength interface}
3414 @item Linux
3415 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3416 @item Linux iproute2
3417 @tab @code{ip addr add} @var{address}@code{/}@var{prefixlength} @code{dev} @var{interface}
3418 @item FreeBSD
3419 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3420 @item OpenBSD
3421 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3422 @item NetBSD
3423 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3424 @item Solaris
3425 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3426 @item Darwin (MacOS/X)
3427 @tab @code{ifconfig} @var{interface} @var{address} @code{netmask} @var{netmask}
3428 @item Windows
3429 @tab @code{netsh interface ip set address} @var{interface} @code{static} @var{address} @var{netmask}
3430 @end multitable
3431
3432 For IPv6 addresses:
3433
3434 @multitable {Darwin (MacOS/X)} {ifconfig route add -bla network address netmask netmask prefixlength interface}
3435 @item Linux
3436 @tab @code{ifconfig} @var{interface} @code{add} @var{address}@code{/}@var{prefixlength}
3437 @item FreeBSD
3438 @tab @code{ifconfig} @var{interface} @code{inet6} @var{address} @code{prefixlen} @var{prefixlength}
3439 @item OpenBSD
3440 @tab @code{ifconfig} @var{interface} @code{inet6} @var{address} @code{prefixlen} @var{prefixlength}
3441 @item NetBSD
3442 @tab @code{ifconfig} @var{interface} @code{inet6} @var{address} @code{prefixlen} @var{prefixlength}
3443 @item Solaris
3444 @tab @code{ifconfig} @var{interface} @code{inet6 plumb up}
3445 @item
3446 @tab @code{ifconfig} @var{interface} @code{inet6 addif} @var{address} @var{address}
3447 @item Darwin (MacOS/X)
3448 @tab @code{ifconfig} @var{interface} @code{inet6} @var{address} @code{prefixlen} @var{prefixlength}
3449 @item Windows
3450 @tab @code{netsh interface ipv6 add address} @var{interface} @code{static} @var{address}/@var{prefixlength}
3451 @end multitable
3452
3453 On Linux, it is possible to create a persistent tun/tap interface which will
3454 continue to exist even if tinc quit, although this is normally not required.
3455 It can be useful to set up a tun/tap interface owned by a non-root user, so
3456 tinc can be started without needing any root privileges at all.
3457
3458 @multitable {Darwin (MacOS/X)} {ifconfig route add -bla network address netmask netmask prefixlength interface}
3459 @item Linux
3460 @tab @code{ip tuntap add dev} @var{interface} @code{mode} @var{tun|tap} @code{user} @var{username}
3461 @end multitable
3462
3463 @c ==================================================================
3464 @node    Routes
3465 @section Routes
3466
3467 In some cases it might be necessary to add more routes to the virtual network
3468 interface.  There are two ways to indicate which interface a packet should go
3469 to, one is to use the name of the interface itself, another way is to specify
3470 the (local) address that is assigned to that interface (@var{local_address}). The
3471 former way is unambiguous and therefore preferable, but not all platforms
3472 support this.
3473
3474 Adding routes to IPv4 subnets:
3475
3476 @multitable {Darwin (MacOS/X)} {ifconfig route add -bla network address netmask netmask prefixlength interface}
3477 @item Linux
3478 @tab @code{route add -net} @var{network_address} @code{netmask} @var{netmask} @var{interface}
3479 @item Linux iproute2
3480 @tab @code{ip route add} @var{network_address}@code{/}@var{prefixlength} @code{dev} @var{interface}
3481 @item FreeBSD
3482 @tab @code{route add} @var{network_address}@code{/}@var{prefixlength} @var{local_address}
3483 @item OpenBSD
3484 @tab @code{route add} @var{network_address}@code{/}@var{prefixlength} @var{local_address}
3485 @item NetBSD
3486 @tab @code{route add} @var{network_address}@code{/}@var{prefixlength} @var{local_address}
3487 @item Solaris
3488 @tab @code{route add} @var{network_address}@code{/}@var{prefixlength} @var{local_address} @code{-interface}
3489 @item Darwin (MacOS/X)
3490 @tab @code{route add} @var{network_address}@code{/}@var{prefixlength} @var{local_address}
3491 @item Windows
3492 @tab @code{netsh routing ip add persistentroute} @var{network_address} @var{netmask} @var{interface} @var{local_address}
3493 @end multitable
3494
3495 Adding routes to IPv6 subnets:
3496
3497 @multitable {Darwin (MacOS/X)} {ifconfig route add -bla network address netmask netmask prefixlength interface}
3498 @item Linux
3499 @tab @code{route add -A inet6} @var{network_address}@code{/}@var{prefixlength} @var{interface}
3500 @item Linux iproute2
3501 @tab @code{ip route add} @var{network_address}@code{/}@var{prefixlength} @code{dev} @var{interface}
3502 @item FreeBSD
3503 @tab @code{route add -inet6} @var{network_address}@code{/}@var{prefixlength} @var{local_address}
3504 @item OpenBSD
3505 @tab @code{route add -inet6} @var{network_address} @var{local_address} @code{-prefixlen} @var{prefixlength}
3506 @item NetBSD
3507 @tab @code{route add -inet6} @var{network_address} @var{local_address} @code{-prefixlen} @var{prefixlength}
3508 @item Solaris
3509 @tab @code{route add -inet6} @var{network_address}@code{/}@var{prefixlength} @var{local_address} @code{-interface}
3510 @item Darwin (MacOS/X)
3511 @tab ?
3512 @item Windows
3513 @tab @code{netsh interface ipv6 add route} @var{network address}/@var{prefixlength} @var{interface}
3514 @end multitable
3515
3516 @c ==================================================================
3517 @node    Automatically starting tinc
3518 @section Automatically starting tinc
3519
3520 @menu
3521 * Linux::
3522 * Windows::
3523 * Other platforms::
3524 @end menu
3525
3526 @c ==================================================================
3527 @node       Linux
3528 @subsection Linux
3529
3530 @cindex systemd
3531 There are many Linux distributions, and historically, many of them had their
3532 own way of starting programs at boot time. Today, a number of major Linux
3533 distributions have chosen to use systemd as their init system. Tinc ships with
3534 systemd service files that allow you to start and stop tinc using systemd.
3535 There are two service files: @code{tinc.service} is used to globally enable or
3536 disable all tinc daemons managed by systemd, and
3537 @code{tinc@@@var{netname}.service} is used to enable or disable specific tinc
3538 daemons. So if one has created a tinc network with netname @code{foo}, then
3539 you have to run the following two commands to ensure it is started at boot
3540 time:
3541
3542 @example
3543 systemctl enable tinc
3544 systemctl enable tinc@@foo
3545 @end example
3546
3547 To start the tinc daemon immediately if it wasn't already running, use the
3548 following command:
3549
3550 @example
3551 systemctl start tinc@@foo
3552 @end example
3553
3554 You can also use @samp{systemctl start tinc}, this will start all tinc daemons
3555 that are enabled. You can stop and disable tinc networks in the same way.
3556
3557 If your system is not using systemd, then you have to look up your
3558 distribution's way of starting tinc at boot time.
3559
3560 @c ==================================================================
3561 @node       Windows
3562 @subsection Windows
3563
3564 On Windows, if tinc is started with the @code{tinc start} command without using
3565 the @code{-D} or @code{--no-detach} option, it will automatically register
3566 itself as a service that is started at boot time. When tinc is stopped using
3567 the @code{tinc stop} command, it will also automatically unregister itself.
3568 Once tinc is registered as a service, it is also possible to stop and start
3569 tinc using the Windows Services Manager.
3570
3571 @c ==================================================================
3572 @node       Other platforms
3573 @subsection Other platforms
3574
3575 On platforms other than the ones mentioned in the earlier sections, you have to
3576 look up your platform's way of starting programs at boot time.
3577
3578 @c ==================================================================
3579 @node    About us
3580 @chapter About us
3581
3582
3583 @menu
3584 * Contact information::
3585 * Authors::
3586 @end menu
3587
3588
3589 @c ==================================================================
3590 @node    Contact information
3591 @section Contact information
3592
3593 @cindex website
3594 Tinc's website is at @url{https://www.tinc-vpn.org/},
3595 this server is located in the Netherlands.
3596
3597 @cindex IRC
3598 We have an IRC channel on the FreeNode and OFTC IRC networks. Connect to
3599 @uref{https://freenode.net/, irc.freenode.net}
3600 or
3601 @uref{https://www.oftc.net/, irc.oftc.net}
3602 and join channel #tinc.
3603
3604
3605 @c ==================================================================
3606 @node    Authors
3607 @section Authors
3608
3609 @table @asis
3610 @item Ivo Timmermans (zarq)
3611 @item Guus Sliepen (guus) (@email{guus@@tinc-vpn.org})
3612 @end table
3613
3614 We have received a lot of valuable input from users.  With their help,
3615 tinc has become the flexible and robust tool that it is today.  We have
3616 composed a list of contributions, in the file called @file{THANKS} in
3617 the source distribution.
3618
3619
3620 @c ==================================================================
3621 @node    Concept Index
3622 @unnumbered Concept Index
3623
3624 @c ==================================================================
3625 @printindex cp
3626
3627
3628 @c ==================================================================
3629 @contents
3630 @bye