Tuesday, November 27, 2012

Serving a custom catch-all web page on a private WiFi

Sometimes you would like to publish a specific private web page for your WiFi users. For example, you want to allow the guests in your restaurant to access the on-line version of your menu while using your open WiFi hotspot (and no other internet web page!). It is an easy task with an OpenWRT or DD-WRT router (your web pages still need to be served from a server, not the router itself). This might be known with the keywords catch-all, wildcard, HTTP, DNS.

First we need to make sure we catch all DNS requests and return the IP of our web server for all different domains. The trick is in an additional DNSMasq configuration option (192.168.1.5 is your web server):
address=/#/192.168.1.5
Of course, your DHCP server should give only your DNS as the DNS server to the client. And this is all we need if the router is not connected to internet as any other hacking (e.g. entering a custom DNS server on the client or trying to use a VPN) will have no effect. But you may still enable the HTTP redirect in DD-WRT firmware just to be sure to catch the IP only web requests also.

When all domains are redirected to our IP address we need to instruct the web server to serve the same page for all requests (ignoring the Host header) which is pretty easy and the most common default configuration. But for visual effect you can server your page on myrestaurant.com (it doesn't matter if the domain exists or not as long as you use it only inside your internal network) and force a http redirect to it if a guest is trying to access any other domain (e.g. facebook.com or google.com). A hint for Apache users (others should google for "http redirect 301" and your web server name):
Redirect 301 / http://www.newdomain.com/

Of course it is highly recommended not to use this wireless network for anything else as it will look bogus from users perspective (web pages not loading etc.). Use a firewall or do not connect the router to internet at all.

Resources for DNSMasq configuration:

http://serverfault.com/questions/351108/using-dnsmasq-to-resolve-all-hosts-to-the-same-address
http://www.dd-wrt.com/wiki/index.php/DNSMasq_-_DNS_for_your_local_network_-_HOWTO
http://coolaj86.info/articles/redirect-domains-and-dns-using-dd-wrt.html

WARNING: this guide is not yet tested but in theory it should work. This warning will be removed when I actually test it (or get a confirmation that it works).