2

I recently got a raspberry pi. I have it set up as an access point in a standalone network (not connected to the internet). I can also serve a static website on this network. Ive been trying to set up a captive portal so that when a user joins the network it automatically takes them to this website.

Looking at these tutorials:

This is how I set up the access point

For captive portal using nodogsplash

So the access point is working but honestly I have no clue about how the captive portal works with this. Im wondering whether the pi has to be connected to the internet for the captive portal to work? If anyone knows anything useful, I will forever be in your debt.

3

Follow the instruction:
1. Config the RPi as a Wifi Access point or a Wifi Hotspot

sudo apt-get -y install hostapd dnsmasq 

nano /etc/hostapd/hostapd.conf   

Add the config below to the hostapd.conf file:

interface=wlan0
driver=nl80211
ssid=MyPiAP
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=raspberry
rsn_pairwise=CCMP   

Edit hostapd:

nano /etc/default/hostapd  

Change this part to:

DAEMON_CONF="/etc/hostapd/hostapd.conf"   

Then:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
sudo nano /etc/dnsmasq.conf  

Add these lines to dnsmasq.conf :

interface=wlan0 
listen-address=192.168.5.1
bind-interfaces 
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.5.100,192.168.5.200,24h  

Enable IP Forwarding:

nano /etc/sysctl.conf  

Uncomment:

net.ipv4.ip_forward=1  

Add these commands for the firewall and packet forwarding:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT  

sh -c "iptables-save > /etc/iptables.ipv4.nat"  



sudo nano /etc/rc.local  

add these lines before Exit 0:

iptables-restore < /etc/iptables.ipv4.nat  
ifconfig wlan0 192.168.5.1

Finally, reboot the device and check it out by a Wifi client. You must connect to the internet.
Note that, you need to connect to internet by eth0 interface.

2. Now, it's the time to using nodogsplash, which is the captive portal software:

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.
Done.

0

In case of you need a customizable captive portal you can install all using this project Kupiki https://github.com/pihomeserver/Kupiki-Hotspot-Script

Once installed you can replace the captive portal by what ever you want using the Nginx configuration.

Internet is not mandatory. It's usefull if you want the page to be closed automatically once you are authenticated as it tries to reach a specific page to confirm that Internet is up

0

Captive portals work because devices make a DNS request to specific URLS, depending on which operating system, and they expect a success response. If they get a redirect instead, then they will show that new site as a captive portal.

A list of some of the URL's can be found here: How Automatic Detection of Captive Portal works.

If you followed that tutorial, then you can change your DNS server to redirect any request to a domain that isn't yours to the Raspberry Pi. The /etc/dnsmasq.conf file controls the DNS server. Add the following line to redirect all requests (change the IP address if you chose not to use 192.168.4.1)

address=/#/192.168.1.1

You will then need to set up your webserver to redirect those requests. I suggest choosing a URL, like http://mysite/, and telling your webserver (such as nginx) to show your site for that domain, and send a redirect for all other domains.

For setting up redirects, see the following pages

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.