I use MikroTik + RouterOS to implement an hospot platform with the radius remote authentication system.
I’m looking for a way to display a dafault page when device is disconnected from the www (so the service isn’t available).
This thing is freaking me out, i tried a lot of different solution without luck because when disconnected RouterOS just doesn’t translate addresses and client see the default browser dns error.
I’m looking for a way to redirect users to an internal mikrotik webpage when device is disconnected or the classic login.html when device is connected to the internet.
Is it possible? Please help me.
(Sorry for bad english)
Thank you in advance.
Lorenzo (the spaghetti eater).
set up hotspot, but replace the login page with some error page, or whatever you want
disable all the hotspot setup
make a netwatch script that pings some external IP, and when ping fails, enables all hotspot settings, so users get redirected to the login page with your message
Ok, i tried your solution but i made some mistake.
If the device is connected to the internet the hotspot-> login page is shown correctly and when i phisically disconnected router from the internet the hotspot → login page is not shown (instead the default browser dns error is shown).
It seems like the hotspot service isn’t called at all when the router is not connected to the internet. Is it a dns problem?
My test was:
Create new hotspot service with hotspot setup and configuring it
Replace the login.html code with an error message
Disconnect the routerboard from the internet
Try to connect the service (like an user should do)
→ Result: I can only see the browser dns default error page
Another test was:
5. Reconnect the routerbord to the internet
6. Try to connect the service (like an user should do)
→ Result: I can see the login.html with my error page correctly
So my problem isn’t the hotspot switch script or system but find a way to show an internal page when the device is diconnected from the internet.
Thank you a lot for the help
Lorenzo (the spaghetti eater)
So i think the captive portal system is called only if the dns resolution has success else the dns error default browser page is shown.
Well, yes. Of course. That’s due to how TCP/IP works. For a client to load a web page in a browser it first has to resolve DNS, otherwise it can’t connect to the destination’s IP address. DNS is just a translation layer for names to IPs, it has nothing to do with IP connections actually carrying HTTP.
/ip dns
set allow-remote-requests=yes
/ip dns static
add address=1.1.1.1 disabled=no name=.* ttl=1m comment="catchall"
Note that it’s .*, and not *. as you had. . is not a valid regular expression. * means zero or more, . means any character. So . means one or more characters, any of them. That works. *. is nonsensical.
Of course you’ll also have to make sure the router is used for DNS resolution:
And then include something like this in your script to enable/disable that catchall DNS entry as it must only be active when there’s a problem condition:
/ip dns static { disable [find comment="catchall"] };
/ip dns static { enable [find comment="catchall"] };