README: provide some more setuid-related explanation
[dyn-nsupdate.git] / README.rst
1 dyn-nsupdate: Self-made DynDNS
2 ==============================
3
4 Introduction
5 ------------
6
7 Welcome to dyn-nsupdate_, a collection of tools using BIND_, CGI_ and Python_ to 
8 provide DynDNS services with your own nameserver. Both IPv4 and IPv6 are fully
9 supported.
10
11 dyn-nsupdate consists of two pieces: The server part provides a way to update IP 
12 addresses in Bind's DNS zones via CGI, in a safe manner. The client part uses CGI
13 to update some domain to the current address(es) of the machine it is running 
14 on. Alternatively, some routers can be configured to do this themselves. The 
15 FritzBox is known to be supported.
16
17 .. _dyn-nsupdate: https://www.ralfj.de/projects/dyn-nsupdate
18 .. _BIND: https://www.isc.org/downloads/bind/
19 .. _CGI: https://en.wikipedia.org/wiki/Common_Gateway_Interface
20 .. _Python: https://www.python.org/
21
22 Server Setup
23 ------------
24
25 In the following, replace ``dyn.example.com`` by whatever domain will be managed 
26 through DynDNS. I assume that BIND has already been set up for 
27 ``dyn.example.com`` as a dynamic zone that can be updated through ``nsupdate 
28 -l``. This can be achieved by setting ``update-policy local;`` in the zone 
29 configuration. Furthermore, I assume the directory ``/var/lib/bind/`` exists.
30
31 There are two pieces that have to be installed: A setuid wrapper which checks 
32 the passwords, and applies the updates; and some CGI scripts offered through a 
33 webserver. Please read this guide carefully and make sure you understand the
34 security implications of what you are doing. setuid wrappers are not toys!
35
36 Let's setting up the setuid wrapper. To compile it, you will need cmake and 
37 boost, including the regex and program_options boost packages. Starting in the 
38 source directory, run::
39
40   cd nsupd-wrapper
41   mkdir -p build
42   cd build
43   DIR=/var/lib/bind
44   cmake .. -DCMAKE_BUILD_TYPE=Release -DDYNNSUPDATE_CONFIG_FILE=$DIR/dyn-nsupdate.conf
45   make
46
47 This should compile the binary ``dyn-nsupdate``. Notice that the path to the 
48 configuration file will be hard-coded into the binary. If it were run-time 
49 configurable, then a user could call the script with her own configuration file, 
50 gaining access to all domains BIND lets you configure. If you want to put the 
51 files in another directory, change the configuration file name accordingly. Make 
52 sure the file (nor any of the directories it is in) can *not be written by 
53 non-root*. The setuid wrapper trusts that file. You can now install it and the 
54 sample configuration file, and set their permissions::
55
56   sudo install dyn-nsupdate $DIR/dyn-nsupdate -o bind -g bind -m +rx,u+ws
57   sudo install ../../dyn-nsupdate.conf.dist $DIR/dyn-nsupdate.conf -o bind -g bind -m u+rw
58
59 Finally, edit the config file. The format should be pretty self-explanatory. In 
60 particular, **change the password**!
61
62 Now, let's go on with the CGI scripts. They are using Python 2, so make sure you 
63 have that installed. There are two scripts: One is used for clients to detect 
64 their current external IP address, and one is used to do the actual update of 
65 the domain. The first script should be available on a domain that is available 
66 only through a single protocol, i.e., IPv4 only or IPv6 only. If you want to 
67 support both IPv4 and IPv6, I suggest you have three domains 
68 ``ipv4.ns.example.com``, ``ipv6.ns.example.com`` and ``ns.example.com`` where 
69 only the latter is available via both protocols (this is something you have to 
70 configure in your ``example.com`` zone). All can serve the same scripts (e.g. 
71 via a ``ServerAlias`` in the apache configuration). I also **strongly suggest** 
72 you make these domains *HTTPS-only*, as the client script will send a password!
73
74 Choose some directory (e.g., ``/srv/ns.example.com``) for the new domain, and 
75 copy the content of ``server-scripts`` there. Now configure your webserver 
76 appropriately for CGI scripts to be executed there. You can find a sample 
77 configuration for apache in ``apache-ns.example.com.conf``. If you used a 
78 non-default location for the ``dyn-nsupdate`` wrapper, you have to change the 
79 path in the ``update`` CGI script accordingly.
80
81 That's it! Your server is now configured. You can use ``curl`` to test your 
82 setup::
83
84   DOMAIN=test.dyn.example.com
85   PW=some_secure_password
86   curl 'https://ns.example.com/update?domain=$DOMAIN&password=$PW&ip=127.0.0.1'
87
88
89 Client setup (using the script)
90 -------------------------------
91
92 You can find the client script at ``client-scripts/dyn-ns-client``. It requires 
93 Python 3. Copy that script to the machine that should be available under the 
94 dynamic domain. Then change the configuration section at the top to match your 
95 setup. Note that the script can update a list of domain names, in case you need 
96 the machine to have several names (it is preferable to use a CNAME instead, this 
97 will reduce the number of updates performed in the zone). The ``serverIPv4`` and 
98 ``serverIPv6`` are only used if IPv4/IPv6 is enabled. These machines must be 
99 available with that protocol only, otherwise it is not possible to reliably 
100 detect the current external address.
101
102 To run the script regularly, simply set up a cronjob. You can do so by running 
103 ``crontab -e``, and add a line as follows::
104
105   */15 * * * * /home/user/dyn-ns-client
106
107 This sets the update interval to 15min. If your IP address changes daily, you 
108 may want to reduce this to 5min to have a smaller timeframe during which your 
109 server is not available.
110
111 Client setup (using a router)
112 -----------------------------
113
114 Some routers are able to perform the update of the domain names themselves. The 
115 FritzBox is known to be supported. To configure it to tell your server about the 
116 current IP address, go to the DynDNS configuration section of the FritzBox and 
117 choose the "custom" DynDNS provider. Then enter the following settings:
118
119 - Update-URL: ``https://ns.example.com/update?domain=<domain>&password=<pass>&ip=<ipaddr>``
120 - Domain Name: ``test.dyn.example.com``
121 - User Name: ``just_something``
122 - Password: ``some_secure_password``
123
124 Note that the user name is ignored.
125
126
127
128 Source, License
129 ---------------
130
131 You can find the sources in the `git repository`_. They are provided under a 
132 2-clause BSD license.
133
134 .. _git repository: http://www.ralfj.de/git/dyn-nsupdate.git
135
136 Contact
137 -------
138
139 If you found a bug, or want to leave a comment, please
140 `send me a mail <mailto:post-AT-ralfj-DOT-de>`_.