What I'm trying to achieve is that I can manually switch between my Pi having internet access over WLAN or letting it function as an Access Point. When the Access Point is active, the Pi has no internet (there is no eth0 available) and it broadcasts its SSID.
When a user is connected, he should be presented with a Captive Portal (such as nodogsplash).
When deleting the AP, WLAN should function normal again.
Creating the AP works fine, letting nodogsplasg setup a webserver at the gateway (in my case 192.168.50.5), works as well. Users can also connect to the AP and browse manually to the nodogsplash site: 192.168.50.5:2050. The problem is that there is no captive screen presented, and when the user browses to any other site, the browser displays a connection error as opposed to the captive portal.
It seems that not all traffic is routed properly to the webserver.
This is how I create the AP ($wifidev = "wlan0")
createAdHocNetwork()
{
echo "Creating Hotspot"
ip link set dev "$wifidev" down
ip a add 192.168.50.5/24 brd + dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -k "$wifidev" >/dev/null 2>&1
iptables -t nat -A POSTROUTING -o "$ethdev" -j MASQUERADE
iptables -A FORWARD -i "$ethdev" -o "$wifidev" -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i "$wifidev" -o "$ethdev" -j ACCEPT
systemctl start dnsmasq
systemctl start hostapd
echo 1 > /proc/sys/net/ipv4/ip_forward
}
I modified it slightly, since my pi doesn't have eth0:
createAdHocNetwork()
{
echo "Creating Hotspot"
ip link set dev "$wifidev" down
ip a add 192.168.50.5/24 brd + dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -k "$wifidev" >/dev/null 2>&1
iptables -t nat -A POSTROUTING -j MASQUERADE
systemctl start dnsmasq
systemctl start hostapd
echo 1 > /proc/sys/net/ipv4/ip_forward
}
The /etc/dnsmasq.conf file reads:
#AutoHotspot config
interface=wlan0
bind-dynamic
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.50.150,192.168.50.200,255.255.255.0,12h
Any clue on what might be incorrectly setup here?
Thanks!
M
createAdHocNetwork() {}
statements? Haven't seen it before.nodogsplash
and compile that. Look at THIS link.