1

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
}

(taken from https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/157-raspberry-pi-auto-wifi-hotspot-switch-internet)

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

2
  • What operating system do you use? What are these createAdHocNetwork() {} statements? Haven't seen it before.
    – Ingo
    Commented Nov 29, 2019 at 13:20
  • At first, try to make your RPi function az a normal wifi hotspot. Then, download the latest stable version of nodogsplash and compile that. Look at THIS link. Commented Dec 10, 2019 at 22:09

1 Answer 1

1

Follow the instructions:

sudo apt install git libmicrohttpd-dev

git clone https://github.com/nodogsplash/nodogsplash.git

cd nodogsplash
make
sudo make install

sudo nano /etc/nodogsplash/nodogsplash.conf   

Change the configuration to:

GatewayInterface wlan0
GatewayAddress 192.168.5.1
MaxClients 250
AuthIdleTimeout 480

Add nodogsplash command to rc.local:

sudo nano /etc/rc.local  

add this line before Exit 0:

iptables-restore < /etc/iptables.ipv4.nat    

Now, you can connect to the MyPiAP SSID and the splash page will appear. Tap the Continue button for connecting to the internet.

Bear it in mind that the splash page doesn't appear for clients if the RPi doesn't have an internet connection.
To solve this problem, check this link - Running NDS without Internet Access out on GitHub.

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.