I have created a python flask script that runs on my raspberry pi, I have also configured rpi to switch to access point so when my laptop/mobile gets connected to the AP, I can navigate to the IP '192.168.4.1' to access the python flask web page. Now I want to do is set up a captive portal so that whenever I get connected to the AP, I get redirected to the IP of my pi and can access the flask web page. Can anyone give me an example/url to follow and understand what to do?
I have tried the following steps: 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.4.1
/etc/rc.local
has limitations due to Compatibility with SysV. We have seen many problems here on this site using it. Following the recommendation of the developers from systemd you should avoid using it.