{"id":179,"date":"2021-10-25T18:57:35","date_gmt":"2021-10-25T16:57:35","guid":{"rendered":"http:\/\/cln.io\/blog\/?p=179"},"modified":"2022-12-01T00:58:46","modified_gmt":"2022-11-30T22:58:46","slug":"rebooting-adguard-pihole-dns-container-when-dns-is-unresponsive","status":"publish","type":"post","link":"https:\/\/cln.io\/blog\/rebooting-adguard-pihole-dns-container-when-dns-is-unresponsive\/","title":{"rendered":"Restart AdGuard \/ pi-hole (a DNS container) when DNS stops responding with home assistant"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">At times for an unknown reason, my AdGuard docker instance running on home assistant operating system stops responding, it ignores all queries sent to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have to manually restart the container, and with home assistant being an automation platform, it made me want to automate this task too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whilst I should really be fixing the issue itself (something to do with QUICK) and this being &#8220;not really the way to do things&#8221; sometimes necessity goes above anything else.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On this page<\/p>\n\n\n\n<nav aria-label=\"Table of Contents\" class=\"wp-block-table-of-contents\"><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/rebooting-adguard-pihole-dns-container-when-dns-is-unresponsive\/#setting-up-a-dns-sensor\">Setting up a DNS sensor<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/rebooting-adguard-pihole-dns-container-when-dns-is-unresponsive\/#the-sensor-values\">The sensor values<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/rebooting-adguard-pihole-dns-container-when-dns-is-unresponsive\/#setting-up-the-automation-to-reboot-the-dns-if-resolving-goes-down\">Setting up the automation to reboot the DNS if resolving goes down.<\/a><\/li><\/ol><\/nav>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-up-a-dns-sensor\">Setting up a DNS sensor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The first thing we want to do is to setup a DNS sensor, this can be done with the <a href=\"https:\/\/www.home-assistant.io\/integrations\/dnsip\/\" target=\"_blank\" rel=\"noreferrer noopener\">dnsip<\/a> sensor integration<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sensor:\n  - platform: dnsip\n    scan_interval: 60\n    hostname: one.one.one.one\n    name: one_one_one_one\n    resolver: 192.168.1.4<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default it refreshes the DNS resolve results every 120 seconds, that would be a bit long if DNS goes down so I reduced my sensor to 60 seconds.<br>You can take a public domain, but I advise to use a custom domain setup in your DNS resolver to always reply the same IP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Eg:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dns-resolving-is-alive.com -&gt; 0.0.0.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reason you want a local resolved address is because:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you take a public domain and your internet &#8220;dies&#8221; it will reboot the instance (unneeded)<\/li>\n\n\n\n<li>If you take a public domain and your upstream goes down it will reboot the instance (a reboot won&#8217;t fix this)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This is only in my case, if you resolve locally (unbound, etc&#8230;), you might want to use a public domain like:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  - platform: dnsip\n    scan_interval: 60\n    hostname: dns-resolving-is-alive.com\n    name: dns_resolving_is_alive\n    resolver: 192.168.1.4 <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Else, set up a custom domain, as such: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-1024x559.png\" alt=\"\" class=\"wp-image-180\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-1024x559.png 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-300x164.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-768x419.png 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-1536x838.png 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/custom_resolve-2048x1118.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Setting up a custom reply on a domain (don&#8217;t pick something you actually browse to)<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-sensor-values\">The sensor values<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We don&#8217;t care what the dnsip is having as value, since for example with the one.one.one.one it will loadbalance over its two A records, what we care about is the &#8220;unknown&#8221; value which would indicate our dns is not resolving.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dig one.one.one.one\n\n;; ANSWER SECTION:\none.one.one.one.\t149\tIN\tA\t1.1.1.1\none.one.one.one.\t149\tIN\tA\t1.0.0.1<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Meaning every time we ask the round-robin load balancing will give us a different result as seen in the sensor history.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.54.12.png\" alt=\"\" class=\"wp-image-183\" width=\"375\" height=\"277\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.54.12.png 836w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.54.12-300x222.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.54.12-768x568.png 768w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><figcaption class=\"wp-element-caption\">the results of round-robin load balancing<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">When (in my case) DNS stops responding it becomes an unknown:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.56.01.png\" alt=\"\" class=\"wp-image-184\" width=\"389\" height=\"278\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.56.01.png 874w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.56.01-300x215.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.56.01-768x550.png 768w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><figcaption class=\"wp-element-caption\">DNS unresponsive.<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Or the more &#8220;safer&#8221; route and avoid rebooting the containers if internet is down or the upstream is to use the DNS rewritten result:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.58.02.png\" alt=\"\" class=\"wp-image-185\" width=\"398\" height=\"248\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.58.02.png 842w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.58.02-300x187.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-16.58.02-768x480.png 768w\" sizes=\"auto, (max-width: 398px) 100vw, 398px\" \/><figcaption class=\"wp-element-caption\">DNS is alive &amp; kicking (no outbound connections)<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">If you stop the container (to simulate DNS not responding) it will look like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.39.png\" alt=\"\" class=\"wp-image-186\" width=\"402\" height=\"280\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.39.png 914w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.39-300x209.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.39-768x536.png 768w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><figcaption class=\"wp-element-caption\">state is &#8216;unknown&#8217; (UI shows capital U, but state wise its lowercase)<\/figcaption><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.32.png\" alt=\"\" class=\"wp-image-187\" width=\"396\" height=\"46\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.32.png 756w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.01.32-300x35.png 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.13.43.png\" alt=\"\" class=\"wp-image-189\" width=\"384\" height=\"50\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.13.43.png 754w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.13.43-300x39.png 300w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-up-the-automation-to-reboot-the-dns-if-resolving-goes-down\">Setting up the automation to reboot the DNS if resolving goes down.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We don&#8217;t need a cooldown period on the automation, since we go from x.x.x.x to unknown.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since it will stay &#8220;unknown&#8221; until the resolver starts working again, thus only triggering at max 1 reboot<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"153\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-1024x153.png\" alt=\"\" class=\"wp-image-190\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-1024x153.png 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-300x45.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-768x115.png 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-1536x230.png 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.30.57-2048x307.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Make a new automation, everything default, add a trigger and action.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-1024x640.png\" alt=\"\" class=\"wp-image-193\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-1024x640.png 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-300x187.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-768x480.png 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-1536x960.png 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.50.26-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"429\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-1024x429.png\" alt=\"\" class=\"wp-image-192\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-1024x429.png 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-300x126.png 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-768x322.png 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-1536x644.png 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-25-at-17.45.24-2048x858.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">YAML export<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">- id: '1635167344810'\n  alias: If adguard stops responding, reboot it\n  description: ''\n  trigger:\n  - platform: state\n    entity_id: sensor.dns_resolving_is_alive\n    to: unknown\n  condition: []\n  action:\n  - service: hassio.addon_restart\n    data:\n      addon: a0d7b954_adguard\n  mode: single<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Thats it! your DNS container will be rebooted when it stops responding.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-1024x683.jpg\" alt=\"\" class=\"wp-image-1204\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-1024x683.jpg 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-300x200.jpg 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-768x512.jpg 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-1536x1024.jpg 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2022\/12\/colin-avery-InMS8UZ5Ki8-unsplash-2048x1365.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@shofukan?utm_source=unsplash&#038;utm_medium=referral&#038;utm_content=creditCopyText\">Colin Avery<\/a> on <a href=\"https:\/\/unsplash.com\/s\/photos\/steam-engine?utm_source=unsplash&#038;utm_medium=referral&#038;utm_content=creditCopyText\">Unsplash<\/a>\n  <\/figcaption><\/figure>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>At times for an unknown reason, my AdGuard docker instance running on home assistant operating system stops responding, it ignores all queries sent to it. I have to manually restart the container, and with home [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":196,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,35,4,26],"tags":[8,28,12],"class_list":["post-179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation","category-dns","category-homeassistant","category-it","tag-automation","tag-dns","tag-homeassistant"],"_links":{"self":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":12,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":1205,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/179\/revisions\/1205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/media\/196"}],"wp:attachment":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}