Maybe you are a business owner who offers free Wi-Fi to all your customers; maybe you have a captive audience and are planning to sell access to your Wi-Fi network, or maybe you want to friendly remind your guests of the etiquette to use your home network? Here you will learn how to turn your Raspberry Pi into a captive portal Wi-Fi hotspot.
ContentsWhy do I need a captive portal?What you'll needGetting started:Update your Raspberry PiSet up a wireless hotspot for Raspberry PiSecure your Wi-Fi hotspotCreate a captive portal with NodogsplashSet up your captive portalSecure make sure your portal is always onlineHow to customize your captive portalIf you've ever tried to access a seemingly open Wi-Fi network in a coffee shop, restaurant, hotel, or gym, only to be greeted by a login screen that refuses to let you continue until you enter certain information (usually your email address), then you already know about captive portals!
A captive portal is a web page that automatically opens in the user's default browser or loads when they try to visit a web page. The user will usually need to perform an action before they can leave the captive portal.
Although commonly used by businesses, captive portals can also be a useful addition to your home network. For example, you can create a separate network for your children, complete with parental controls and a captive portal that gently reminds your children that you trust them to use the web responsibly – just in case they are keen enough. of technology to know how a VPN works.
To complete this tutorial you will need:
Connect your external keyboard, monitor, and ethernet cable, then connect your Pi to a power source. Once started, open a terminal and type the following command to update it:
sudo apt update &&sudo apt -y upgrade
Restart your Raspberry Pi by running the following command:
Once your Raspberry Pi has restarted, everything will be up to date.
There are several ways to turn your Raspberry Pi into a fully functional access point, but in this tutorial a RaspAP is used because it is easy to configure.
To install the RaspAP software, open a Terminal window and run the following command:
curl -sL https://install.raspap.com | bash
Connect to this network and you will be prompted for a password. RaspAP's default password is "ChangeMe", so enter it in the network configuration box, click "Connect" and you will be connected to your new Raspberry Pi hotspot!
Before going any further, update "ChangeMe" to something more secure, via the RaspAP web interface:
1. Launch your web browser, if you haven't already.
2. In the address bar, type the following:10.3.141.1.
When prompted, enter username "admin" and password "secret". You should now see the main RaspAP web interface.
3. From the left menu, select "Hotspot -> Security".
4. Find the "PSK" section and enter the password you want to use for your Wi-Fi hotspot - make sure it's a secure password!
5. Click "Save Settings".
Now that your access point is up and running, you're ready to secure it with a captive portal.
The captive portal will be built using the Nodogsplash Captive Portal solution, but first you need to install the libmicrohttpd-dev
package, as it contains code that you will use to compile Nodogspash.
On your Raspberry Pi, run the following command:
sudo apt install git libmicrohttpd-dev
Once you have the libmicrohttpd-dev
package, you can clone the repository which contains all the Nodogsplash code:
cd ~git clone https://github.com/nodogsplash/nodogsplash.git
Once Raspbian has finished cloning this code, you are ready to compile and install the Nodogsplash software:
cd ~/nodogsplashmakesudo make install
Nodogsplash is now installed on your Raspberry Pi.
Next, you need to point Nogdogsplash in the direction of the gateway address, which is the router interface connected to the local network. RaspAP uses 10.3.141.1 by default, so you need to edit the Nogdogsplash configuration file so that it listens on this address.
To change the gateway address, open the Nogdogsplash configuration file:
sudo nano /etc/nodogsplash/nodogsplash.conf
Add the following:
GatewayInterface wlan0GatewayAddress 10.3.141.1MaxClients 250AuthIdleTimeout 480
Once these changes are made, save your file by pressing Ctrl + O , followed by Ctrl + X .
Start your captive portal by running the following command:
sudo nodogsplash
Your captive portal is now live. To test it, try connecting to your Wi-Fi hotspot.
You should now be greeted by Nodogsplash's default captive portal.
Now that you have verified that the captive portal is working properly, you need to ensure that Nodogsplash starts automatically on boot.
Configure Nodogsplash to launch automatically by editing your "rc.local" file. In the Raspberry Pi terminal, run the following command:
sudo nano /etc/rc.local
Find the following line:
exit
Just above, add the following:
nodogsplash
Save your changes by pressing Ctrl + O , followed by Ctrl + X .
At this point, you have a WiFi hotspot protected by a captive portal. However, you're still using the default Nodogsplash page, so in this final section, let's look at how you can access the code that controls your captive portal page and make some simple changes.
To customize the default Nodogsplash page, you will need to open the "splash.html" file:
sudo nano /etc/nodogsplash/htdocs/splash.html
You can now add images and text to your portal and remove existing content. For example, in the image below, the text displayed in the captive portal frame is being edited.
When you are happy with the changes you have made, save your changes by pressing Ctrl + O , followed by Ctrl + X .
Try reconnecting to your Wi-Fi hotspot and you should see your captive portal revamped.
Note that depending on your operating system and web browser, you may need to clear your browser cache in order to see the updated captive portal.
In addition to a Wi-Fi hotspot, you can also turn your Raspberry Pi into an ad blocker or personal web server.
How do you use your newly created captive portal? To welcome people into your home network, establish ground rules, or as a tool to help promote your business? Let us know in the comments below!