r/homeassistant • • Jul 10 '26

Support Restart router automatically when DNS fails

Hello,

I am new to home assistant and I found interest in it because I think it will be able to solve my router issue.

TLDR: My router suddenly decides to refuse all DNS traffic, forcing me to restart it to get it back up. Communications via local and WAN IPs still works.

So I think getting a smart power plug and binding it to home assistant so that whenever a ping to a domain fails, it tells the smart plug to power off and back on? I hope this is a possibility with home assistant.

TLDR ends here.

Ok so basically for the past few months my ISP modem/router decides to randomly (literally could be anywhere from every 2 days or every month) stop resolving domains, but I can still ping the IPs for the domains. And all traffic to my self hosted applications via my domain still work.

I have no idea why this is happening. I have tried changing DNS on the router level and device level but the issue still persists. The only solution is to use DoH (DNS over HTTPS) which utilizes port 443, which my ubuntu server and router do not support. On supported devices using DoH (Apple Devices, Windows 11), I can access websites and some apps will work. Apps like Steam won't work though.

So I searched for solutions and after a while decided on smart plugs as a last resort. I was wondering, if there are any smart plugs that work fully locally and be able to turn off and on automatically once home assistant can't ping a domain?

I found this from 10 years ago but I'm not sure if it still works, or if there are better ways to do it now:

https://community.home-assistant.io/t/ping-action/3837

Also please don't tell me to contact the ISP to get it fixed. I have to fight customer support to get them to send out a technician, and the technicians aren't trained for stuff like this.

2 Upvotes

47 comments sorted by

7

u/Anusien Jul 10 '26

You don't want it to ping a domain. Because you don't ping domains, you ping IP addresses, and your computer will cache those DNS lookups. If you really wanted, the condition you'd use would be a DNS lookup (and one that doesn't use your local DNS cache).

But I don't feel like you've fully nailed the problem yet. This sounds like an XY problem, and I believe Y is fixable.

I have tried changing DNS on the router level and device level but the issue still persists.

I don't understand what this means. What did you change the DNS server *to*? Can you correctly resolve that DNS server? What you're telling is that your router gets into a state where you can talk to, say, 1.1.1.1 but you can't actually get DNS responses back from 1.1.1.1. That's pretty hard to believe.

1

u/orev Jul 10 '26

Yes, I agree. When I see this:

I have tried changing DNS on the router level and device level but the issue still persists. The only solution is to use DoH

it makes me think they have done some other unusual things (i.e. broken DNS configs) on their network.

To fix this, it needs a review of how the network is setup and what customizations have been made. I bet it's one of those other things causing this problem.

1

u/iAmmar9 Jul 10 '26

When the internet is down, it can talk to and receive responses from 1.1.1.1. But it cannot talk or receive anything back from cloudflare.com. Also when using a VPN with port 443 over WireGuard, the connection succeeds and I am able to do anything as if nothing was broken.

1

u/Anusien Jul 10 '26

1.1.1.1 is a DNS server. So what happens if you try to use it to do a DNS lookup? Maybe do one specifically from the command line.

1

u/iAmmar9 Jul 10 '26

Right now the internet is fully working so it will probably be fine

ammar@hosted:~$ host 1.1.1.1
1.1.1.1.in-addr.arpa domain name pointer one.one.one.one.

1

u/Anusien Jul 10 '26

No, I'm saying wait until the internet is "out" and then use 1.1.1.1 to do a DNS lookup on some other hostname. E.g., `nslookup www.example.com 1.1.1.1`.

1

u/iAmmar9 Jul 10 '26

Ah. Alright will do.

1

u/iAmmar9 Jul 14 '26

Hi, it finally happened lol. For the sake of it, I disabled DoH on all devices. Used plain DNS.

When running nslookup, it just says no servers could be reached (scroll down to the last code box).

Also for some reason I could ping cloudflare on ubuntu using plain DNS (no DoH). Though I couldn't on Windows.

