Sub topic 9
Understanding named.conf, options and ACLs
This chapter assumes you can edit files as root, you have BIND installed (see the installation chapter), and you know what an authoritative server and a recursive resolver are. It covers how BIND's main configuration file is organized, which statements go in it, and how access control lists (ACLs) decide who may use the server.
Where the configuration lives
BIND reads one top-level file, named.conf. Distributions split it differently.
| Item | Debian/Ubuntu | RHEL family |
|---|---|---|
| Main file | `/etc/bind/named.conf` | `/etc/named.conf` |
| Options | `named.conf.options` (included) | inside `named.conf` |
| Your zones | `named.conf.local` (included) | inside `named.conf` or an included file |
| Working directory | `/var/cache/bind` | `/var/named` |
| Service name | `named` (alias `bind9`) | `named` |
On Debian, named.conf is only a list of include lines. This keeps your own zones in named.conf.local, so package upgrades do not overwrite them.
Syntax rules that cause most errors
named.conf is a list of statements. Each statement has a keyword, optional arguments, and a block in braces. The rules are strict:
- Every statement and every setting ends with a semicolon, including the closing brace of a block.
- Comments can be
//,#, or/* ... */. - Strings such as zone names and file paths go in double quotes.
- Address lists inside braces separate entries with semicolons, as in
{ 127.0.0.1; 192.0.2.10; };.
A missing semicolon is the most common failure. The named-checkconf command reports it with a file name and line number. The reported line is often the one after the real mistake.
The main statement types
| Statement | Purpose |
|---|---|
| `options` | Global settings. Only one is allowed. |
| `acl` | Names a list of addresses for reuse. |
| `zone` | Declares a zone and where its data comes from. |
| `key` | Defines a TSIG secret (covered in the zone transfer chapter). |
| `logging` | Chooses what is logged and where. |
| `controls` | Configures the `rndc` control channel. |
| `view` | Groups zones and options per client group (covered in the split-horizon chapter). |
| `include` | Reads another file at that point. |
The options block
The options statement holds server-wide behavior. These settings matter most for a first deployment:
directorysets the base directory for relative file names. Zonefileentries that are not absolute paths are resolved against it.listen-onlists the IPv4 addresses and ports wherenamedaccepts queries.listen-on-v6does the same for IPv6. They are separate, so setting one does not restrict the other.allow-querysays who may ask questions the server can answer.recursionturns recursive service on or off.allow-recursionsays who may use it.allow-transfersays who may request full zone copies. Set it explicitly.dnssec-validation autovalidates answers using the built-in root trust anchor.
Use the following as a starting point for an authoritative-only server:
acl "trusted" {
127.0.0.1;
192.0.2.0/24;
};
options {
directory "/var/cache/bind";
listen-on { 127.0.0.1; 192.0.2.10; };
allow-query { any; };
recursion no;
allow-transfer { none; };
dnssec-validation auto;
};This server answers anyone about the zones it holds, and it refuses recursion and zone transfers. The trusted ACL is defined here but not used yet. The next section shows where to use it.
ACLs in depth
An acl statement gives a name to a list of matches. You can then use the name anywhere an address list is accepted.
acl "trusted" {
127.0.0.1;
192.0.2.0/24;
};
acl "clients" {
!192.0.2.99;
192.0.2.0/24;
};Four details decide how ACLs behave:
- Built-in names.
anymatches everything.nonematches nothing.localhostmatches the server's own addresses.localnetsmatches every network the server has a directly attached interface on. - Order matters. BIND checks entries from top to bottom and stops at the first match. In
clients, host192.0.2.99matches the negated entry first and is rejected. If you swapped the two lines, the whole/24would match first and.99would be allowed. - Define before use. An ACL must appear in the file before a statement that references it. Put ACLs at the top of
named.conf, or in the first included file. - Names are quoted by convention. Quote them in definitions and use the same spelling when you reference them. Do not reuse the built-in names for your own ACLs.
You then reference the ACL in options:
options {
directory "/var/cache/bind";
listen-on { 127.0.0.1; 192.0.2.10; };
allow-query { trusted; };
allow-recursion { trusted; };
allow-transfer { none; };
};Overriding settings per zone
Many options can also appear inside a zone block. A zone-level value overrides the global one for that zone only.
zone "example.com" {
type primary;
file "/etc/bind/db.example.com";
allow-transfer { 192.0.2.11; };
};Here the global allow-transfer { none; } still applies to every other zone. Only example.com can be copied, and only by 192.0.2.11. This pattern lets you keep a closed default and open one door at a time.
Applying and checking changes
Always validate before reloading. A bad configuration on a running server will not take effect, but a bad restart can leave the service down.
sudo named-checkconf
sudo named-checkconf -z
sudo rndc reload
sudo ss -lntup | grep namednamed-checkconf alone checks syntax. With -z it also loads each master zone and reports zone file errors. rndc reload re-reads the configuration and changed zones without dropping the cache. The ss command confirms that named is bound to the addresses you listed in listen-on.
Common errors
syntax error near '}'. A semicolon is missing on the line above, or a block was not closed.unknown keyorundefined ACL. The ACL or key is referenced before it is defined, or its name is misspelled.- Zone loads but secondaries fail to refresh.
allow-transferdoes not include the secondary's address. permission deniedwriting a zone file. On Debian, AppArmor limitsnamedto/etc/bindfor reading and/var/cache/bindfor writing. A secondary zone file kept in/etc/bindwill fail to save. Put it in the working directory.- The server answers on an address you did not intend.
listen-onis missing, sonamedlistens on all IPv4 interfaces. Set it explicitly.
Exercise
A server has acl "lan" { 192.0.2.0/24; !192.0.2.50; }; and allow-recursion { lan; };. Can host 192.0.2.50 use recursion? How would you change the ACL so that it cannot?
Show answer
Yes, it can. BIND stops at the first match, and 192.0.2.50 matches the /24 entry before it reaches the negated entry. Move the negation to the top: acl "lan" { !192.0.2.50; 192.0.2.0/24; };. Run named-checkconf and then rndc reload to apply it.
Exercise
You declare a secondary zone with file "/etc/bind/db.example.com"; on a Debian server. The zone transfers, but the log shows permission errors when saving the file. What is the likely cause, and what is the fix?
Show answer
AppArmor does not allow named to write under /etc/bind. Change the file path to a location in the working directory, such as /var/cache/bind/db.example.com, then reload the configuration.