How to Install NSD on OpenBSD

NSD, or Name Server Daemon, is a versatile and efficient open-source DNS server. In this tutorial, we will go over the steps to install NSD on OpenBSD.

Prerequisites

Before we begin, make sure that you have the following prerequisites:

Installing NSD

Open a terminal or shell session and follow these steps to install NSD:

  1. Update the package repository:

    $ sudo pkg_add -Uu
    
  2. Install NSD:

    $ sudo pkg_add nsd
    
  3. Confirm the installation by querying the version of NSD installed on your system:

    $ nsd -v
    NSD 4.3.6
    
  4. Start the NSD service:

    $ sudo rcctl enable nsd
    $ sudo rcctl start nsd
    

    The enable command configures NSD to start at boot time, and the start command starts the NSD service immediately.

Configuring NSD

Now that NSD is installed and running, let's configure it to serve DNS requests for your domain(s). Follow these steps to create a basic configuration for NSD:

  1. Create a configuration file for NSD:

    $ sudo touch /var/nsd/etc/nsd.conf
    
  2. Add the following configuration to the nsd.conf file:

    server:
        hide-version: yes
        logfile: "/var/nsd/log/nsd.log"
    
    zone:
        name: "example.com"
        zonefile: "/var/nsd/zones/example.com.zone"
    

    This configuration tells NSD to serve DNS requests for the example.com domain and to log its activity to /var/nsd/log/nsd.log.

  3. Create a zone file for your domain. For example:

    $ sudo touch /var/nsd/zones/example.com.zone
    
  4. Edit the zone file and add the following contents:

    $ORIGIN example.com.
    $TTL 86400   ; 24 hours
    
    example.com.   IN SOA  ns1.example.com. admin.example.com. (
                    1   ; serial number
                    3600   ; refresh every hour
                    600   ; retry every 10 minutes
                    86400   ; expire after 1 day
                    3600 ) ; default TTL of 1 hour
    
    example.com.   IN NS ns1.example.com.
    ns1.example.com.   IN A 192.0.2.1
    

    This configuration sets up a basic DNS zone for the example.com domain, with a single nameserver (ns1.example.com) and an IP address associated with it.

  5. Reload the NSD configuration:

    $ sudo rcctl reload nsd
    

    This command reloads the NSD configuration, which incorporates the changes you made to the nsd.conf file and the zone file.

Testing NSD

To test if NSD is running and serving DNS requests, follow these steps:

  1. Query NSD for the IP address of ns1.example.com:

    $ nslookup ns1.example.com localhost
    
  2. Verify that the response matches the IP address you configured in your zone file.

Congratulations! You've successfully installed and configured NSD on OpenBSD.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!