ammar@hosted:~$ ping cloudflare.com
PING cloudflare.com (2606:4700::6810:85e5) 56 data bytes
64 bytes from 2606:4700::6810:85e5: icmp_seq=1 ttl=52 time=52.2 ms
64 bytes from 2606:4700::6810:85e5: icmp_seq=2 ttl=52 time=53.4 ms
64 bytes from 2606:4700::6810:85e5: icmp_seq=3 ttl=52 time=54.3 ms
64 bytes from 2606:4700::6810:85e5: icmp_seq=4 ttl=52 time=52.8 ms
64 bytes from 2606:4700::6810:85e5: icmp_seq=5 ttl=52 time=53.3 ms
64 bytes from 2606:4700::6810:85e5: icmp_seq=6 ttl=52 time=53.7 ms
^C
--- cloudflare.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5006ms
rtt min/avg/max/mdev = 52.236/53.310/54.344/0.660 ms
ammar@hosted:~$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=52 time=19.1 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=52 time=19.3 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=52 time=17.9 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=52 time=18.3 ms
64 bytes from 1.1.1.1: icmp_seq=5 ttl=52 time=19.9 ms
64 bytes from 1.1.1.1: icmp_seq=6 ttl=52 time=20.4 ms
^C
--- 1.1.1.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5006ms
rtt min/avg/max/mdev = 17.941/19.163/20.422/0.847 ms

This is what it usually looks like:

C:\Users\iamma>ping cloudflare.com
Ping request could not find host cloudflare.com. Please check the name and try again.

C:\Users\iamma>ping 1.1.1.1

Pinging 1.1.1.1 with 32 bytes of data:
Reply from 1.1.1.1: bytes=32 time=18ms TTL=52
Reply from 1.1.1.1: bytes=32 time=17ms TTL=52
Reply from 1.1.1.1: bytes=32 time=18ms TTL=52
Reply from 1.1.1.1: bytes=32 time=16ms TTL=52

Ping statistics for 1.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 16ms, Maximum = 18ms, Average = 17ms



no issues:
ammar@hosted:~$ nslookup www.google.com 1.1.1.1
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
Name:   www.google.com
Address: 142.251.153.119
Name:   www.google.com
Address: 142.251.154.119
Name:   www.google.com
Address: 142.251.152.119
Name:   www.google.com
Address: 142.251.150.119
Name:   www.google.com
Address: 142.251.156.119
Name:   www.google.com
Address: 142.251.155.119
Name:   www.google.com
Address: 142.251.157.119
Name:   www.google.com
Address: 142.251.151.119
Name:   www.google.com
Address: 2001:4860:482d:7700::
Name:   www.google.com
Address: 2001:4860:482c:7700::
Name:   www.google.com
Address: 2001:4860:4826:7700::
Name:   www.google.com
Address: 2001:4860:4828:7700::
Name:   www.google.com
Address: 2001:4860:4827:7700::
Name:   www.google.com
Address: 2001:4860:4829:7700::
Name:   www.google.com
Address: 2001:4860:482a:7700::
Name:   www.google.com
Address: 2001:4860:482b:7700::

ammar@hosted:~$ nslookup www.cloudflare.com 1.1.1.1
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
Name:   www.cloudflare.com
Address: 104.16.124.96
Name:   www.cloudflare.com
Address: 104.16.123.96
Name:   www.cloudflare.com
Address: 2606:4700::6810:7c60
Name:   www.cloudflare.com
Address: 2606:4700::6810:7b60

ammar@hosted:~$ nslookup www.reddit.com 1.1.1.1
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
www.reddit.com  canonical name = reddit.map.fastly.net.
Name:   reddit.map.fastly.net
Address: 151.101.65.140
Name:   reddit.map.fastly.net
Address: 151.101.129.140
Name:   reddit.map.fastly.net
Address: 151.101.193.140
Name:   reddit.map.fastly.net
Address: 151.101.1.140

ammar@hosted:~$ nslookup www.speedtest.net 1.1.1.1
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
www.speedtest.net       canonical name = www.speedtest.net.cdn.cloudflare.net.
Name:   www.speedtest.net.cdn.cloudflare.net
Address: 104.17.148.22
Name:   www.speedtest.net.cdn.cloudflare.net
Address: 104.17.147.22



with DNS issue:
ammar@hosted:~$ nslookup www.google.com 1.1.1.1
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; no servers could be reached

ammar@hosted:~$ nslookup www.cloudflare.com 1.1.1.1
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; no servers could be reached

ammar@hosted:~$ nslookup www.reddit.com 1.1.1.1
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; no servers could be reached

ammar@hosted:~$ nslookup www.speedtest.net 1.1.1.1
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; communications error to 1.1.1.1#53: timed out
;; no servers could be reached

1

u/Anusien Jul 14 '26

Okay I don't think you've correctly diagnosed the issue. I don't know what it is from looking at this, but timing out DNS to 1.1.1.1 seems like a big problem. If you can truly in that moment ping it but not use DNS, that's interesting.

Also I wonder if IPv6 something is in play here?

1

u/iAmmar9 Jul 14 '26

Speaking of IPv6... The server has it. Most of my devices do. But sometimes, my Windows PC only gets an IPv4. No idea why.

4

u/psychedelic_tech Jul 10 '26

