I'm working on a project where a Raspberry Pi creates its own access point running a Flask server, but will not have an internet connection. I set up the iptables so that when the user tries to connect to any website, they are instead redirected to a custom HTML portal from Flask.

This mostly works, but the issue I'm having is that mobile phones, when connected, will correctly recognize the access point as "Connected, no internet." It then appears that the mobile phone will fall back to using mobile data. So if the user tries to access www.google.com, it will actually connect to Google via the mobile data. If I disable mobile data on the phone, accessing www.google.com will redirect to the Flask webpage as intended.

Since this device will not be connected to the internet, I would guess that I need some way to make the device think that it does have a valid internet connection so that it won't use mobile data. Does that sound right? And if so, how would I go about doing this? For reference, here is how I was setting up the iptables:

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

And here is my /etc/dnsmasq.conf file:


You are only redirecting port 80. If you redirect all traffic, it's possible the detection mechanism will also use traffic that is redirected, increasing your odds of success. Of course, if the detection is looking for fixed IP addresses, this might not work.

  • Worth noting that if someone has "google.com" bookmarked, it is probably "https://google.com", which would be port 443. Redirecting from that may or may not be something that the phone browser handles politely (I'd guess you at least get a warning pop-up, regardless of the fact that you aren't trying to spoof the real site). – goldilocks Feb 23 '18 at 22:39
  • Thanks for the advice about 443. That's a good idea to add to the redirect. I managed to get around the problem by creating an error handler in Flask for 404's, and serve the index.html instead. That works ok, although now it's acting as a captive portal, which isn't ideal. Still, it works. Thanks for your help. – Andrew Langley Feb 26 '18 at 19:06

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.