I currently have a Raspberry Pi 3 equipped with a SenseHat running Raspbian. I Have made a website to control the SenseHat by running programs that use the SenseHat. My server is nothing fancy:). I needed a way to demonstrate my Raspberry Pi SenseHat website so I have my RPi configured as a wireless access point. I feel the next part is to make a captive portal so that I don't have to tell people to punch a long IP address into their phones when they want to control the SenseHat. Their are tutorials to do this but it doesn't seem to work captive portal to Their are tutorials to show me how to do this with lighttpd, I could do this but then I would have a Splash page with a link to my SenseHat Library Homepage and from that page their would be a link to the actual page you can run the SenseHat from(Seems a long ways around when you could go straight to the SenseHat Library HomePage!). I am sure their is a way to do this can anyone help?

  • So is your end goal to redirect all users to a captive pages to have them agree to some sort of terms and services? – Mohammad Ali Jun 21 '16 at 4:15
  • No I want to bring them to a Home Page for my SenseHat Library Programs. – RPImaniac Jun 21 '16 at 4:22

I recommend doing this with a small set of iptables rules redirecting all traffic to port 80 and 443 to your home page.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination localhost:80
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination localhost:80

An example with the ip's that you have provided being:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination

Additionally you should have your HTTP server configured to redirect every unknown URL to its start page. So that if a user enters http://www.awesomepeople.com/Mohammad-Ali you don't get a 404 from your sense hat web server. This would in essence redirect them to

What the IP tables rules above are doing in essence is redirecting all traffic to your web server which in this case is your sense hat page, so if I where connected to your network and entered in any domain at all, i would be redirected to your page.

| improve this answer | |
  • would there be some way to do this with the dnsmasq configuration? – RPImaniac Jun 21 '16 at 4:52
  • @RPImaniac probably, but the problem with using the dns is caching, odds are that a lot of people will have their website dns cached which means that it won't hit your dns but instead would have the IP in memory. – Mohammad Ali Jun 21 '16 at 4:54
  • 1
    If this doesn't work as it, check with sudo iptables -t nat -L --line-numbers -n to see if where it has ended up in relation to any rules related to the access point; you may have to work them into that or use -I appropriately. (It should be fine IMO, since I don't think an AP should require any other PREROUTING rules, but the question doesn't get into details about how it was done...). Note also this means all web traffic via the AP, regardless of intended domain, will end up coming to the pi's server instead. Of course, that is what a "captive portal" does. – goldilocks Jun 21 '16 at 13:56
  • 1
    @RPImaniac part 1 the http server part isn't about how you configured your server. It is about how you want people to be redirected. Here let me give you a hypothetical example. Imagine I connected to your access point, then I entered Google.com or any other domain into my web browser. Now instead of taking me to google I would be redirected to your site which is located at But now instead imagine that I entered google.com/Mohammad-is-my-hero Instead of being able to see how I am a hero I would instead by shown – Mohammad Ali Jun 22 '16 at 4:04
  • 1
    @RPImaniac part 2 which would in turn depending on how your server is configured display a 404 page which may cause confusion amongst users – Mohammad Ali Jun 22 '16 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.