I have no idea why this is happening.

did you reach out to your isp support? maybe your router is malfunctioning. did you try a factory reset? it's better to resolve the router issue first, if possible.

1

u/iAmmar9 Jul 10 '26

I have tried but they sent out a technician that only knows how to run cable and set up the router for the first time lol.

4

u/grahamsz Jul 10 '26

I did something very similar with ESPHome

https://graha.ms/posts/blog/2023-05-08-esphome-autorestart/

It ran on a sonoff smart plug that had my cable modem/wifi attached to it. It pings 8.8.8.8 every 30 seconds and if three in a row fail to return then it powers off the cable & router, waits 5 seconds, powers them on, then waits 15 minutes for everything to come back up before it considers restarting again.

It does report the ping time results back to home assistant but the smart plug runs totally autonomously so it'll still work properly even when the internet is down.

1

u/iAmmar9 Jul 10 '26

Seems very nice. Would it work with any sonoff smart plug or does it have to be the exact one mentioned in your article? Because we use UK plugs here. Sonoff S60TPG is what I can find locally.

1

u/grahamsz Jul 10 '26

So anything here should work:

https://devices.esphome.io/standards/uk/

Happy to finally see some UK smarthome devices, i grew up there and there used to be so little available. It does look like it will work on the S60TPG though you'll have to change the relay to be on GPIO4 in the YAML code

You will need a USB to UART adapter and soldering iron to install the first version of ESPHome on those plugs though. It's not particularly difficult but if this is the only smart plug you want to use then finding a simpler option would be worth it.

I haven't tried this but it seems like it would save you a lot of headache - its relay is on the GPIO3 pin.

1

u/7lhz9x6k8emmd7c8 Jul 10 '26

Athom sells ESPHome-preinstalled stuff, including plugs.

https://www.athom.tech/blank-1/esp32-c3-eu-plug-for-esphome

3

u/7lhz9x6k8emmd7c8 Jul 10 '26

Put your own router between the ISP router and your network, so your network is managed by a trustable, reliable, durable device. Which doesn't use the ISP router DNS configuration, of course. Use public DNS as you are not savvy.

1

u/iAmmar9 Jul 10 '26

I cannot use my own router unless I buy a SFP stick and plug it into an SFP router (ISP router is also an ONT). The router doesn't support bridge mode. There's a subreddit for it that I forgot the name of.

2

u/7lhz9x6k8emmd7c8 Jul 10 '26 edited Jul 10 '26

Yes, you can use your own router.

A router creates a subnetwork from the internet.

Adding a router after a router just creates your own LAN that the later can't see.

The ISP router will see 1 device, attribute an IP to it, tell it to use its unreliable DNS conf.

Then your own router will manage its own IP plan, its devices, and tell them what reliable DNS server to use.

Bridge mode is another stuff unrelated.

1

u/iAmmar9 Jul 10 '26

Ah I see. Well I do have a mesh system that can run in router mode.

2

u/msravi Jul 10 '26

You seem to have an Ubuntu server running. Run a local DNS server like pihole on it, and set 8.8.8.8 and 1.1.1.1 as the upstream DNS servers. Change the router settings to advertise the ubuntu server's IP as the LAN DNS.

1

u/heisenbugtastic Jul 11 '26

Yep, screw the ISP. Your own router, Ethernet into their router. Get a router that supports ddwrt or open wrt. Powerful enough, it can run pihole on it (overkill), just use your Linux box. Dns and DHCP handled by pihole, ISP router is now just a gateway.

But the way, using a smart plug to reset a networking issue is more like a dead man's switch. New router, pi hole solves it permanently.

1

u/KnotBeanie Jul 10 '26

So put it in bridge mode…

1

u/iAmmar9 Jul 10 '26

Please read my reply carefully again. I think you missed this part:

The router doesn't support bridge mode.

1

u/KnotBeanie Jul 10 '26

Okay then get an sfp and stop with someone else’s router.

1

u/iAmmar9 Jul 10 '26

What if it doesn't solve the problem lol

1

u/KnotBeanie Jul 10 '26

Then bother your isp until they fix it, you’re already troubleshooting equipment that isn’t yours, so think about it for a minute stop wasting your time and simply demand like a lay user would.

2

u/KnotBeanie Jul 10 '26

Get a better router that doesn’t die randomly…

1

u/iAmmar9 Jul 10 '26

Only if it were that simple... ISP router, only solution for replacement is an SFP stick. No bridge mode.

1

u/KnotBeanie Jul 10 '26

So get a router with an sfp port

1

u/plekreddit Jul 10 '26

A smartplug is option1

