0

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 192.168.4.1:80

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

interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
bogus-priv
server=/localnet/192.168.4.1
local=/localnet/
address=/#/192.168.4.1
domain=localnet
dhcp-option=3,192.168.4.1
dhcp-option=6,192.168.4.1

1 Answer 1

1

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.

2
  • 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
    Commented Feb 23, 2018 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. Commented Feb 26, 2018 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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