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:
- A server or virtual machine (VM) running OpenBSD.
- Root or sudo access to the server or VM.
- An internet connection for downloading and installing NSD.
Installing NSD
Open a terminal or shell session and follow these steps to install NSD:
Update the package repository:
$ sudo pkg_add -UuInstall NSD:
$ sudo pkg_add nsdConfirm the installation by querying the version of NSD installed on your system:
$ nsd -v NSD 4.3.6Start the NSD service:
$ sudo rcctl enable nsd $ sudo rcctl start nsdThe
enablecommand configures NSD to start at boot time, and thestartcommand 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:
Create a configuration file for NSD:
$ sudo touch /var/nsd/etc/nsd.confAdd the following configuration to the
nsd.conffile: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.comdomain and to log its activity to/var/nsd/log/nsd.log.Create a zone file for your domain. For example:
$ sudo touch /var/nsd/zones/example.com.zoneEdit 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.1This configuration sets up a basic DNS zone for the
example.comdomain, with a single nameserver (ns1.example.com) and an IP address associated with it.Reload the NSD configuration:
$ sudo rcctl reload nsdThis command reloads the NSD configuration, which incorporates the changes you made to the
nsd.conffile and the zone file.
Testing NSD
To test if NSD is running and serving DNS requests, follow these steps:
Query NSD for the IP address of
ns1.example.com:$ nslookup ns1.example.com localhostVerify that the response matches the IP address you configured in your zone file.
Congratulations! You've successfully installed and configured NSD on OpenBSD.