Redirect to page when connection to net is disconnected

Hi all !
An idea arose, maybe a little crazy, but still.

Periodically, somewhere along the line there are communication breakdowns, mainly due to a power outage somewhere on the line and, of course, the Internet does not work.
Users start unplugging the router, then call me :slight_smile:
Question: is it possible to do something so that when the Internet goes out, the user is redirected in the browser to a page on which it will be written - don’t worry, the Internet will appear soon :slight_smile:

I'll take a stab, what could go wrong?

You could add an internal DNS address that resolves all requests to an in house URL.
Internet goes down, dns fails except the last one which resolves all requests to a local HTML page.

2 Likes

If a specific site is down, but "the rest of the Internet" works, then the "Internet is down" web page would be inaccurate, no? :thinking:

Granted, you also get this symptom with "the standard way" every system checks for Internet connectivity (that is, attempt to connect to a specific server). Speaking of which, I wonder how any such solution would interact with such built-in "connectivity checker" functions.

1 Like

You would get a 404 because the DNS was resolved to an outside page but nothing was fetched.

How approximately to do this? I have a lot of ideas, but not enough knowledge

I do not code. I used to do html.

So you just need to figure out how to forward all requests, that end up resolved locally, to one url.
IOW:
Make a DNS server.

Thanks for the tip, I’m completely new to this, but I’ll try to figure it out

I'm going to attempt to sketch a possible implementation of @LilRedDog's solution. I have not actually tried this.

  1. Run another dnsmasq instance listening on localhost only and on a different port, say port 5353. Call this the "failover DNS".

  2. Configure the failover DNS to return the OpenWrt device IP for all queries. According to the dnsmasq man page, you can use something like --address=/#/192.168.1.1 to achieve this effect.

  3. Configure the main DNS to use the failover DNS when upstream DNS aren't available. My initial reading of the man page suggests using --strict-order in combination with multiple --server directives. Apparently you need to specify the servers in reverse order, so the highest-priority servers go last in the list. This would mean the failover DNS directive like --server=192.168.1.1#5353 goes first.

  4. Modify or replace the LuCI front page to show your desired message.

2 Likes

Remember:

DNS resolves words to numbers. So, if the DNS address was a webpage with an ip address, it might show the page you want to write.

Better thought out than my last post.

there's a 404 page setting in uhttpd - https://openwrt.org/docs/guide-user/services/webserver/uhttpd

since most/all URLs the clients will try to fetch will be 404s on OpenWRT's webserver, you could replace the 404 page with an "internet is down" page.

2 Likes

I couldn’t enable something, it only works if I enter the router address, for example 192.168.1.1/654564564
in all other cases does not want to work

You mean if google.com/blah resolves to the IP of the router, it doesn't throw the 404 page ?

I did this

uci set uhttpd.main.error_page='/404.html'
uci set uhttpd.main.error_handler='/404.html'
uci commit uhttpd
/etc/init.d/uhttpd restart

created an empty file
touch /404.html

inserted text
echo "text" > /404.html

and doesn't work

Very much doubt this is correct.

text is inserted
and redirects only if you enter the router address, for example 192.168.1.1/fhgjg
text visible
but if you enter the wrong domain into the browser address, it doesn’t redirect, maybe I’m doing something differently than usual, but beyond these steps I’m at a dead end :slight_smile:

Still need to do step 2 from @elbertmai's post.