]> mj.ucw.cz Git - nsc-5.git/blob - README
Dist: Reconfigured my directory structure
[nsc-5.git] / README
1
2              Domain Name Server Configuration Utilities -- NSC 5.0
3
4                     (c) 1997--2019 Martin Mares <mj@ucw.cz>
5
6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7
8
9 -----------------------------------------------------------------------
10 WARNING: There were several incompatible changes between major versions
11          See NEWS for the summary of changes.
12 -----------------------------------------------------------------------
13
14
15    NSC is a set of shell and M4 scripts for easy maintenance of DNS zone files
16 and name server daemon configuration (currently available only for BIND 8.x/9.x,
17 but easily portable for other daemons). It has been designed to make administration
18 of a DNS server a piece of cake (unlike other utilities which resemble more
19 an English pudding :-) ), which includes automatic generation of reverse records
20 for all your hosts, handling of classless reverse delegations and support for IPv6
21 (AAAA and PTR in ip6.arpa, not A6 and DNAME which seem to be dying out).
22
23    NSC requires GNU m4, GNU Bash, the `md5sum' and `sha1sum' utilities (which
24 are present for example in GNU coreutils), and utilities distributed with BIND.
25 Some of the extra utilities require Perl 5. I've tested everything on Linux
26 (Debian Stretch), but the whole package should run on other unices as well.
27
28    The whole package can be used and distributed according to the terms of the
29 GNU General Public License, version 2 or higher. See file COPYING in any of the
30 GNU utility archives (you should have one as you are expected to have at least
31 GNU M4 ;-)).
32
33
34 0. Quick Howto for the Impatient
35 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 (everything will be explained in more detail in the subsequent sections)
37
38         - Create a directory where all NSC files will reside (e.g., /etc/named)
39           and copy everything from the NSC distribution here.
40
41         - Add an include directive to your BIND configuration file (usually
42           /etc/bind/named.conf), referring to /etc/named/named.conf.
43
44         - Change directory to /etc/named
45
46         - Edit cf/domains to suit your needs -- replace the example domains
47           by your entries.
48
49         - Create cf/<domain-name> for all domains (again, you can easily follow
50           the example domains).
51
52         - If you are using BIND 9.x, make the `bak' directory writable
53           by the bind user.
54
55         - Run bin/nsconfig (Makefile and named.conf will be generated).
56
57         - Run make.
58
59         - Enjoy your new DNS setup. If everything goes OK, be happy. Else
60           write a bug report :-)
61
62         - Every time you modify the domain files, re-run make. If you have
63           added or removed domains or changed options which affect named.conf,
64           re-run bin/nsconfig before make.
65
66 An interesting companion to this package is the DNS Sleuth -- a DNS zone
67 consistency checker. It's a simple utility written in Perl with help of the
68 DNS module and it should be able to detect all common errors in DNS setup
69 (I have written it after much disappointment with the other checkers).
70 The Sleuth is available online on http://atrey.karlin.mff.cuni.cz/~mj/sleuth/,
71 follow the links to download the source. However, I haven't updated Sleuth
72 for a long time, so it does not know about DNSSEC yet.
73
74
75 1. Directory structure
76 ~~~~~~~~~~~~~~~~~~~~~~
77 The NSC directory (/etc/named in the above example) contains the following
78 files and subdirectories:
79
80         cf/                     - user-defined configuration files
81         cf/domains              - the domain list (see Section 2)
82         cf/config               - global settings (see Section 3)
83         cf/<domain>             - each domain has its own config file
84         bin/                    - commands (e.g., nsconfig)
85         m4/                     - M4 scripts (used by the commands)
86         zone/                   - primary zone files
87         bak/                    - backups of zones we serve as a secondary NS for
88         ver/                    - version files where NSC remembers version
89                                   numbers of the primary zones
90         tmp/                    - temporary files
91         hash/                   - hashes of zone files used for detection of changes
92         dss/<domain>            - DNSSEC DS records
93         keys/<domain>/          - DNSSEC keys
94         khash/                  - hashes of DNSSEC keys used for detection of changes
95
96    How are different files created:
97
98         - You create everything in cf/.
99         - Then you run bin/nsconfig.
100         - If you want to use DNSSEC, create keys (see section 8)
101         - Makefile and named.conf gets created according to cf/domains.
102         - You run make.
103         - The Makefile creates primary zone files in zone/ and version files
104           in ver/ and tells BIND to reload its configuration.
105         - BIND downloads contents of secondary zones and puts them to bak/.
106
107
108 2. The Domain List File
109 ~~~~~~~~~~~~~~~~~~~~~~~
110 The domain list contains configuration commands describing all domains handled
111 by your server and their parameters. In fact, it's a M4 script, but viewing it as
112 a config file is a good approximation (however, see Section 8 for some caveats).
113 Lines starting with a semicolon are treated as comments and ignored. Text outside
114 declarations is silently ignored.
115
116 You can specify:
117
118 PRIMARY(zone, [extra-files...])
119                 Define a zone (domain) we run a primary name server for.
120                 The contents of the zone are described in cf/<zone>
121                 and possibly in other specified cf files (all files are
122                 concatenated to produce a single configuration). See the next
123                 section for a look inside these files.
124
125                 When the zone name contains a slash (as happens in classless
126                 reverse zones), it is replaced by "@" in the cf file name.
127
128 SECONDARY(zone, primary)
129                 Define a zone we run a secondary name server for.
130                 "primary" is an IP address of the primary name server.
131
132 REVERSE(network, primary-files...)
133                 Define a reverse zone for the given network. The network name
134                 consists of several numbers separated by dots, just like an IP
135                 address does, but the network usually has only 3 components.
136                 Each reverse zone has its own config file cf/<network> which
137                 can of course specify the contents of the zone.
138
139                 However, there is a more convenient method to generate the PTR
140                 records directly from the A records: just specify the REVERSE
141                 directive in cf/<network> and then include all the config files
142                 for the primary zones containing hosts from this network. The
143                 automatic concatenation of multiple primary-files comes very
144                 handy for that.
145
146                 In fact, REVERSE(network, p-f...) is almost an equivalent of
147                 PRIMARY(REV(network), p-f...) where REV(network) is a macro
148                 translating network numbers to names of the corresponding
149                 reverse zones [e.g., REV(1.2.3) equals 3.2.1.in-addr.arpa].
150                 The only difference is that although the domain name is translated
151                 by REV, the config file is still named according to the network.
152                 You can also use the REV macro explicitly, which can be handy
153                 for example in SECONDARY declarations.
154
155 FORWARDED(zone, ip...)
156                 Define a forwarding zone. All queries are forwarded to the
157                 specified name servers.
158
159 BLACKHOLE(zone)
160                 Define an empty zone according to RFC 6303. This is usually done
161                 for zones for which clients are known to erroneously ask queries
162                 (e.g., reverse resolving of link-local addresses). The contents
163                 served for these zones is taken from cf/blackhole.
164
165 ZONE_OPTIONS(`options;
166         more options;
167 ')
168                 Define options to be inserted to all subsequent zone declarations
169                 until the next ZONE_OPTIONS command. Please keep in mind that the
170                 semicolon character act as M4 comment, so you need to put the
171                 closing quote at a separate line. See our example cf/domains.
172
173 CONFIG(...)
174                 Insert user data to named.conf, again beware of semicolons.
175
176 MAKEFILE(...)
177                 Insert user data to Makefile.
178
179 DNSSEC(`declarations...')
180                 Request DNSSEC signing for all zones declared within the block.
181
182 DSFOR(zone)
183                 Declare dependency of the previous PRIMARY/REVERSE domain on DS
184                 records for the given zone configured in dss/*.
185
186
187 3. The Domain Files
188 ~~~~~~~~~~~~~~~~~~~
189 The domain files contain descriptions of all DNS records for the given
190 domain, starting with the SOA record. Again, these are M4 scripts and the
191 declarations are macro calls. Lines starting with a semicolon are treated
192 as comments and just copied to the generated zone file. Text outside
193 declarations is copied to the zone file as well, so you can spice up the NSC
194 output with your own records.
195
196 All host or domain names are either names relative to the current domain
197 with no dots inside or absolute names (in this case, NSC automatically
198 ensures that the trailing dot is present in the resource records). Relative
199 names with dots are not supported, but they are rare and you can always write
200 them as absolute anyway.
201
202 Your menu:
203
204 SOA(domain-name)
205                 Generate a SOA record for the domain. This must be the first
206                 declaration in the config file. The parameters of the SOA
207                 are taken from configuration variables (see below). The
208                 serial number is calculated from the version number remembered
209                 in the version file, following the usual practice of encoding
210                 current date and a sequence number within the current day
211                 in the serial number, which is guaranteed to be strictly
212                 increasing unless you perform more than 99 updates in a single
213                 day (in which case NSC stops and tells you to tweak the serial
214                 number manually).
215
216                 The SOA record otherwise acts like a sub-domain (D) declaration,
217                 therefore it can be followed by other records like NS (mandatory)
218                 or MX.
219
220 H(host)
221                 Start declaration of a host. Doesn't generate anything, only
222                 remembers the host's name.
223
224 ADDR(addr...)
225                 Specify addresses for the current host. In the normal mode, it
226                 creates A/AAAA records, in the reverse mode, PTR records.
227
228 H(host, addr...)
229                 A shortcut for H(host) ADDR(addr...) -- in many cases everything
230                 you need for a single host.
231
232 DADDR(addr...)
233                 Like ADDR, but suppresses PTR records. (This one is useful if you
234                 have a single IP address used for zillions of names and you want
235                 to avoid having zillions of PTR records for the same address.)
236
237 DH(host, addr...)
238                 A shortcut for H(host) DADDR(addr...)
239
240 D(domain)
241                 Start declaration of a sub-domain. Technically the same as H(domain),
242                 but this one should be more intuitive.
243
244 GLUE(ns, addr...)
245                 Specify a glue record for a name server contained within a sub-domain
246                 it's a primary for. Currently it's an equivalent of DH(ns, addr...).
247
248 NS(ns...)
249                 Specify a list of name server names for the current domain
250                 (started by either a SOA or D declaration). Generates NS records.
251
252 DS()
253 DS(dsset)
254                 Include DS records for the current sub-domain. With no arguments,
255                 they are loaded from dss/<sub-domain>. If the name of the sub-domain
256                 does not match the name of the DSset (as it frequently happens with
257                 reverse zones), you can specify the DSset name explicitly.
258
259 MX(mx...)
260                 Specify a list of mail exchangers for the current host or domain.
261                 Each mail exchanger should be preceded by a priority. Generates
262                 MX records.
263
264 HI(hw,os)
265                 Specify a HINFO record for the current host. Very rare in the
266                 today's Internet.
267
268 ALIAS(alias...)
269                 Specify a list of aliases for the current host or domain.
270                 Generates a series of CNAME records pointing from the aliases
271                 to the current host/domain.
272
273 TXT(text)
274                 Specify a TXT record for the current host or domain.
275
276 RP(mail, txt)
277                 Specify a RP (responsible person) record for the current host or domain.
278                 The first argument is a mail address in DNS notation (with `@' replaced
279                 by `.' as in the SOA record), the second one is a name of a TXT record
280                 with contact information.
281
282 SRV(service, protocol, priority, weight, port, target)
283                 Specify a SRV (service) record for the current host or domain.
284
285 CNAME(src, dest)
286                 Generate a CNAME record -- "src" points to "dest".
287
288 PTR(src, dest)
289                 Generate a PTR record -- "src" points to "dest". It's a common
290                 record in reverse zones (and although it's legal in forward
291                 zones as well, such use is very rare), however it's more convenient
292                 to have your PTR's generated by the REVERSE directive. But if you
293                 need anything special, here is the tool.
294
295 REVBLOCK(subdomain, min, max)
296                 Generate a series of CNAME records numbered from `min' to `max'
297                 and pointing to the same name in the given sub-domain, finally
298                 declaring the sub-domain as well, so you can continue with its
299                 NS records.
300
301                 Example: REVBLOCK(a, 16, 18) NS(ns.xyzzy.org) yields
302
303                         16      CNAME   16.a
304                         17      CNAME   17.a
305                         18      CNAME   18.a
306                         a       NS      ns.xyzzy.org.
307
308                 This is a very common construct for classless reverse delegations,
309                 see Section 6 for more details.
310
311 REVERSE(network)
312                 Switch to reverse mode. From this point on, all output is suppressed
313                 except for ADDR declarations belonging to the specified network which
314                 are automatically converted to PTR records.
315
316                 With help of this feature, defining reverse zones can be as easy as:
317
318                         ; Reverse zone for 10.0.0.0/24 a.k.a. 0.0.10.in-addr.arpa.
319                         SOA(REV(10.0.0))
320                         NS(ns1.example.com, ns2.example.com)
321                         REVERSE(10.0.0)
322                         ; Include all primary zones containing ADDR's from this range,
323                         ; which can be accomplished by a multi-file REVERSE declaration
324                         ; in cf/domains.
325
326
327 4. Configuration variables
328 ~~~~~~~~~~~~~~~~~~~~~~~~~~
329 There is a fair amount of configuration variables (which are in reality normal
330 M4 macros). Each variable has a hard-wired default value which can be overridden
331 in cf/config by re-defining the variable. Also, all other config files can specify
332 their local definitions, but you need to be careful to change the variable before
333 it is used for the first time.
334
335 To change the setting, use
336
337                 define(`variable', `value')
338
339 As usually, even this config file is a M4 script. Comments can be started by
340 semicolons, text outside macros is ignored.
341
342 The following variables are available:
343
344 NAMED_RESTART_CMD       Shell command for restarting the name server daemon
345                         (default: rndc reload)
346
347 CFDIR                   Directory with config files (default: cf)
348
349 REFRESH                 SOA record parameters
350 RETRY
351 EXPIRE
352 MINTTL
353 NSNAME                  Origin server (default: hostname of your machine)
354 MAINTNAME               Domain maintainer name (default: root@NSNAME)
355
356 KEYGEN_OPTIONS          Extra options given to dnssec-keygen
357                         (by default, it selects key type and key size).
358 SIGNZONE_OPTIONS        Extra options given to dnssec-signzone
359                         (by default, it specifies signature validity of 365 days).
360 DSFROMKEY_OPTIONS       Extra options given to dnssec-dsfromkey
361                         (by default, there are none).
362
363 For the timing parameters, the following shortcuts are available:
364
365 HOURS(n)                Convert hours to seconds
366 MINUTES(n)              Convert minutes to seconds
367 DAYS(n)                 Convert days to seconds
368
369
370 5. Makefile targets
371 ~~~~~~~~~~~~~~~~~~~
372 The Makefile generated by NSC offers the following targets:
373
374         all (default)           - update all zone files and reload the daemon
375         clean                   - clean all generated zone files, backups, and hashes
376         clobber                 - clean + delete Makefile and named.conf
377                                   (wise to do after major reconfigurations)
378         distclean               - clobber + delete all version files (use only
379                                   if you really know what you are doing as the
380                                   serial number information in newly generated
381                                   files might be inconsistent then).
382
383
384 6. Classless reverse delegations
385 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386 NSC also supports classless delegations for reverse zones using the mechanism
387 described in RFC 2317, i.e. by putting CNAME records to the reverse zone which
388 point to records of the same name in a sub-domain which you can delegate directly.
389
390 For example if you want to delegate 64-127 in 0.0.10.in-addr.arpa to ns.example.net,
391 you create a 64/26 sub-domain (26 is the network prefix length) and add the following
392 records to 0.0.10.in-addr.arpa:
393
394         64      CNAME   64.64/26.0.0.10.in-addr.arpa.
395         65      CNAME   65.64/26.0.0.10.in-addr.arpa.
396         ...
397         127     CNAME   127.64/26.0.0.10.in-addr.arpa.
398
399         64/26   NS      ns.example.net.
400
401 Then you configure ns.example.net to be a primary name server for the zone
402 64/26.0.0.10.in-addr.arpa and put the PTR records there:
403
404         64      PTR     sixty-four.example.net.
405         65      PTR     sixty-five.example.net.
406         ...
407         127     PTR     two-to-seven-minus-one.example.net.
408
409 NSC offers special primitives for configuring such delegations, but not limited
410 to the sub-domain name syntax shown above (which is recommended by the RFC, but it's
411 far from being the only one used in the real world, other possibilities being for
412 example 64-127, 64+64 etc.).
413
414 The CNAME block can be generated by the REVBLOCK(subdomain-name, low-addr, high-addr)
415 directive in the configuration of the whole reverse zone. The example above would
416 be written as:
417
418         REVBLOCK(64/26, 64, 127)
419
420 The sub-zone can be created automatically like any another reverse zone, you only
421 need to use the three-parameter form of the REVERSE directive to specify the
422 address range in order to filter out possible hosts falling outside your range.
423
424 CAVEAT: The slashes in zone names are automatically translated to @'s when forming
425 file names.
426
427 Again for the example above, you need to put the following to cf/domains:
428
429         REVERSE(10.0.0.64/26, <list-of-domains-to-gather-the-addresses-from>)
430
431 And to cf/64@26.0.0.10:
432
433         SOA(REV(10.0.0.64/26))
434         NS(<list-of-name-servers>)
435         REVERSE(10.0.0, 64, 127)
436
437 NOTE: It's usually helpful to configure the primary name server for the parent
438 domain (i.e., the one where you configure the delegation and create the CNAME's)
439 as a secondary for the sub-zone as well, so if it replies with the CNAME, it will
440 include the PTR record pointed to by the CNAME in the additional section of its
441 reply, eliminating the need for an extra query.
442
443
444 7. Support for IPv6
445 ~~~~~~~~~~~~~~~~~~~
446 NSC also supports IPv6 in a pretty straightforward form: wherever you can write
447 an IPv4 address, you can use an IPv6 address as well. Incomplete IP addresses
448 or ranges used for specifying address blocks for reverse delegations are replaced
449 by network prefixes of the standard form <address>/<prefix-length>.
450
451 Example:
452
453         H(ianus, 1.2.3.4, fec0::1234:5678:9abc:def0)
454
455 specifies a dual-stack host with both an A record and an AAAA record.
456
457 CAVEAT: The backward-compatible IPv6 address syntax with ":v.w.x.y" at the end
458 is not supported. All other syntaxes and quirks hopefully are.
459
460
461 8. DNSSEC support
462 ~~~~~~~~~~~~~~~~~
463 NSC knows the basics of DNSSEC. It does not handle key management (you need to
464 schedule generation and retirement of your keys by other means), but once the
465 keys are in place, it uses them for signing zones.
466
467 === Key management ===
468
469 Keys live in keys/<zone>/*.(key|private) and they are stored in the usual BIND
470 format. To generate a zone-signing key, you can use the following command after
471 writing at least rudimentary cf/<zone>:
472
473         bin/key-gen <zone>
474
475 If you want a key-signing key, use:
476
477         bin/key-gen <zone> -f KSK
478
479 (Generally, you can add arbitrary arguments for BIND's dnssec-keygen. Default
480 keygen options can be set in cf/config, see section 4.)
481
482 To detect key changes, NSC keeps a hash of all keys for each domain.
483 If you edit the keys manually (e.g., to delete a key), you need to recalculate
484 the hash by:
485
486         bin/key-update <zone>
487
488 (or without a zone to update all hashes).
489
490 === Domain signing ===
491
492 All domains whose declarations in cf/domains are wrapped by DNSSEC(`...')
493 are automatically signed using all set up keys. If you specify key validity
494 period when generating the key, it is respected, but the domains are not
495 re-signed automatically when a key becomes valid / ceases to be. If you
496 want to modify dnssec-signzone arguments, you can do so in cf/config.
497
498 Beware that all signatures have a limited lifetime (even if the keys do not
499 expire). The default lifetime is 365 days, so you need to re-sign your zones
500 at least once in a year. The recommended solution is to set up a cron job,
501 which touches keys/resign-stamp. A change of timestamp of this file forces
502 a re-sign on the next run of make.
503
504 === Subdomains ===
505
506 If you want to delegate a signed sub-domain, you need to include DS records
507 in the parent zone. Add a DS() macro after declaration of the sub-domain
508 in the parent. It loads DS records from dss/<child>.
509
510 If the sub-domain is also maintained by NSC, you can generate the DS record
511 set automatically by:
512
513         bin/key-delegate <zone>
514
515 === Reverse zones ===
516
517 Unlike primary/secondary zones, reverse zones have file names which differ
518 from the full domain name. In such cases, keys are named after the file name
519 and NSC constructs the full name whenever necessary.
520
521 There is one exception where automatic construction is not available:
522 delegation of sub-domain keys. In such cases, you need to pass the file
523 name of the sub-zone to the DS macro.
524
525
526 9. Interaction with M4
527 ~~~~~~~~~~~~~~~~~~~~~~
528 All config files are fully-fledged M4 scripts, so you can use any M4 features
529 you need, the most helpful one being definition of your own macros by
530
531         define(`macro_name', `expansion')
532
533 However, there is a couple of things you need to care about:
534
535   o  The comment character is redefined to `;'. I.e., wherever a semicolon
536      occurs, the rest of the line is a comment which is copied verbatim
537      to the output file (if the output is not suppressed like in case
538      of the cf/domains file).
539
540   o  Names starting with 'nsc_' or spelled in all caps are reserved
541      for the NSC itself and unless documented, messing with them can
542      bring surprising results. If you need to use such a name in your
543      zone file (maybe you like to shout in your host names :-) ),
544      quote it like `this'.
545
546   o  Don't use commas, quotes nor parentheses in your record names.
547
548
549 9. Other utilities
550 ~~~~~~~~~~~~~~~~~~
551 convert         A simple Perl script for conversion of zone files to NSC
552                 domain files. Requires the Net::DNS module (available from
553                 CPAN at ftp.cpan.org; present in recent versions of Perl).
554                 Keep in mind that the script is very simple and its craft
555                 is of a very limited kind, so check its output carefully.
556
557 chkdel          A simple Perl script for checking of domain delegations --
558                 it checks all PRIMARY and SECONDARY records in cf/domains
559                 against NS records. Requires the Net::DNS module and also
560                 some tweaking of parameters at the top of the script.