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
Start the hostapd
service:
sudo service hostapd start
If you face to a problem in this step, check this link out.
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.