mail us  |  mail this page

contact us
training  | 
tech stuff  | 

$GENERATE Directive

The $GENERATE directive is a BIND specific directive and should not be used if zone files will be ported between BIND and other RFC compliant DNS software.

$GENERATE is provided to simplify generation of repetitive sequences of RRs and can be used with any RR which has a simple owner-name (lhs) RR target-name (rhs) structure (such as PTR, CNAME, DNAME, A , AAAA and NS). $GENERATE is typically used when creating reverse zone files including those used in the delegation of reverse subnet maps for IPv4 address ranges of > /24 (range /23 to /32). For IPv4 address ranges < /24 (range /1 to /23) you can experiment with this tool. Reverse-map zone files can involve a series of RRs which increment by a regular value. The following fragment shows an extract from the reverse delegation zone file described in Chapter 3:

$ORIGIN 199.168.192.IN-ADDR.ARPA.
65            IN  CNAME   65.64/26
66            IN  CNAME   66.64/26
67            IN  CNAME   67.64/26 
125           IN  CNAME   125.64/26 
126           IN  CNAME   126.64/26

The following $GENERATE directive would create the full sequence above.

$GENERATE 65-126 $ CNAME $.64/26


$GENERATE start-stop[/step] lhs[{offset[,width[,type]]}] rr-type rhs[{offset[,width[,type]]}]
$GENERATE 65-126/2 $ CNAME $.64/26
$GENERATE 65-126 $Joe CNAME joe$.64/26

Where start is the starting value of the generated sequence and stop is the ending value, /step is optional and indicates the value to be added on each iteration, if omitted 1 is assumed (it is added to both lhs and rhs expansions). lhs indicates the value of the left hand name (owner-name). $ indicates the current iteration value will be substituted and will be prepended or appended to any string which appears in lhs or rhs. The rr-type field is the RR type (CNAME, DNAME, A, AAAA, NS and PTR are supported as well as others), rhs is the right hand expression, again $ indicates the current iteration value will be substituted. The rhs and lhs values will have normal $ORIGIN substitution rules applied. If using a $ character within the lhs or rhs it should be escaped in the normal way as \$.

Both lhs and rhs will take an optional format specifier expression which takes the form:

[ { offset [ ,width [ ,type ] ] } ]

Note: The format specifier is an undocumented feature and while both the default and decimal versions work exactly as expected, care must be taken when using other types as noted below. You are advised to use the named-checkzone method documented below to check the output when using anything other than type d. Note also that when BIND expands $GENERATE the resulting zone file is in canonical owner-name (left-hand-name) order. This can lead to some confusion when interpreting results from named-checkconf and entirely unexpected results when using format specifiers with both lhs and rhs.


  1. offset: Defines any offset (may be negative or positive) which is applied to each iteration.

  2. width: Defines the required width of any resulting field and will be zero padded on the left to give a fixed width value.

  3. type: Defines how the iterator operates and may take the values d, o, x, X, n or N, where:

    1. d: defines a decimal number, thus 9 + 1 = 10.

    2. o: defines an octal (base 8 number), thus 7 + 1 = 10. Unexpected canonical output results occur when using a width value less than 3.

    3. x or X: defines a hexadecimal number, thus 9 + 1 = a (if x) or A if (X). Unexpected canonical output results occur when using a width value less than 3, widths of >= 2 give the expected canonical results, thus, 2F + 1 = 30.

    4. n or N: defines a nibble format in which each nibble of the iterated value (expressed as a hex number in lower case (n) or upper case (N)) is reversed and separated with dots. Thus, the decimal number 47 has a hex value of 2F which is reversed and separated with dots and output as F.2 followed by 0.3, 1.3 as expected. Unexpected canonical output results occur when using a width value less than 3.

Example of format specifier:

$GENERATE 65-126/2 ${0,3,d} CNAME $.64/26

This has the effect of padding all left hand labels to 3 characters, thus the first left hand label will be 065, the second 067 and so on.

Note: If the optional format specifier is omitted (perhaps the normal case) then the format specifier defaults to {0,0,d} which indicates no initial offset, the width of the label reflects the actual number (thus 7 is 1 character wide and 17 is two - no zero padding) and uses a decimal type. The lhs and rhs format specifiers are not related so if a format specifier is used on, say, lhs but is not required on rhs it can be safely omitted as in the above example.


The corresponding PTR records used in reverse map delegation will typically have unique host names that cannot be used with the $GENERATE directives, for example, bill, fred, www and so on which do not have an iterator relationship, but if the host names were sequentially numbered such as PC65 to PC126 in the above example the $GENERATE directive could be applied to them.

The $GENERATE statement is executed while loading the zone file and will result in an expanded in-memory version of the zone being used by BIND9 operationally while the zone file itself is unchanged. If you want to see the expansion (you don't trust the outcome or you want to edit it) the bind utility named-checkzone will allow creation of an expanded zone file (including the $GENERATE directive(s)) which may be used as a template (or skeleton) and subsequently edited. As a side effect of using named-checkzone any unqualified labels (names) will also be expanded to full FQDNs and any $TTL directive will be used to populate individual RR TTLs. This may, or may not, be a useful side effect. Assuming the zone file containing the $GENERATE directive is 192.168.199.rev (as per this guide's zone file naming convention) and the zone name is 199.168.192.IN-ADDR.ARPA then the following command will output an expanded zone file to 192.168.199.rev.exp.

named-checkzone -D -o 192.168.199.rev.exp 199.168.192.IN-ADDR.ARPA 192.168.199.rev

$GENERATE has little to offer in the generation of IPv6 reverse addresses, however the super site a will generate a skelton reverse zone file from user entered parameters and generates a clean file unlike named-checkzone above.

Alternatively, you could use our IPv6 reverse map generator or IPv4 reverse map generator tools.

Problems, comments, suggestions, corrections (including broken links) or something to add? Please take the time from a busy life to 'mail us' (at top of screen), the webmaster (below) or info-support at zytrax. You will have a warm inner glow for the rest of the day.

Pro DNS and BIND by Ron Aitchison


tech info
guides home
dns articles
1 objectives
big picture
2 concepts
3 reverse map
4 dns types
5 install bind
6 samples
7 named.conf
8 zone records
9 howtos
10 tools
11 trouble
12 bind api's
13 dns security
bits & bytes
15 messages
notes & tips
registration FAQ
dns resources
dns rfcs
change log

Creative Commons License
This work is licensed under a Creative Commons License.

If you are happy it's OK - but your browser is giving a less than optimal experience on our site. You could, at no charge, upgrade to a W3C STANDARDS COMPLIANT browser such as Firefox




share page via facebook tweet this page


email us Send to a friend feature print this page Decrease font size Increase font size Display full width page



Debian Linux


GNU-Free SW Foundation


Open Source Initiative
Creative Commons


Ibiblio - Library
Open Book Project
Open Directory


CSS Technology SPF Record Conformant Domain
Copyright © 1994 - 2017 ZyTrax, Inc.
All rights reserved. Legal and Privacy
site by zytrax
Hosted by
web-master at zytrax
Page modified: October 21 2015.