Captive Portal Raspberry Pi
Captive Portal Raspberry Pi
A captive portal is a web page that is displayed to users before they can access the Internet. It can be used for various purposes, such as authentication, marketing, or information. In this article, we will show you how to set up a captive portal on your Raspberry Pi using two popular software: RaspAP and Nodogsplash.
What You Need
A Raspberry Pi that is running Raspberry Pi OS
A power cable that is compatible with your Raspberry Pi
An external keyboard and a way to attach it to your Raspberry Pi
An HDMI or micro HDMI cable, depending on your model of Raspberry Pi
An external monitor
An Ethernet cable. Since you are turning your Raspberry Pi into a wireless access point, you will need to connect over Ethernet rather than Wi-Fi.
A Wi-Fi adapter or a model of Raspberry Pi that has built-in Wi-Fi. This will be used to create the wireless access point.
Step 1: Update Your Raspberry Pi
Before you start, you should make sure that your Raspberry Pi is up to date. Attach your external keyboard, monitor and Ethernet cable, and then attach your Pi to a power source. Once it is booted up, open a terminal and type the following command to update it:
sudo apt update && sudo apt -y upgrade
Reboot your Raspberry Pi by running the following command:
Step 2: Install RaspAP
RaspAP is a software that allows you to easily set up a wireless access point on your Raspberry Pi. To install it, open a terminal and run the following command:
curl -sL bash
Next, reboot your Raspberry Pi using the following command:
Once your Raspberry Pi is back up and running, your Wi-Fi access point will be configured with the following settings:
You can change these settings by accessing the web interface of RaspAP from any device that is connected to the same network as your Raspberry Pi. The default username and password are both "admin". You can also access the web interface from your Raspberry Pi by opening a browser and typing the following URL:
Step 3: Install Nodogsplash
Nodogsplash is a software that allows you to create a captive portal on your wireless access point. It can display any web page that you want to users before they can access the Internet. To install it, you will need to install some dependencies first. On your Raspberry Pi, run the following command:
sudo apt install git libmicrohttpd-dev build-essential
Next, clone the Nodogsplash repository from GitHub by running the following command:
Then, change to the Nodogsplash directory and compile and install the software by running the following commands:
cd nodogsplash make sudo make install
Step 4: Configure Nodogsplash
Nodogsplash has a configuration file that you can edit to customize your captive portal. The file is located at /etc/nodogsplash/nodogsplash.conf. You can open it with any text editor, such as nano:
sudo nano /etc/nodogsplash/nodogsplash.conf
There are many options that you can change in this file, but here are some of the most important ones:
GatewayInterface: This is the name of the interface that is used for the wireless access point. You should change it to match the name of your Wi-Fi adapter or the built-in Wi-Fi of your Raspberry Pi. You can find out the name by running the command iwconfig. For example, if your Wi-Fi adapter is named wlan0, then you should change this line to GatewayInterface wlan0.
GatewayName: This is the name that will be displayed on the captive portal. You can change it to anything you want, such as GatewayName My Raspberry Pi.
MaxClients: This is the maximum number of clients that can connect to your wireless access point at the same time. You can change it to suit your needs, but keep in mind that a higher number may affect the performance of your Raspberry Pi. For example, you can set it to MaxClients 20.
PreAuthIdleTimeout: This is the number of minutes that a client can stay connected to your wireless access point without authenticating on the captive portal. After this time, the client will be disconnected and will have to authenticate again. You can change it to any value you want, such as PreAuthIdleTimeout 10.
SplashPage: This is the name of the file that contains the HTML code for the captive portal. The file is located at /etc/nodogsplash/htdocs/splash.html. You can edit this file to customize the appearance and content of your captive portal. For example, you can add a logo, a title, a message, a form, or a button.
After you have made the changes that you want, save and close the file by pressing Ctrl+X, then Y, then Enter.
Step 5: Start Nodogsplash
To start Nodogsplash, run the following command:
You can also make Nodogsplash start automatically at boot by running the following command:
sudo systemctl enable nodogsplash
Step 6: Test Your Captive Portal
To test your captive portal, connect to your wireless access point from another device, such as a smartphone or a laptop. You should see the captive portal page that you have configured in Step 4. Depending on what you have added to the splash.html file, you may need to enter some information or click a button to access the Internet.
In this article, we have shown you how to set up a captive portal on your Raspberry Pi using RaspAP and Nodogsplash. You can use this captive portal for various purposes, such as authentication, marketing, or information. You can also customize it to suit your needs and preferences by editing the configuration and HTML files.
If you want to learn more about RaspAP and Nodogsplash, you can visit their websites or their GitHub repositories . You can also find more tutorials and projects for your Raspberry Pi on our website.