0388.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Setup Pi-Hole as a Recursive DNS Server with Unbound</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Browser Based,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Ad Blocker,Ad Blocking,DNS,Linux,Pi-Hole,Pi Hole,Network Wide Ad Blocking,Web Based,Web Based Tools,Unbound,Recursive DNS,Recursive DNS Server,Unbound DNS Server,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Setup Pi-Hole as a Recursive DNS Server with Unbound">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="11/13/2022 07:53:18 PM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Setup Pi-Hole as a Recursive DNS Server with Unbound</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>Installing and Configuring Unbound</h2>
  26. <ol>
  27. <li>Run the following commands in a terminal window:
  28. <div class="codeBlock"># install unbound<br />
  29. sudo apt install unbound<br />
  30. # update root hints file<br />
  31. wget https://www.internic.net/domain/named.root -qO- | sudo tee /var/lib/unbound/root.hints<br />
  32. # edit unbound configuration<br />
  33. sudo nano /etc/unbound/unbound.conf.d/pi-hole.conf</div>
  34. </li>
  35. <li>Paste the following configuration into pi-hole.conf
  36. <p>server:<br />
  37. &nbsp; &nbsp; # If no logfile is specified, syslog is used<br />
  38. &nbsp; &nbsp; # logfile: &quot;/var/log/unbound/unbound.log&quot;<br />
  39. &nbsp; &nbsp; verbosity: 0</p>
  40. <p>&nbsp; &nbsp; interface: 127.0.0.1<br />
  41. &nbsp; &nbsp; port: 5335<br />
  42. &nbsp; &nbsp; do-ip4: yes<br />
  43. &nbsp; &nbsp; do-udp: yes<br />
  44. &nbsp; &nbsp; do-tcp: yes</p>
  45. <p>&nbsp; &nbsp; # May be set to yes if you have IPv6 connectivity<br />
  46. &nbsp; &nbsp; do-ip6: no</p>
  47. <p>&nbsp; &nbsp; # You want to leave this to no unless you have *native* IPv6. With 6to4 and<br />
  48. &nbsp; &nbsp; # Terredo tunnels your web browser should favor IPv4 for the same reasons<br />
  49. &nbsp; &nbsp; prefer-ip6: no</p>
  50. <p>&nbsp; &nbsp; # Use this only when you downloaded the list of primary root servers!<br />
  51. &nbsp; &nbsp; # If you use the default dns-root-data package, unbound will find it automatically<br />
  52. &nbsp; &nbsp; #root-hints: &quot;/var/lib/unbound/root.hints&quot;</p>
  53. <p>&nbsp; &nbsp; # Trust glue only if it is within the server&#39;s authority<br />
  54. &nbsp; &nbsp; harden-glue: yes</p>
  55. <p>&nbsp; &nbsp; # Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS<br />
  56. &nbsp; &nbsp; harden-dnssec-stripped: yes</p>
  57. <p>&nbsp; &nbsp; # Don&#39;t use Capitalization randomization as it known to cause DNSSEC issues sometimes<br />
  58. &nbsp; &nbsp; # see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details<br />
  59. &nbsp; &nbsp; use-caps-for-id: no</p>
  60. <p>&nbsp; &nbsp; # Reduce EDNS reassembly buffer size.<br />
  61. &nbsp; &nbsp; # Suggested by the unbound man page to reduce fragmentation reassembly problems<br />
  62. &nbsp; &nbsp; edns-buffer-size: 1472</p>
  63. <p>&nbsp; &nbsp; # Perform prefetching of close to expired message cache entries<br />
  64. &nbsp; &nbsp; # This only applies to domains that have been frequently queried<br />
  65. &nbsp; &nbsp; prefetch: yes</p>
  66. <p>&nbsp; &nbsp; # One thread should be sufficient, can be increased on beefy machines. In reality for most users running on small networks or on a single machine, it should be unnecessary to seek performance enhancement by increasing num-threads above 1.<br />
  67. &nbsp; &nbsp; num-threads: 1</p>
  68. <p>&nbsp; &nbsp; # Ensure kernel buffer is large enough to not lose messages in traffic spikes<br />
  69. &nbsp; &nbsp; so-rcvbuf: 1m</p>
  70. <p>&nbsp; &nbsp; # Ensure privacy of local IP ranges<br />
  71. &nbsp; &nbsp; private-address: 192.168.0.0/16<br />
  72. &nbsp; &nbsp; private-address: 169.254.0.0/16<br />
  73. &nbsp; &nbsp; private-address: 172.16.0.0/12<br />
  74. &nbsp; &nbsp; private-address: 10.0.0.0/8<br />
  75. &nbsp; &nbsp; private-address: fd00::/8<br />
  76. &nbsp; &nbsp; private-address: fe80::/10</p>
  77. </li>
  78. <li>Press CTRL+O, Enter, CTRL+X to write the changes to pi-hole.conf</li>
  79. <li>Continue with the following commands in terminal
  80. <div class="codeBlock"># restart the unbound service<br />
  81. sudo service unbound restart<br />
  82. # test a DNS lookup via unbound<br />
  83. dig github.io @127.0.0.1 -p 5335</div>
  84. </li>
  85. <li>Back in the web browser, navigate back to the Pi-Hole web interface</li>
  86. <li>Log in if you are not already</li>
  87. <li>Select Settings &gt; DNS</li>
  88. <li>Uncheck any of the previously selected upstream DNS servers</li>
  89. <li>Check the box next to Custom 1 (IPv4)</li>
  90. <li>Enter 127.0.0.1#5335 as the address</li>
  91. <li>Scroll down and click the Save button</li>
  92. </ol>
  93. <h2>Testing the Changes</h2>
  94. <ol>
  95. <li>Open a new tab in the web browser and navigate to https://yahoo.com</li>
  96. <li>Go back into Pi-Hole and select Query Log from the left navigation</li>
  97. <li>Filter the results on www.yahoo.com</li>
  98. <li>You should see entries showing the DNS requests forwarding to localhost#5335</li>
  99. </ol> </div>
  100. </div>
  101. </body>
  102. </html>