--- title: "Explanation of views in BIND" slug: "explanation-of-views-in-bind" description: "What are views, how to use them, configuration examples and handy hints." tags: ["B;view", "B;match-clients", "B;match-destinations", "B;match-recursive-only", "B;acl"] updated: 2026-12-04T16:30:25Z published: 2026-12-04T16:30:25Z canonical: "kb.isc.org/explanation-of-views-in-bind" --- > ## Documentation Index > Fetch the complete documentation index at: https://kb.isc.org/llms.txt > Use this file to discover all available pages before exploring further. # Explanation of views in BIND ## What are views? Views are constructs designed to keep certain configuration elements separate and to allow them, potentially, to have different configurations for servicing distinct groups of clients. They provide a kind of container into which configuration is written. Each view's configuration is, or can be, separate from the others. ## Built-in views Out of the box, BIND starts with two built-in views: - `_bind`, which is used for queries in the CHAOS class only. This view is permanent, regardless of other configuration. - `_default`, which is used for queries in the IN class only and exists as long as no user-defined views are configured. Neither of these views appear in the configuration; they just exist. A lot of elements that users might add to their configuration, such as zones and various policies, logically belong in a view and if there are no explicit `view` blocks, they will live in the `_default` view, implicitly. ## User-defined views A user-defined view is created by configuring a `view` block at the top level of the configuration hierarchy, like this: ``` view view-one { view-specific configuration goes here... }; ``` The name of the view being defined here is `view-one`. The name does not need to be in quotes, can contain hyphens or underscores (and maybe other characters) and has no practical limit on length, though shorter names are generally easier to understand. The official grammar of a view block is defined [here](https://bind9.readthedocs.io/en/stable/reference.html#namedconf-statement-view), but also see [this](/v1/docs/bind-block-view) KB article. Overriding `_default` As soon as one user-defined view is created, the `_default` view is deleted. This means that any configuration that may have existed already, which was dependent on the `default` view, must now be moved into a user-defined view. Some examples below should help to clarify this. The code blocks below shows a skeleton hypothetical configuration, both before and after introducing a user-defined view. ``` logging { }; options { }; zone test.example.com { type primary; file "db.test.example.com"; }; ``` Once a user-defined view is introduced, the config needs to be changed to look like this: ``` logging { }; options { }; view view-one { zone test.example.com { type primary; file "db.test.example.com"; }; }; # end of view-one ``` The zone moves Note that the zone definition needed to move **inside** the view `view-one`. This is because zones must live inside **a** view and when `view-one` was defined, the invisible view `_default` ceased to exist, so the zone had to be wrapped up inside the view block. The next code block shows a slightly more complex configuration that has two views with a zone in each: ``` logging { }; options { }; view view-one { zone test.example.com { type primary; file "db.test.example.com"; }; }; # end of view-one view view-two { zone test.example.com { type primary; file "db.test.example.com"; }; }; # end of view-two ``` A few things are worth noting here: 1. The same zone has been defined in both views. This is quite alright and is sometimes the reason why views are needed at all; so that two separate user populations both have access to the data in one or more common zones. 2. The config, as it stands, is incomplete as it provides no way for the server to know which view a given incoming query should be directed to. view order is important In the configuration for `named`, the order in which statements appear is mostly not important. However, `view` blocks are an exception. As queries arrive at the server it tests each view **in the order they are configured**, to see which view view should handle a given query. That is, the views are tested top down and the query is handled by the first view it matches. ## How are queries matched to a view? There are four criteria that the server can optionally use to determine whether a given query matches a view: 1. client source address: the `match-clients` statement. 2. destination address: the `match-destinations` statement. 3. Whether the query species recursion or not: the `match-recursive-only` statement. 4. TSIG key. ### `match-clients` This statement takes an address match list as its argument: ``` view view-one match-clients {;...}; ... }; ``` Elements of the list may be explicit IP addresses (IPv4 or IPv6), subnet addresses, including a mask in CIDR notation, or the name of an `acl`. The purpose of this statement, which is optional, is to create a test for the **source** address in the packet as it arrives. If that source address can be matched against one of the elements in the list then this client matches against this view (or the view has been said to be **selected** by this client) and query processing continues according to the configuration in the view. ### `match-destinations` This statement also takes an address match list as its argument, with the same syntax listed above: ``` view view-one match-destinations {;...}; ... }; ``` The purpose of this statement, which is also optional, is to create a test for the **destination** address in the packet as it arrives. If that destination address can be matched against one of the elements in the list then this client matches against this view (or the view has been said to be **selected** by this client) and query processing continues according to the configuration in the view. An important difference here, from `match-clients`, is that the destination address must be one on which BIND is listening for incoming messages. Using either or both `match-clients` and `match-destinations` provides a flexible way to categorize incoming queries to match the view of your choice. ### `match-recursive-only` This statement takes either a **true** or **false** argument. It is used to test whether incoming queries have the **Recursion Desired** (RD) bit in the DNS message header set (value 1), indicating that the client wishes the server to perform recursion on its behalf, if necessary and if the server is configured to do so. All stub clients - laptops, desktops, mobile phones and many other types of devices - will set the RD bit when making queries. In contrast, recursive DNS servers themselves, when making queries to other servers in order to learn information that will be used to respond to clients, typically do not set the RD bit. Secondary servers also do not set the RD bit when making SOA queries before a zone transfer, or for the start of the zone transfer itself. Therefore, this statement can be used to filter stub clients from DNS server clients. A potential use for this is to separate queries and zone transfers: #### internal clients versus zone transfers. It may be that one server is doing several jobs; servicing stub client queries at the same time as handling zone transfer requests. It would be desirable to keep these tasks separate so that, for instance, stub clients can't transfer zones. Using one view for stub clients, containing `match-recursive-only yes;`, will cause it to **not** be matched by server-server queries, allowing them to fall through to a second view dedicated to zone transfer. ### Where does TSIG come in? A key can be created in the global `named` configuration and then used for a number of purposes. One of those purposes could be to refine selection of a view, in conjunction with either/both `match-clients` and `match-destinations`. For example, a key might be defined like this: ``` key keytwo { algorithm hmac-md5; secret "a8Ht4BV08KljR6dWnF95Xa==" }; ``` The **secret** is the base64-encoding of the key hash. The example shown uses algorithm **hmac-md5**, which has a 128 bit (16 byte) hash. Every three bytes of the hash must be encoded using four bytes of base64 output. Since 16 does not divide perfectly by three (remainder 1), two padding characters must be added, which are the **==** shown at the end. ### A brief introduction to address match lists A list comprises one or more elements, each of which must be one of the following: - An IP (4 or 6) host address, with no mask. - An IP (4 or 6) subnet address, with a mask - The name of an ACL, which must be defined in the global configuration of the server. ACLs are a convenient way to collect and name groups of IP addresses for use elsewhere, such as here. - A TSIG key, which is specified by using the keyword **key** followed by the key name. Any list element may be negated by prefixing it with an exclamation mark **!**, which means **do not** match queries that would match this address or have this key. Another important thing to note about address match lists is that the elements are tested in the order they appear and testing stops if a match is found. Take this list, for example: ``` match-clients {any; 10.0.0.0/8;}; ``` The built-in element **any** matches any address, so the 10.0.0.0/8 prefix will never be tested and may as well not be there. ### Putting it together Expanding on the earlier configuration might give us this: ``` logging { }; options { }; key keyone { algorithm hmac-md5; secret "a8Ht4BV08KljR6dWnF95Xa==" }; key keytwo { algorithm hmac-md5; secret "hifXw4R5I3Nvn6qjiG0h8A==" }; view view-one match-clients {key keyone; !key keytwo; ;...}; zone test.example.com { type primary; file "db.test.example.com"; }; view view-two match-clients {key keytwo; !key keyone; ;...}; zone test.example.com { type primary; file "db.test.example.com"; }; }; ``` What this shows is the following: - Any message not containing either key will first be tested against other elements in the `match-clients` address match list in `view-one`. - If a match for the source address of the packet containing the message (since this is a `match-clients` statement) is found then `view-one` has been matched, no more testing is done and the response, if there is one, will be served from that view. - If the source address does **not** match any element in `view-one`'s `match-clients` list then processing continues with the next view in order. - Any message containing `keyone` will match against `key keyone` in the `match-clients` statement in `view-one`, no more testing is done and the response, if there is one, will be served from that view. - Any message containing `keytwo` will **not** match against the `match-clients` statement in `view-one` because of the `!key keytwo` element and processing continues, testing against the next view. - Having failed to match against `view-one`, a message containing `keytwo` will match against `view-two` because its `match-clients` statement contains an explicit element `key keytwo`. One view only Once the server has found a match and determined which view is going to be responsible for handling a given query, no further testing is performed. That means that, if `view x` is a match, but for some reason cannot fulfil the request, query processing stops there. It **does not** fall through to `view y`, `view z` etc. The simple examples given above use the same primary zone in both views, which, on its own, does nothing particularly useful as clients matching either view will receive the same responses. But the power of views comes from being able to change settings and policies, zones, forwarding etc. between views. e.g. `view-one` may be used for forwarding to a specific set of resolvers, perhaps internal to your infrastructure, and `view-two` may be used for recursion. That could look something like this (other configuration has been omitted, for clarity): ``` view view-one { match-clients {!key keytwo; key keyone; 10.0.0.0/8;}; forwarders {x.x.x.x; y.y.y.y;}; forward only; }; view view-two { match-clients {key keytwo; any;}; }; ``` Clients matching `view-one` will be answered from cache, or the server will forward queries to one of the listed addresses to obtain answers. Perhaps these forwarders provide a filtered DNS service, thus this view is providing a walled garden function for all clients using TSIG key `keyone`, or with a source address in the 10/8 range. `forward only` tells the server to **not** recurse if all forwarding should fail. Clients matching `view-two` will be answered from cache, or the server will recurse (start at the DNS root, if necessary, and make queries to successive nameservers) to obtain answers. per view cache Another important point to note about views is that each maintains its own cache, if it is permitted to recurse by specifying `recursion yes;`, which is the default. This can be an important consideration when planning how many views you need and the total RAM available in the system. By default, each view will set a `max-cache-size` of 90% of available memory. Note that BIND does not request this memory up front. If it tried to do that then even two views would fail. ### Sharing resources between views There are a few ways to share resources between views. Whilst this may sound an odd thing to want to do at first - you created views **because** you want different user poulations to not have the same experience - there can be value in sharing some things. Examples are given below. #### `in-view` This is used in one view to reference a zone that has already been defined in another view. This would work for the examples shown earlier, where both views contained the zone `test.example.com`. It could be used like this: ``` view view-one { zone test.example.com { type primary; file "db.test.example.com"; }; }; view view-two { zone test.example.com { in-view view-one; }; }; ``` #### `attach-cache` This is used in one view to cause it to reference the cache of another view. You might want to do this if, for instance, `view-one` is very busy and typically has a rich cache, but `view-two` is used far less, so does not have the opportunity to build up much of a cache of its own. Piggybacking on `view-one`'s cache may help to speed up the processing of queries that land in `view-two` and also helps to reduce the overall memory requirement of the server. Views must share some common properties In order for `attach-cache` to be accepted at run time, some parameters of both views must be the same, or `named` will fail to start. At least the following statements must have the same values in both views: - check-names - cleaning-interval - zero-no-soa-ttl - max-cache-size - max-cache-ttl - max-ncache-ttl - max-stale-ttl - dnssec-validation - dnssec-accept-expired ### Performance implications of using views. There are no definitive figures on how the use of views will impact server performance. It depends greatly on factors such as; - How many views are configured. - What is the relative split of traffic between views. - How many different criteria are used to filter traffic. - What each view is used for. - Memory (RAM) available to `named`. As with all configuration and tuning, it must be tested in your own environment, with your own client dynamics on your own network infrastrauctre to obtain the best information about how a given configuration will perform for you. Some points worth considering when planning whether and how to use views are: 1. Since views are tested top down as queries arrive, the more views there are, potentially the more testing will need to be done against the match criteria in each view. 2. A consequence of the above point is that busy views should be configured first. For example, if the intention is to have one view for recursive client queries and another for zone transfers it is probably best to have the recursive client view first because it is likely it will be handling a greater volume of messages, coupled with the clients themselves being impatient. 3. An inefficient configuration would be to use lots of views and place the busiest last. 4. Memory usage and possible resource sharing between views. As discussed earlier, techniques are available to share common information between views, reducing the overall resource requirements. The general advice, therefore is: - If you have to use views, try to plan for as few as possible. - Order them sensibly, generally busiest first. - Keep matches in each view to the minimum necessary for filtering messages. - Take advantage of resource sharing, where possible or appropriate.