Lessons

Setting Up BIND 9 DNS Server

Level: Intermediate Module: TCP/IP & Networking 5 min read Lesson 17 of 66

Overview

  • What you’ll learn: How to install and configure BIND 9 on Ubuntu Server, create forward and reverse lookup zones, define resource records, configure zone transfers for secondary servers, and test your DNS server.
  • Prerequisites: Lesson 16 – DNS Fundamentals
  • Estimated reading time: 25 minutes

Introduction

BIND (Berkeley Internet Name Domain) is the most widely deployed DNS server software on the Internet. BIND 9, the current major version, is maintained by the Internet Systems Consortium (ISC) and supports authoritative DNS, recursive resolution, DNSSEC, and dynamic updates.

Running your own DNS server gives you complete control over name resolution for your domain. This is essential for internal networks, split-horizon DNS configurations, and environments where you need custom DNS records that a registrar’s DNS panel cannot provide.

In this lesson, you will install BIND 9 on Ubuntu Server, configure it as an authoritative DNS server, create forward and reverse zones, and verify that resolution works correctly.

Installing BIND 9

BIND 9 is available in the Ubuntu package repositories. The installation includes the server daemon (named), configuration utilities, and documentation.

# Install BIND 9 and utilities
$ sudo apt update
$ sudo apt install -y bind9 bind9-utils bind9-dnsutils

# Verify the installation
$ named -v
BIND 9.18.18-0ubuntu0.22.04.2-Ubuntu (Extended Support Version)

# Check the service status
$ sudo systemctl status named
● named.service - BIND Domain Name Server
     Loaded: loaded (/lib/systemd/system/named.service; enabled)
     Active: active (running) since Mon 2025-01-01 10:00:00 UTC

# BIND configuration directory structure
$ ls /etc/bind/
bind.keys  db.0  db.127  db.255  db.empty  db.local
named.conf  named.conf.default-zones  named.conf.local
named.conf.options  rndc.key  zones.rfc1918

Configuring BIND 9 Options

The main configuration is split across several files. named.conf is the entry point that includes the other files. Start by configuring global options in named.conf.options.

# /etc/bind/named.conf.options
options {
    directory "/var/cache/bind";

    // Listen on local interfaces
    listen-on { 127.0.0.1; 192.168.1.10; };
    listen-on-v6 { ::1; };

    // Allow queries from the local network
    allow-query { localhost; 192.168.1.0/24; };

    // Forwarding: send unresolved queries to upstream DNS
    forwarders {
        8.8.8.8;
        8.8.4.4;
    };

    // Enable recursion only for trusted clients
    recursion yes;
    allow-recursion { localhost; 192.168.1.0/24; };

    // DNSSEC validation
    dnssec-validation auto;

    // Hide version for security
    version "not disclosed";
};

# Validate the configuration
$ sudo named-checkconf
# (No output means the configuration is valid)

Creating a Forward Lookup Zone

A forward lookup zone maps domain names to IP addresses. You define the zone in named.conf.local and create the zone file with your resource records.

# /etc/bind/named.conf.local — Add zone declaration
zone "lab.example.com" {
    type primary;
    file "/etc/bind/zones/db.lab.example.com";
    allow-transfer { 192.168.1.11; };  // Secondary DNS server
};

# Create the zones directory
$ sudo mkdir -p /etc/bind/zones

# /etc/bind/zones/db.lab.example.com — Forward zone file
$TTL    604800
@       IN      SOA     ns1.lab.example.com. admin.lab.example.com. (
                     2025010101         ; Serial (YYYYMMDDNN)
                         604800         ; Refresh (7 days)
                          86400         ; Retry (1 day)
                        2419200         ; Expire (28 days)
                         604800 )       ; Negative Cache TTL (7 days)

; Name servers
@       IN      NS      ns1.lab.example.com.
@       IN      NS      ns2.lab.example.com.

; A records
ns1     IN      A       192.168.1.10
ns2     IN      A       192.168.1.11
web     IN      A       192.168.1.20
db      IN      A       192.168.1.30
mail    IN      A       192.168.1.40

