c4a860e44cbc35c229335f81837d9a8cfe8871d1
[wiki] / examples / zeroconf-ip-and-dns.mdwn
1 [[!meta title="zeroconf IP and DNS configuration"]]
2
3 ## Example: zeroconf IP and DNS configuration
4
5 This example describes how to setup a network with no centralized dhcp server
6 and automatic dns resolution and minimum configuration:
7
8 You will need Avahi mDNS daemon up and running (not part of this guide,
9 please refer to your distro): [http://avahi.org/](http://avahi.org/)
10
11 ### Setting up Avahi hostname resolution:
12
13 This will allow your computer to resolve mDNS hostnames which addresses in the form of something.local.
14 In order to do it,
15 edit `/etc/nsswitch.conf` and append `mdns_minimal [NOTFOUND=return]` to your `hosts:` line before your `dns` entry,
16 for example my configuration is:
17
18         hosts: files myhostname mdns_minimal [NOTFOUND=return] dns
19
20 (Note that you can use a different top level domain than .local,
21 but in such case you need to use `mdns` entry instead of `mdns_minimal`.)
22
23 ### Automatic ip assignment and network setup:
24
25 Follow the "how to configure" guide from the [[manual|docs]] to create the key pair and folders,
26 then edit `tinc.conf` and insert `Mode = switch`,
27 this will allow to make all nodes to listen to the same subnet mask simplifying the configuration
28 (although it'll increase traffic since all nodes will get the data).
29 By default the subnet mask is 169.254.0.0/16.
30 We'll change how `tinc-up` brings up the VPN interface; instead of using `ifconfig` to bring up the interface,
31 we'll use `avahi-autoipd daemon`.
32 This yields many advantages:
33
34 * autoipd daemon automatically assignes an ip address based off available pool
35 * it'll publish the hostname in the mdns resolution network and will also act as controller for the avahi daemon allowing to browse or publish avahi services
36
37 So in the `tinc-up` script you'll have a line like: `avahi-autoipd -D $INTERFACE`.
38 That's it! your VPN will have auto assigned IP addresses, and automatically resolved DNS entries once it's up.
39 In order to list the machines on the network you can use this command: `avahi-browse -d networkname`.
40
41 ### Useful bits:
42
43 You can insert static hostname resolution for VPN nodes using `/etc/avahi/hosts` much like `/etc/hosts`.
44 You can manually ask for preferred IP when calling `avahi-autoipd` by appending `-S` <i>wantedip</i>.
45
46 ### Example configuration:
47
48 In my configuration I have a PC everything connects to (alarmpi, reachable at LAN address 192.168.1.12 and public address alarmpi.xyz.com), and a laptop and a phone that can access it.
49
50 Alarmpi's `tinc.conf`:
51
52         Name = alarmpi
53         Mode = switch
54
55 The laptop's `tinc.conf`:
56
57         ConnectTo = alarmpi
58         Name = laptop
59         Mode = switch
60
61 The phone's `tinc.conf`:
62
63         ConnectTo = alarmpi
64         Name = phone
65         Mode = switch
66
67 Every node has the same `tinc-up:`
68
69         #!/bin/sh
70         avahi-autoipd -D $INTERFACE
71
72 `hosts/alarmpi`:
73
74         Address = 192.168.1.12
75         Address = alarmpi.xyz.com
76         
77         -----BEGIN RSA PUBLIC KEY-----
78         snip
79         -----END RSA PUBLIC KEY-----
80
81 `hosts/laptop`:
82
83         -----BEGIN RSA PUBLIC KEY-----
84         snip
85         -----END RSA PUBLIC KEY-----
86
87 `hosts/phone`:
88
89         -----BEGIN RSA PUBLIC KEY-----
90         snip
91         -----END RSA PUBLIC KEY-----