{"id":188,"date":"2023-09-12T16:28:10","date_gmt":"2023-09-12T19:28:10","guid":{"rendered":"https:\/\/vargolino.com\/wp\/?p=188"},"modified":"2023-09-12T16:28:10","modified_gmt":"2023-09-12T19:28:10","slug":"how-to-override-dns-for-private-networks-with-bind-rpz","status":"publish","type":"post","link":"https:\/\/vargolino.com\/wp\/?p=188","title":{"rendered":"How to override DNS for private networks with BIND RPZ"},"content":{"rendered":"\n<p>In our private network we have services that are served to the internet and should also be used by the users sitting inside the network (physically or via VPN). We have a main DNS servers in a cloud provider and it is serving service.example.com pointing to our firewall internet facing address and an internal DNS server with all the same records duplicated except service.example.com that is pointing to its address reachable in the private network.<\/p>\n\n\n\n<p>This arrangement causes some maintenance trouble because every time we add a new domain to the main DNS, we need to duplicate this entry in the internal server.<\/p>\n\n\n\n<p>Some time ago I looked up how to solve this a little more elegantly and found out about response-policy-zone feature in BIND. With this set up we can have our internal server configured to only have entries for the domains that need to have different responses in our private network without the need to duplicate all other entries.<\/p>\n\n\n\n<p>Step-by-step<\/p>\n\n\n\n<p>Configure a response-policy in the options:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>options {\n  &#91;...]\n  response-policy { zone \"rpz\"; };\n}<\/code><\/pre>\n\n\n\n<p>Create the zone you referenced in the response-policy (<code>\"rpz\"<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zone \"rpz\" {\n  type master;\n  file \"rpz.db\";\n};<\/code><\/pre>\n\n\n\n<p>Then populate the zone file referenced (<code>\"rpz.db\"<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$TTL 300\n@    IN SOA localhost. root.localhost. (\n          2023091201  ; serial\n          86400       ; refresh, seconds\n          7200        ; retry, seconds\n          3600000     ; expire, seconds\n          86400       ; minimum, seconds\n)\n\n@        IN NS dns.google.\n\n; you need the full domain here, without ending with a period\nproduction.example.com   IN A 192.168.0.10\ndev.example.com          IN A 192.168.0.10\n\nbad.ads.example.com      IN A 127.0.0.1\nevil.domain.example.com  IN A 127.0.0.1<\/code><\/pre>\n\n\n\n<p>reload the configs and you should be good to go.<\/p>\n\n\n\n<p>References:<br><a href=\"https:\/\/www.redpill-linpro.com\/sysadvent\/2015\/12\/08\/dns-rpz.html\">https:\/\/www.redpill-linpro.com\/sysadvent\/2015\/12\/08\/dns-rpz.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/dnsrpz.info\/\">https:\/\/dnsrpz.info\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our private network we have services that are served to the internet and should also be used by the users sitting inside the network (physically or via VPN). We have a main DNS servers in a cloud provider and it is serving service.example.com pointing to our firewall internet facing address and an internal DNS &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/vargolino.com\/wp\/?p=188\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to override DNS for private networks with BIND RPZ&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[26,7],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-solution","tag-dns","tag-howto","entry"],"_links":{"self":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=188"}],"version-history":[{"count":2,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}