; CNAME records
www     IN      CNAME   web.lab.example.com.
ftp     IN      CNAME   web.lab.example.com.

; MX record
@       IN      MX  10  mail.lab.example.com.

# Validate the zone file
$ sudo named-checkzone lab.example.com /etc/bind/zones/db.lab.example.com
zone lab.example.com/IN: loaded serial 2025010101
OK

Creating a Reverse Lookup Zone

A reverse lookup zone maps IP addresses back to domain names using PTR records. The zone name is based on the reversed IP network octets followed by .in-addr.arpa.

# /etc/bind/named.conf.local — Add reverse zone
zone "1.168.192.in-addr.arpa" {
    type primary;
    file "/etc/bind/zones/db.192.168.1";
    allow-transfer { 192.168.1.11; };
};

# /etc/bind/zones/db.192.168.1 — Reverse zone file
$TTL    604800
@       IN      SOA     ns1.lab.example.com. admin.lab.example.com. (
                     2025010101         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL

; Name servers
@       IN      NS      ns1.lab.example.com.
@       IN      NS      ns2.lab.example.com.

; PTR records
10      IN      PTR     ns1.lab.example.com.
11      IN      PTR     ns2.lab.example.com.
20      IN      PTR     web.lab.example.com.
30      IN      PTR     db.lab.example.com.
40      IN      PTR     mail.lab.example.com.

# Validate the reverse zone
$ sudo named-checkzone 1.168.192.in-addr.arpa /etc/bind/zones/db.192.168.1
zone 1.168.192.in-addr.arpa/IN: loaded serial 2025010101
OK

# Restart BIND to load the new zones
$ sudo systemctl restart named

# Test forward resolution
$ dig @192.168.1.10 web.lab.example.com A +short
192.168.1.20

# Test reverse resolution
$ dig @192.168.1.10 -x 192.168.1.20 +short
web.lab.example.com.

Key Takeaways

  • BIND 9 is the most widely used DNS server software, supporting authoritative zones, recursion, DNSSEC, and zone transfers.
  • Configuration is split across named.conf, named.conf.options (global settings), and named.conf.local (zone declarations).
  • Forward zones map names to addresses (A/AAAA records); reverse zones map addresses to names (PTR records in the .in-addr.arpa domain).
  • Always validate with named-checkconf (configuration) and named-checkzone (zone files) before restarting the service.
  • Remember to increment the SOA serial number every time you modify a zone file — secondary servers use this to detect changes.

What’s Next

In Lesson 18, you will learn how to set up a DHCP Server with isc-kea — the modern replacement for ISC DHCP, capable of dynamically assigning IP addresses, options, and integrating with DNS.

繁體中文

概述

  • 學習目標:如何在 Ubuntu Server 上安裝和設定 BIND 9、建立正向和反向查詢區域、定義資源記錄、設定次要伺服器的區域傳輸,以及測試您的 DNS 伺服器。
  • 先決條件:第 16 課 – DNS 基礎
  • 預計閱讀時間:25 分鐘

簡介

BIND(Berkeley Internet Name Domain)是網際網路上部署最廣泛的 DNS 伺服器軟體。BIND 9 是目前的主要版本,由網際網路系統聯合會(ISC)維護,支援授權 DNS、遞迴解析、DNSSEC 和動態更新。

執行自己的 DNS 伺服器可以讓您完全控制網域的名稱解析。這對於內部網路、分離水平 DNS 設定,以及需要註冊商 DNS 面板無法提供的自訂 DNS 記錄的環境至關重要。

在本課程中,您將在 Ubuntu Server 上安裝 BIND 9,將其設定為授權 DNS 伺服器,建立正向和反向區域,並驗證解析是否正確運作。

安裝 BIND 9

BIND 9 可在 Ubuntu 套件儲存庫中取得。安裝包括伺服器守護程序(named)、設定工具和文件。

設定 BIND 9 選項

主要設定分布在多個檔案中。named.conf 是包含其他檔案的入口點。首先在 named.conf.options 中設定全域選項。

建立正向查詢區域

正向查詢區域將網域名稱對應到 IP 位址。您在 named.conf.local 中定義區域,並建立包含資源記錄的區域檔案。

建立反向查詢區域

反向查詢區域使用 PTR 記錄將 IP 位址對應回網域名稱。區域名稱基於反轉的 IP 網路八位元組,後接 .in-addr.arpa

重要觀念

  • BIND 9 是使用最廣泛的 DNS 伺服器軟體,支援授權區域、遞迴、DNSSEC 和區域傳輸。
  • 設定分布在 named.confnamed.conf.options(全域設定)和 named.conf.local(區域宣告)中。
  • 正向區域將名稱對應到位址(A/AAAA 記錄);反向區域將位址對應到名稱(.in-addr.arpa 域中的 PTR 記錄)。
  • 重新啟動服務前,務必使用 named-checkconf(設定)和 named-checkzone(區域檔案)進行驗證。
  • 每次修改區域檔案時都要記得遞增 SOA 序號——次要伺服器使用此序號來偵測變更。

下一步

在第 18 課中,您將學習如何使用 isc-kea 設定 DHCP 伺服器——ISC DHCP 的現代替代品,能夠動態分配 IP 位址、選項,並與 DNS 整合。

日本語

概要

  • 学習内容:Ubuntu ServerでのBIND 9のインストールと設定方法、正引きおよび逆引きゾーンの作成、リソースレコードの定義、セカンダリサーバーのゾーン転送の設定、DNSサーバーのテスト。
  • 前提条件:レッスン16 – DNSの基礎
  • 推定読了時間:25分

はじめに

BIND(Berkeley Internet Name Domain)はインターネット上で最も広くデプロイされているDNSサーバーソフトウェアです。現在のメジャーバージョンであるBIND 9はInternet Systems Consortium(ISC)によって維持され、権威DNS、再帰解決、DNSSEC、動的更新をサポートしています。

独自のDNSサーバーを運用することで、ドメインの名前解決を完全に制御できます。これは内部ネットワーク、スプリットホライズンDNS設定、レジストラのDNSパネルでは提供できないカスタムDNSレコードが必要な環境に不可欠です。

このレッスンでは、Ubuntu ServerにBIND 9をインストールし、権威DNSサーバーとして設定し、正引きおよび逆引きゾーンを作成し、解決が正しく動作することを確認します。

BIND 9 のインストール

BIND 9はUbuntuパッケージリポジトリで利用できます。インストールにはサーバーデーモン(named)、設定ユーティリティ、ドキュメントが含まれます。

BIND 9 オプションの設定

メインの設定は複数のファイルに分割されています。named.confは他のファイルをインクルードするエントリポイントです。まずnamed.conf.optionsでグローバルオプションを設定します。

正引きゾーンの作成

正引きゾーンはドメイン名をIPアドレスにマップします。named.conf.localでゾーンを定義し、リソースレコードを含むゾーンファイルを作成します。

逆引きゾーンの作成

逆引きゾーンはPTRレコードを使用してIPアドレスをドメイン名にマップします。ゾーン名は逆にしたIPネットワークオクテットに.in-addr.arpaを付加したものです。

重要ポイント

  • BIND 9は最も広く使用されているDNSサーバーソフトウェアで、権威ゾーン、再帰、DNSSEC、ゾーン転送をサポートしています。
  • 設定はnamed.confnamed.conf.options(グローバル設定)、named.conf.local(ゾーン宣言)に分割されています。
  • 正引きゾーンは名前をアドレスにマップし(A/AAAAレコード)、逆引きゾーンはアドレスを名前にマップします(.in-addr.arpaドメインのPTRレコード)。
  • サービスを再起動する前に、必ずnamed-checkconf(設定)とnamed-checkzone(ゾーンファイル)で検証してください。
  • ゾーンファイルを変更するたびにSOAシリアル番号をインクリメントすることを忘れないでください——セカンダリサーバーはこれを使用して変更を検出します。

次のステップ

レッスン18では、isc-keaによるDHCPサーバーのセットアップ方法を学びます——ISC DHCPの現代的な後継で、IPアドレス、オプションの動的割り当て、DNSとの統合が可能です。

You Missed