Setting up unbound DNS server: Difference between revisions
m (Changed hyperlink to https) |
Prabuanand (talk | contribs) m (added Pi-hole wikilink) |
||
| (9 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
[ | [https://nlnetlabs.nl/projects/unbound/about/ Unbound] is a validating, recursive, and caching DNS resolver that supports DNSSEC. | ||
= | == Installation == | ||
Install the {{Pkg|unbound}} package: | Install the {{Pkg|unbound}} package: {{Cmd|# apk add unbound}} | ||
{{Cmd|apk add unbound}} | |||
= | == Configuration == | ||
The following configuration is an example of a caching name server (in a production server, it's recommended to adjust the access-control parameter to limit access to your network). The forward-zone(s) section will forward all DNS queries to the specified servers. Don't forget to change the 'interface' parameter to that of your local interface IP address (or 0.0.0.0 to listen on all local IPv4 interfaces). The following is a minimal example with many options commented out | The following configuration is an example of a caching name server (in a production server, it's recommended to adjust the access-control parameter to limit access to your network). The forward-zone(s) section will forward all DNS queries to the specified servers. Don't forget to change the 'interface' parameter to that of your local interface IP address (or 0.0.0.0 to listen on all local IPv4 interfaces). The following is a minimal example with many options commented out:{{Cat|/etc/unbound/unbound.conf|<nowiki>server: | ||
{{ | |||
< | |||
server: | |||
verbosity: 1 | verbosity: 1 | ||
## Specify the interface address to listen on: | ## Specify the interface address to listen on: | ||
| Line 62: | Line 57: | ||
forward-addr: 4.2.2.1 | forward-addr: 4.2.2.1 | ||
forward-addr: 4.2.2.4 | forward-addr: 4.2.2.4 | ||
</ | </nowiki> | ||
}} | |||
== Service management == | |||
Check the configuration file for errors:{{Cmd|$ unbound-checkconf}} | |||
If no errors are reported, add the {{ic|unbound}} service to auto-start using [[OpenRC]]: {{Cmd|# rc-update add unbound default}} | |||
{{ic|unbound}} service can be managed using standard start|stop|restart [[OpenRC]] commands. To start the service immediately:{{Cmd|# rc-service unbound start}} | |||
== Testing == | |||
Test the working of DNS service as follows: {{Cmd|$ nslookup www.google.cz 10.0.0.1}} | |||
or: | |||
use {{ic|dig}} command from {{Pkg|bind-tools}} package:{{Cmd|$ dig dl-cdn.alpinelinux.org @10.0.0.1}} | |||
or: | |||
use {{ic|drill}} command from the {{Pkg|drill}} package: {{Cmd|$ drill www.bbc.co.uk @10.0.0.1}} | |||
== root-hints == | == root-hints == | ||
Instead of forwarding queries to a public DNS server, you may prefer to query the root DNS servers. To do this, comment out the forwarding entries ("forward-zone" sections) in the config. | |||
{{Cmd|wget -S https://www.internic.net/domain/named.cache -O /etc/unbound/root.hints}} | Instead of forwarding queries to a public DNS server, you may prefer to query the root DNS servers. To do this, comment out the forwarding entries ("forward-zone" sections) in the config. | ||
=== Download root hints === | |||
Grab the latest root hints file using wget and place it the at {{Path|/etc/unbound/root.hints}} as follows: {{Cmd|# wget -S https://www.internic.net/domain/named.cache -O /etc/unbound/root.hints}} | |||
=== Enable root hints === | |||
Point unbound to the root hints file by adding the following line to the server section of the unbound config file: | |||
<pre> | <pre> | ||
root-hints: "/etc/unbound/root.hints" | root-hints: "/etc/unbound/root.hints" | ||
</pre> | </pre> | ||
Restart unbound to ensure the changes take effect. | [[#Service management|Restart unbound]] to ensure the changes take effect. You may wish to setup a [[Alpine_Linux:FAQ#Why_don't_my_cron_jobs_run?|cron job]] to update the root hints file occasionally. | ||
== 0x20 bit == | == 0x20 bit == | ||
Use of the [https:// | |||
Use of the [https://datatracker.ietf.org/doc/html/draft-vixie-dnsext-dns0x20-00.html 0x20 bit] is considered experimental. It makes use of an otherwise unused bit in a DNS packet to ask an authoritative server to respond with an answer mimicking the case used in the query. | |||
For example, when using this feature a query for www.google.com could appear in the request as www.google.com or Www.GoogLe.coM or WWW.GoOGlE.cOm or any other conbination of upper and lower case. The authoritative server should respond with the same case. This helps prevent DNS spoofing attacks. | For example, when using this feature a query for www.google.com could appear in the request as www.google.com or Www.GoogLe.coM or WWW.GoOGlE.cOm or any other conbination of upper and lower case. The authoritative server should respond with the same case. This helps prevent DNS spoofing attacks. | ||
| Line 83: | Line 103: | ||
</pre> | </pre> | ||
= | == See also == | ||
= | |||
[https://calomel.org/unbound_dns.html excellent unbound tutorial at calomel.org] | * [https://unbound.docs.nlnetlabs.nl/en/latest/ Official website] | ||
* [[Using Unbound as an Ad-blocker]] | |||
* [[Using Pi-hole with Unbound]] | |||
* [https://linux.die.net/man/5/unbound.conf unbound.conf man page] | |||
* [https://web.archive.org/web/20180508133447/https://unbound.net/documentation/howto_optimise.html unbound optimization guide] | |||
* [https://calomel.org/unbound_dns.html excellent unbound tutorial at calomel.org] | |||
* Wikipedia pages | |||
** [https://en.wikipedia.org/wiki/Domain_Name_System DNS] | |||
** [https://en.wikipedia.org/wiki/List_of_DNS_record_types record types] | |||
** [https://en.wikipedia.org/wiki/Dns_zone zones] | |||
** [https://en.wikipedia.org/wiki/Name_server name servers] | |||
** [https://en.wikipedia.org/wiki/Dnssec DNSsec] | |||
[[Category:Networking]] | [[Category:Networking]] | ||
Latest revision as of 07:55, 3 November 2025
Unbound is a validating, recursive, and caching DNS resolver that supports DNSSEC.
Installation
Install the unbound package:
# apk add unbound
Configuration
The following configuration is an example of a caching name server (in a production server, it's recommended to adjust the access-control parameter to limit access to your network). The forward-zone(s) section will forward all DNS queries to the specified servers. Don't forget to change the 'interface' parameter to that of your local interface IP address (or 0.0.0.0 to listen on all local IPv4 interfaces). The following is a minimal example with many options commented out:
Contents of /etc/unbound/unbound.conf
Service management
Check the configuration file for errors:
$ unbound-checkconf
If no errors are reported, add the unbound service to auto-start using OpenRC:
# rc-update add unbound default
unbound service can be managed using standard start|stop|restart OpenRC commands. To start the service immediately:
# rc-service unbound start
Testing
Test the working of DNS service as follows:
$ nslookup www.google.cz 10.0.0.1
or:
use dig command from bind-tools package:
$ dig dl-cdn.alpinelinux.org @10.0.0.1
or:
use drill command from the drill package:
$ drill www.bbc.co.uk @10.0.0.1
root-hints
Instead of forwarding queries to a public DNS server, you may prefer to query the root DNS servers. To do this, comment out the forwarding entries ("forward-zone" sections) in the config.
Download root hints
Grab the latest root hints file using wget and place it the at /etc/unbound/root.hints as follows:
# wget -S https://www.internic.net/domain/named.cache -O /etc/unbound/root.hints
Enable root hints
Point unbound to the root hints file by adding the following line to the server section of the unbound config file:
root-hints: "/etc/unbound/root.hints"
Restart unbound to ensure the changes take effect. You may wish to setup a cron job to update the root hints file occasionally.
0x20 bit
Use of the 0x20 bit is considered experimental. It makes use of an otherwise unused bit in a DNS packet to ask an authoritative server to respond with an answer mimicking the case used in the query.
For example, when using this feature a query for www.google.com could appear in the request as www.google.com or Www.GoogLe.coM or WWW.GoOGlE.cOm or any other conbination of upper and lower case. The authoritative server should respond with the same case. This helps prevent DNS spoofing attacks.
In some cases a very small number of old or misconfigured servers may return an error (less than 1% of servers will respond incorrectly). To turn on this feature, simply add the following line to the 'server' section of /etc/unbound/unbound.conf and restart the server:
use-caps-for-id: yes