OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • DNS Services Comparison
        • Installation
        • Configuration
          • Base Configuration File
          • Zone File Format
          • Permissions
        • Zone Validation and Reload
        • DNSSEC with NSD
        • Controlling NSD
        • Logging and Debugging
        • Example Usage
        • Summary of Key Files and Directories

        NSD Authoritative DNS Server

        Synopsis #

        nsd(8) is an authoritative DNS server developed by NLnet Labs and included in the OpenBSD base system. It answers queries for configured zones and does not resolve other domains for clients.

        This chapter describes the configuration and management of nsd(8) on OpenBSD for serving DNS zones to the public or within internal networks.

        DNS Services Comparison #

        Compare NSD with the other DNS daemons available on OpenBSD:

        Featureunbound(8)nsd(8)named(8) (BIND)
        PurposeResolverAuthoritativeBoth
        Included in OpenBSD baseYesYesNo
        Recursive resolutionYesNoYes
        Authoritative serverNoYesYes
        DNSSEC validationYesNo (serves DNSSEC data)Yes
        DNS-over-TLS supportYesYesYes
        ComplexityLowLowHigh
        Use caseClient systemsHosting zonesMixed environments

        Installation #

        nsd(8) is included in the OpenBSD 8.0 base system. No external packages are required.

        Enable nsd at boot:

        doas rcctl enable nsd
        

        Start the daemon:

        doas rcctl start nsd
        

        The main configuration directory is /var/nsd. Configuration files are stored in:

        /var/nsd/etc/nsd.conf
        

        Zone files are typically stored in:

        /var/nsd/zones/
        

        Configuration #

        Base Configuration File #

        An example minimal configuration for a domain example.com is shown below:

        server:
            hide-version: yes
            zonesdir: "/var/nsd/zones"
            ip-address: 192.0.2.1
        
        remote-control:
            control-enable: yes
            control-interface: /var/run/nsd.sock
        
        zone:
            name: "example.com"
            zonefile: "example.com.zone"
        

        The server: section sets daemon options, and each zone: section defines a domain to serve. Keep remote-control: enabled: OpenBSD’s rcctl uses its local Unix socket to check, reload, and stop NSD.

        Once this file is created at /var/nsd/etc/nsd.conf, test it:

        doas nsd-checkconf /var/nsd/etc/nsd.conf
        

        Zone File Format #

        Zone files use standard BIND-style syntax:

        $ORIGIN example.com.
        $TTL 3600
        @   IN  SOA ns1.example.com. hostmaster.example.com. (
                2025080401 ; serial
                3600       ; refresh
                1800       ; retry
                604800     ; expire
                86400 )    ; minimum TTL
            IN  NS  ns1.example.com.
            IN  NS  ns2.example.com.
        ns1 IN  A   192.0.2.1
        ns2 IN  A   192.0.2.2
        www IN  A   192.0.2.100
        

        Store this file as /var/nsd/zones/example.com.zone.

        Permissions #

        Ensure ownership and permissions are correct:

        doas chown root:_nsd /var/nsd/zones/example.com.zone
        doas chmod 640 /var/nsd/zones/example.com.zone
        

        Zone Validation and Reload #

        NSD reads zone files directly; current NSD does not use the old binary zone database or nsd-control rebuild command. Validate configuration and zone data:

        doas nsd-checkconf /var/nsd/etc/nsd.conf
        doas nsd-checkzone example.com /var/nsd/zones/example.com.zone
        

        Increment the zone serial when updating published records. After successful checks, reload using the configured control channel or restart the service.

        DNSSEC with NSD #

        NSD serves signed zone data but does not perform recursive DNSSEC validation. Signing is a separate operation. Tools such as ldns-signzone require the appropriate package, a private signing key and its public-key companion, and a signing/renewal policy. Pass key basenames as documented by the installed tool, serve the resulting signed zone, and coordinate the DS record with the parent zone. Validate signatures before publishing that DS.

        Controlling NSD #

        The default /var/nsd/etc/nsd.conf includes this section for local administration:

        remote-control:
            control-enable: yes
            control-interface: /var/run/nsd.sock
        

        After checking the configuration and starting NSD with the socket enabled, use:

        doas nsd-control status
        doas nsd-control reload
        

        A local Unix socket does not require the TLS files generated by nsd-control-setup. Remote TCP control needs explicit configuration and protected keys. nsd-control addzone takes a configured pattern name as its second argument, not a configuration-file path. Use a static zone: entry unless dynamic zone management is required.

        Logging and Debugging #

        Logging is sent to syslog(3) under the daemon facility. To view logs:

        doas tail -f /var/log/daemon
        

        Increase verbosity for debugging:

        server:
            verbosity: 2
        

        Then restart the service:

        doas rcctl restart nsd
        

        Example Usage #

        To serve the domain example.com:

        1. Place zone file at /var/nsd/zones/example.com.zone
        2. Add configuration to /var/nsd/etc/nsd.conf
        3. Run:
        doas nsd-checkconf
        doas rcctl restart nsd
        

        To verify:

        drill @192.0.2.1 www.example.com
        

        Summary of Key Files and Directories #

        File/DirectoryDescription
        /var/nsd/etc/nsd.confNSD configuration file
        /var/nsd/zones/Zone data files
        /var/nsd/run/nsd.pidPID file for nsd(8)
        /var/nsd/etc/nsd_control.*nsd-control TLS keys and certs
        /var/log/daemonLog output via syslog
        Report a bug
        • Synopsis
        • DNS Services Comparison
        • Installation
        • Configuration
          • Base Configuration File
          • Zone File Format
          • Permissions
        • Zone Validation and Reload
        • DNSSEC with NSD
        • Controlling NSD
        • Logging and Debugging
        • Example Usage
        • Summary of Key Files and Directories