{"id":118,"date":"2025-05-13T11:11:22","date_gmt":"2025-05-13T02:11:22","guid":{"rendered":"https:\/\/blog.interstellar.co.jp\/en\/?p=118"},"modified":"2025-05-13T14:20:15","modified_gmt":"2025-05-13T05:20:15","slug":"nsd-unbound-dns-server","status":"publish","type":"post","link":"https:\/\/blog.interstellar.co.jp\/en\/2025\/05\/13\/nsd-unbound-dns-server\/","title":{"rendered":"Building DNS authoritative and cache servers with NSD and Unbound"},"content":{"rendered":"\n<p id=\"block-243e10a5-4cbc-48ad-bf88-9d5c37ac9587\">Hello, this is Agata.<\/p>\n\n\n\n<p>If you operate a mail server, you may encounter a large number of DNS queries when using DNSBL for spam prevention. In such cases, it is convenient to have a cache server.<\/p>\n\n\n\n<p id=\"block-23d1c37e-38c5-490a-a0c1-d0d7b19fe3ac\">BIND is a popular choice, but there are some security concerns. Therefore, we decided to try a different DNS server software and came up with the following configuration.<\/p>\n\n\n\n<ul id=\"block-915421ca-c3ed-47e4-8c39-7432e04b0c31\" class=\"wp-block-list\">\n<li>Authoritative server: NSD (lightweight and simple authoritative DNS server)<\/li>\n\n\n\n<li>Cache server: Unbound (secure, high-performance cache DNS resolver)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-1dd0adae-f770-459b-b984-1aec19e9d0cf\">What is NSD?<\/h2>\n\n\n\n<p id=\"block-111e5298-83a3-4bfd-b3b0-d8b75feeb52f\">NSD stands for \u201cName Server Daemon\u201d and is software dedicated to authoritative DNS servers. It is developed by NLnet Labs, a non-profit organization.<\/p>\n\n\n\n<p id=\"block-5c3c9c85-e06b-44a2-9ef5-14af20348758\">Its features are as follows.<\/p>\n\n\n\n<ul id=\"block-d1c1db3f-22bc-4b4e-88c5-16e20b61b4da\" class=\"wp-block-list\">\n<li>Simple and focused solely on authoritative server functions<\/li>\n\n\n\n<li>Lightweight and fast<\/li>\n\n\n\n<li>Security-conscious design<\/li>\n\n\n\n<li>Easier to configure than BIND<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-473851d8-a254-4265-8652-de4fe91c7029\">What is Unbound\uff1f<\/h2>\n\n\n\n<p id=\"block-d9186107-c36a-43bb-a7f8-f997a34fe1d6\">Unbound is a cache-only DNS resolver. It is also developed by NLnet Labs.<\/p>\n\n\n\n<p id=\"block-29e4b991-15e9-4bc4-8a4b-e03d47db4660\">The features are as follows.<\/p>\n\n\n\n<ul id=\"block-fe29f10f-818b-4478-821f-8cb278d4f342\" class=\"wp-block-list\">\n<li>Fast cache functionality<\/li>\n\n\n\n<li>Full security features (DNSSEC compatible)<\/li>\n\n\n\n<li>Memory efficient<\/li>\n\n\n\n<li>Easy to customize<\/li>\n<\/ul>\n\n\n\n<p id=\"block-41a30489-48f2-47d1-b5a2-b337e9ceccbf\">Now, let&#8217;s take a look at the actual setup procedure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-09ef2eff-9d81-47fe-a78e-d5c7f6e47de0\">Environment<\/h2>\n\n\n\n<p id=\"block-3b5f2b82-faba-4494-91f6-e2a02392fe3e\">OS\uff1aUbuntu24.04<\/p>\n\n\n\n<p id=\"block-b663b29a-4bcd-4460-ac9f-860e5546413d\">Run an authoritative server and a cache server on a single server.<\/p>\n\n\n\n<p>The cache server handles only local processing.<\/p>\n\n\n\n<p>For this reason, the authoritative server will listen on port 53, and the cache server will listen on port 5353. This means that local queries will not be sent to the cache server, so we will adjust the resolver (systemd-resolved) settings to address this.<\/p>\n\n\n\n<p id=\"block-5ca88bea-c6c6-45de-ad40-f205f35b9d0b\">* Ideally, these should be run on separate servers. However, in this case, the DNS authoritative server and mail server are running on a VPS, and the cache for DNSBL needs to be operated, resulting in this non-standard configuration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-61817efd-25aa-44e3-9c61-0c4fc3fe7d27\">Unbound settings<\/h2>\n\n\n\n<p id=\"block-c233601d-f01b-4af7-ab35-5b056e3f3da0\">First, let&#8217;s start with the cache server Unbound.<\/p>\n\n\n\n<p id=\"block-b4a8d99f-11de-4b68-b62c-ae51d57cb495\">Install Unbound with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo apt install unbound<\/code><\/pre>\n\n\n\n<p id=\"block-617f8006-3f4d-48e3-a899-ca4cb7b0a142\">Next, create the Unbound configuration file. Enter the following content into \/etc\/unbound\/unbound.conf.d\/local.conf.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">server:\n\tverbosity: 1\n\tinterface: 127.0.0.1\n\tport: 5353\n\tdo-not-query-localhost: no\n\n\thide-identity: yes\n\thide-version: yes\n\n\tcache-min-ttl: 60\n\tcache-max-ttl: 86400<\/code><\/pre>\n\n\n\n<p id=\"block-ea4b50b7-52ee-436b-8dfc-a3d3a5e44424\">Once you have configured the settings, restart Unbound.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl restart unbound<\/code><\/pre>\n\n\n\n<p id=\"block-52edee1e-de03-4c06-b976-543858a8ba91\">In Ubuntu 24.04, systemd-resolved is the default resolver. To point it to the Unbound you just set up, edit \/etc\/systemd\/resolved.conf.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">DNS=127.0.0.1:5353<\/code><\/pre>\n\n\n\n<p id=\"block-edb179aa-92e3-4e32-ae37-00e71491c6c7\">Let&#8217;s restart systemd-resolved as well.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl restart systemd-resolved<\/code><\/pre>\n\n\n\n<p id=\"block-e1dc5c9a-b79d-4d40-bf90-0f32e0b6ff97\">Now, let&#8217;s check if the name resolution works properly. After testing with the dig command, you can check the cache status of Unbound.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">dig www.google.com\nsudo unbound-control stats\nsudo unbound-control dump_cache<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-5270335e-9b87-4a74-80f9-4f9b2a858907\">NSD settings<\/h2>\n\n\n\n<p id=\"block-bb0d66de-b145-4f14-8ea2-850195af0359\">Next, we will configure the NSD for the authoritative server. Let&#8217;s start with the installation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo apt install nsd<\/code><\/pre>\n\n\n\n<p id=\"block-9b776114-d1f6-4899-aaf2-5abc9f566ba4\">Create a directory to store the zone files.<\/p>\n\n\n\n<p>In this case, since existing BIND zone files exist, copy the BIND zone files.<\/p>\n\n\n\n<p id=\"block-6001d261-442d-476a-ba5e-c4ba0114f48b\">NSD can basically use BIND zone files as they are.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo mkdir \/etc\/nsd\/zones\ncp db.example.com \/etc\/nsd\/zones\/example.com.zone<\/code><\/pre>\n\n\n\n<p id=\"block-1cc91b2a-dad8-40cf-8dbb-3d8daeb35ddc\">Create the NSD configuration file \/etc\/nsd\/nsd.conf.d\/example.com.conf.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">server:\n    ip-address: xxx.xxx.xxx.xxx\n    server-count: 1\n    ip4-only: no\n    hide-version: yes\n    identity: \"NSD\"\n    zonesdir: \"\/etc\/nsd\/zones\"\n\nremote-control:\n    control-enable: yes\n    control-interface: 127.0.0.1\n\nzone:\n    name: \"example.com\"\n    zonefile: \"example.com.zone\"<\/code><\/pre>\n\n\n\n<p id=\"block-a9fb336e-e0cf-4bfe-991b-729f18408cca\">Let&#8217;s check if there are any problems with the zone file syntax.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo nsd-checkzone example.com \/etc\/nsd\/zones\/example.com.zone\nzone example.com is ok<\/code><\/pre>\n\n\n\n<p id=\"block-5b0ccc65-f11f-4452-bb2e-2a5596569fdd\">Once confirmed, restart NSD.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl restart nsd<\/code><\/pre>\n\n\n\n<p id=\"block-2bdf15d5-0688-405b-9fb8-f7b6aa95e691\">That completes the basic DNS server settings! All that remains is to switch the name servers, and you will be ready for actual operation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-0b35f232-e4d4-4710-8d76-c6da1a0dab69\">Summary<\/h2>\n\n\n\n<p id=\"block-03a0940b-2f29-40f4-9728-ad995c370bb5\">In this article, we introduced how to build a DNS server using NSD and Unbound as DNS server software other than BIND. NSD is simple and designed specifically for authoritative servers, so it is easy to configure and secure. Unbound is also a high-performance cache resolver and is ideal for operating DNSBL.<\/p>\n\n\n\n<p>Of course, there may still be room for fine-tuning, but the basic configuration is sufficient for now.<\/p>\n\n\n\n<p id=\"block-1af07ef0-22a6-43b0-8d51-480262c14dbc\">That&#8217;s all for this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, this is Agata. If you operate a mail server, you may encounter a large number of DNS queries when using DNSBL for spam prevention. In such cases, it is convenient to have a cache server. BIND is a popular choice, but there are some security concerns. Therefore, we decided to try a different DNS server software and came up with the following configuration. What is NSD? NSD stands for \u201cName Server Daemon\u201d and is software dedicated to authoritative DNS servers. It is developed by NLnet Labs, a non-profit organization. Its features are as follows. What is Unbound\uff1f Unbound is a cache-only DNS resolver. It is also developed by NLnet&#8230;<\/p>\n","protected":false},"author":2,"featured_media":121,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[18],"tags":[33,26,28],"class_list":["post-118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application","tag-dns","tag-install","tag-linux"],"_links":{"self":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":4,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/118\/revisions\/125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/media\/121"}],"wp:attachment":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}