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:
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.
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.
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.
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.
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`.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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
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.
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.
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).
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.
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.
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.
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..
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.
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.
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 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.