Mikrotik Hotspot Script To Show Maintenance Page If Internet Is Down

Display Maintenance Page In A Mikrotik Hotspot Captive Portal When ISP Is Offline.

Script and tutorial to show a Maintenance page when there is no link in Hotspot splash page.

Script For Mikrotik Hotspot.

Add the following Script to specified location in Mikrotik RouterOS to show maintenance page in Hotspot when internet is down.

Netwatch Up Code

Netwatch Down Code

Script For Mikrotik RouterOS Hotspot when Internet is Down.

  • Add this code to Tools > Netwatch > Up script.

{\
/ip dns static disable [/ip dns static find where comment~"MAINTENANCE"];\
/ip dns static enable [/ip dns static find where comment~"CORRECTION"];\
/ip dns cache flush ;\
/ip hotspot profile set [/ip hotspot profile find where html-directory~"flash/maintenancePage"] html-directory="flash/hotspot";\
/ip hotspot profile set [/ip hotspot profile find where html-directory~"flash/hotspot"] dns-name="www.YOUR ACTUAL PROFILE NAME HERE";\
/ip hotspot profile set [/ip hotspot profile find where html-directory~"flash/hotspot"] dns-name="YOUR ACTUAL PROFILE NAME HERE";\
 :log warning "Internet up, showing normal hotspot page"
;}
  • And this to Tools > Netwatch > Down script.
{\
/ip dns static remove [/ip dns static find where name~"HOTSPOT FQDN"];\
/ip dns cache flush ;\
/ip dns static disable [/ip dns static find where comment~"CORRECTION"];\
/ip dns static enable [/ip dns static find where comment~"MAINTENANCE"];\
/ip hotspot profile set [/ip hotspot profile find where html-directory~"flash/hotspot"] html-directory="flash/maintenancePage";\
/ip hotspot active remove [/ip hotspot active find];\
/ip hotspot cookie remove [find];\
/ip dhcp lease remove [find server="YOUR DHCP SERVER NAME"];\
 :log warning "Internet down, showing maintenance page"
;}

Add the following entries with corresponding comments in IP > DNS > Static using REGEX. Do Note that you need to replace 10.0.0.1 with IP of your HOTSPOT Address as shown in IP > Hotspot > Server Profiles.

Since Mikrotik DNS by default gives priority to Static Entries over Dynamic ones, which basically causes issues because when ISP is down as DNS redirects only to Hotspot Server IP which causes all pages to not redirect when Internet is down. This approach forwards all queries to a non working IP and still maintains access to Hotspot IP.

The script also changes the default folder for HTML page when internet goes down to “flash/maintenancePage” so that it is able to show different content when intenet is down. Consequently do remember to populate “flash/maintenancePage” with necessary page (or changes with same content) to make sure that it does not show the usual page. On the other hand it forces existing user to log in again too. You can instead show a banner stating “Internet is Down, we are working on it.”.

Now when your internet goes down, the down script will take effect and firstly change the Hotspot default HTML folder. Then it will change DNS entries so that all DNS requests are forwarded to non working IP but that is then captured and the Splash page is displayed.

Mikrotik captive portal when internet is down
Mikrotik captive portal when internet is down

That is it. In case of any query do not hesitate to use to the comment form below.

Buy.Guru


Similar Implementation Shown On Mikrotik Forums.

Buy Latest Mikrotik Routers On Amazon

This Post Has One Comment

  1. explanation thodienlanh24h

    I would like to thnkx for the efforts you have put in writing this blog.
    I am hoping the same high-grade site post from you in the upcoming as well.
    In fact your creative writing skills has inspired me to get my own website now.

    Really the blogging is spreading its wings rapidly.
    Your write up is a great example of it.

Leave a Reply