Create a basic configuration file at /etc/nsd/nsd.conf:
/etc/nsd/nsd.conf
# NSD configuration fileserver: # Run as the nsd user username: nsd # Listen on all interfaces # ip-address: 0.0.0.0 # ip-address: ::0 # Use 1 server process (increase for multi-core systems) server-count: 1 # IPv4 and IPv6 support do-ip4: yes do-ip6: yes # Port to answer queries on port: 53 # Logging logfile: "/var/log/nsd.log" verbosity: 1 # PID file location pidfile: "/var/run/nsd.pid" # Zone files directory zonesdir: "/etc/nsd/zones" # Database directory for state files database: "" xfrdfile: "/var/lib/nsd/xfrd.state" zonelistfile: "/var/lib/nsd/zone.list"# Remote control configurationremote-control: # Enable nsd-control control-enable: yes # Listen only on localhost for security control-interface: 127.0.0.1 control-interface: ::1 # Control port control-port: 8952 # TLS certificates (generated by nsd-control-setup) server-key-file: "/etc/nsd/nsd_server.key" server-cert-file: "/etc/nsd/nsd_server.pem" control-key-file: "/etc/nsd/nsd_control.key" control-cert-file: "/etc/nsd/nsd_control.pem"# Define a zonezone: name: example.com zonefile: example.com.zone
Configuration highlights:
server-count: 1 - Runs one server process. Increase this to match CPU cores for better performance.
zonesdir - All zone file paths are relative to this directory
control-enable: yes - Enables nsd-control for management
control-interface: 127.0.0.1 - Only allows local control for security
For production systems with multiple cores, optimize performance:
Multi-core configuration
server: # Use one process per CPU core server-count: 4 # Pin each server to a dedicated CPU core server-1-cpu-affinity: 0 server-2-cpu-affinity: 1 server-3-cpu-affinity: 2 server-4-cpu-affinity: 3 # Pin xfrd to its own core xfrd-cpu-affinity: 4 # Enable socket reuse for better performance reuseport: yes
Create your first zone file at /etc/nsd/zones/example.com.zone:
/etc/nsd/zones/example.com.zone
; Zone file for example.com$ORIGIN example.com.$TTL 3600; SOA Record (Start of Authority)@ IN SOA ns1.example.com. admin.example.com. ( 2024030801 ; Serial (YYYYMMDDNN format) 3600 ; Refresh (1 hour) 1800 ; Retry (30 minutes) 604800 ; Expire (1 week) 86400 ) ; Minimum TTL (1 day); Name Server Records IN NS ns1.example.com. IN NS ns2.example.com.; A Records (IPv4)@ IN A 192.0.2.1ns1 IN A 192.0.2.10ns2 IN A 192.0.2.11www IN A 192.0.2.1mail IN A 192.0.2.20; AAAA Records (IPv6)@ IN AAAA 2001:db8::1www IN AAAA 2001:db8::1; MX Record (Mail Exchange)@ IN MX 10 mail.example.com.; TXT Records@ IN TXT "v=spf1 mx -all"_dmarc IN TXT "v=DMARC1; p=reject; rua=mailto:[email protected]"; CNAME Recordftp IN CNAME www.example.com.
Zone file key points:
$ORIGIN - Sets the domain name for the zone
$TTL - Default Time-To-Live for records (in seconds)
SOA Serial - Must be incremented with each zone update
Serial format - Use YYYYMMDDNN (year, month, day, revision number)
# Check if NSD process is runningps aux | grep nsd# Check if NSD is listening on port 53sudo netstat -tulpn | grep :53# or with sssudo ss -tulpn | grep :53# Use nsd-controlsudo nsd-control status
Expected output from nsd-control status:
version: 4.14.2verbosity: 1ratelimit: offserver1 zone example.com state ok
# Reload all zonessudo nsd-control reload# Reload specific zonesudo nsd-control reload example.com
2
View Statistics
Check server statistics:
sudo nsd-control stats
Shows query counts, zone info, and performance metrics.
3
Add Zone Dynamically
Add a new zone without restarting:
# Add zone to running NSDsudo nsd-control addzone example.net /etc/nsd/zones/example.net.zone# Zone is now served immediatelydig @localhost example.net SOA
4
Stop NSD
Gracefully stop the server:
# Using nsd-controlsudo nsd-control stop# Or systemdsudo systemctl stop nsd