Although I used an AI tool to help organize my thoughts for this response, the content reflects my genuine reflections and was carefully reviewed and written by me. This is a crucial exam that will determine my high school placement, so I took this question on stackoverflow very seriously.
I am setting up a captive portal on a single Raspberry Pi (Debian/Raspberry Pi OS) to serve a custom web login page when client smartphones connect to its broadcasted AP.
Network & Environment
Hardware: 1 Raspberry Pi with a single wireless interface (
wlan0), connected to an upstream network via Ethernet (eth0).Initial Setup & Troubleshooting History:
Installed packages:
hostapd,dnsmasq,nginx.Disabled station Wi-Fi using
nmtui/nmcli device disconnect wlan0to prevent interface contention with the upstream AP, and configured the system over SSH.Fixed
hostapd.service is maskedstate viasystemctl unmask hostapd.Removed quotes around the SSID name in
hostapd.confto avoid parsing errors.Resolved DNS wildcard spoofing by testing both
address=/192.168.4.1andaddress=/#/192.168.4.1indnsmasq.conf.Verified Nginx listening state with
ss -tlnp(confirmed active on0.0.0.0:80).Configured
/etc/nginx/sites-available/defaultwithtry_files $uri $uri/ /index.html;.Attempted HTTP 302 redirection via
if ($host != '192.168.4.1') { return 302 [http://192.168.4.1/](http://192.168.4.1/); }.Added DHCP default gateway and DNS server options (
dhcp-option=3,192.168.4.1anddhcp-option=6,192.168.4.1).Tested the Android 11+ Captive Portal API standard (RFC 8910) by providing
dhcp-option=114,"[http://192.168.4.1/](http://192.168.4.1/)"indnsmasq.conf.
Configurations
1. /etc/hostapd/hostapd.conf
2. /etc/dnsmasq.conf
enter image description here
3. /etc/nginx/sites-available/default
Nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm;
server_name _;
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
add_header Pragma "no-cache";
if ($host != '192.168.4.1') {
return 302 http://192.168.4.1/;
}
location / {
try_files $uri $uri/ /index.html;
}
}
Observed Behaviors & Logs
Direct HTTP Access: Navigating directly to
[http://192.168.4.1](http://192.168.4.1)or arbitrary HTTP URLs (e.g.,[http://neverssl.com](http://neverssl.com)) successfully routes and loads the localindex.html.HTTPS Requests: Attempting to connect to HTTPS domains returns
ERR_CONNECTION_REFUSEDsince port 443 is closed.Android Captive Portal Trigger: Android devices connected to the AP do not display the "Sign in to network" notification.
/var/log/nginx/access.logOutput:
Despite the probing request to /generate_204 receiving a 302 redirect to the portal, the Android OS suppresses the captive portal modal/notification.
What is missing in the DNS, DHCP, or Nginx redirection strategy to reliably force Android to launch the captive portal login screen?
enter image description here
enter image description here
refered:
https://hawksites.newpaltz.edu/myerse/2018/06/08/hostapd-on-raspberry-pi/