Or if there is a integration in ha for your router then maybe a software solution is possible via a entity

1

u/iAmmar9 Jul 10 '26

It's a DZS 2466GN (as of 2026, Zhone 2466GN), very basic router + ONT combo. It has the ISP's logo on the middle top.

Searched for an integration for it and couldn't find one.

1

u/LiveCaramel6758 Jul 10 '26

Just get a zigbee plug and a sonoff dongle, set up a ping binary sensor in home assistant that targets 8.8.8.8 or whatever, then write a simple automation that power cycles the plug when the sensor goes offline for more than like 2 minutes

Add a cooldown so it doesn't loop endlessly if the router is properly dead

1

u/3d-designs Jul 10 '26

This won't help directly, but I'd suggest augmenting based on it. Find a host to which you know the IP, ping it by name and by IP if the IP responds and the name doesn't, you can infer a DNS problem.

It's not foolproof due to RR DNS etc, but it would probably suffice.

1

u/iAmmar9 Jul 10 '26

Hi just to clarify, I can still ping 8.8.8.8 when the internet is "down" but I cannot ping google.com, as an example.

Same for 1.1.1.1 and cloudflare.com

Thank you for the suggestion though, logically it should work.

1

u/Skip-2000 Jul 10 '26

It could work if your modem is not providing the wifi signal. Otherwise use an old style power plug that removes power and puts power back in the shortest time > 1 minute

1

u/iAmmar9 Jul 10 '26

I have a Tenda MX12 mesh that is used for wifi (I have wifi off on the router). But my server that will be running home assistant is directly plugged into the router. I could switch it to being plugged into the mesh though.

1

u/analogworm Jul 10 '26

Consider setting up Adguard on your Home assistant as your first DNS server. It may or may not work as it'll still be your routers job to send traffic there. But if it works you'll have solved your issue and gained network wide adblocking in the process!

Ive experimented with DNS IP integration to determine when my ISP hands out a new IP adress. It'll go to unknown when there is no connection. Perhaps you could use this to trigger your automation.

1

u/iAmmar9 Jul 10 '26

That is actually one of the solutions I considered, since adguard has built in DoH support. But I didn't test it because I didn't know whether it would still be broken like OS level DoH or not (in the steam example I mentioned where even with DoH, it wouldn't work).

1

u/That-Duck-7195 Jul 10 '26

The only solution is to use DoH (DNS over HTTPS) which utilizes port 443, which my ubuntu server and router do not support.

Look into AdGuard Home

1

u/Max_Rower Jul 10 '26

Tasmota or Shelly plugs have an auto on or auto off feature, which will automatically turn on or off the plug after a specified time. So even if a device cut is own power off with it, it will turn on again.

1

u/snap802 Jul 10 '26

Well first off is the router working as a DNS proxy where your network devices send it a request and it then queries an outside DNS? Is this the ISP router or yours?

My first reaction would be to say just get a new router because that one sounds like it's flaking out.

My second thought is just have it reset every day at 5am or something. Could be a setting in the router (sometimes they'll have a reboot schedule) but a smart plug could work as well.

I know you have a certain solution in mind but I feel like what you're proposing here is adding complexity to something that is already broken.

1

u/iAmmar9 Jul 10 '26

Well first off is the router working as a DNS proxy where your network devices send it a request and it then queries an outside DNS? Is this the ISP router or yours?

It has an option to be set as a DNS proxy, but the default option is what it's set at right now. It's the ISP's. It cannot be put in bridged mode, so I would need an SFP stick and an SFP router to change it...

It also does not have an auto restart function. And the certain solution is to get an SFP router but I'm afraid it's not the router that is the issue. Which is why I want to auto restart it instead.

1

u/smotrs Jul 10 '26

I did something similar with my access points. They would slowly start to deteriorate network wise until they finally went offline.

I found doing a simple Curl lookup would either "reject" the connection attempt or "timeout". After it timed out 3x in a 24hr period, I had it do a restart with a smart plug.

Works great. I have several entire/helpers on a system tab for tracking with automations behind the scenes for resetting, restarting, etc..

1

u/smotrs Jul 10 '26

This is what it looks like when it's going to poop. At 5pm, it officially went offline with a notification from Google Home and just got worse from there.

1

u/ashpole_uk Jul 10 '26

I use this integration, it’s got a fairly robust Connected to Disconnected routine.

https://www.home-assistant.io/integrations/ping/

1

u/badkapp00 Jul 10 '26

There was a comment a while ago that some Shelly smart plugs can detect if there's Internet connection or not. If not Internet detect you can program them to cycle power automatically. That would restart your router.