A hotspot is technically a Wireless Local Area Network Access Point (WLAN AP). Raspberry Pi’s have a wifi interface that can be configured to provide a wifi network. The article will give a step-by-step guide for setting up a Raspberry Pi hotspot using the nmcli package. We will discuss more nmcli commands shortly.
If you are not running Fedora, then the first prerequisite should be getting Fedora to run with your Raspberry Pi.
- A Raspberry PI 3, 4 single-board computer.
- Network connectivity to the Ethernet network.
- A power supply.
- Ensure you have local access to your Raspberry Pi with screen and keyboard.
- Ensure the Fedora running in your Pi is up-to-date.
- Ensure you have a wireless client like a laptop or smartphone
A hotspot is technically a routed Access Point that sits between the wired network and the created wireless network. The hotspot is tasked with forwarding IP packets between the wired and wireless networks. In Raspberry, the wireless interface is named wlan0, while the wired interface is named eth0.
We will create a wireless network that uses an IP address range different from the current one being used by the wired network. In networking, packets are sent or routed to remote or local destinations based on their IP addresses. This guide will set up a simple routing process, but more complex routers can be set up using DNS and DHCP.
Is it a bridged AP?
No!. The setup we are going to create will not use network bridging to extend the network. The difference between bridging and routing is on the implementation at different OSI network model levels. Bridged AP’s work at the data link networking layer and uses Ethernet MAC addresses to send data. Bridged AP’s use the same IP subnet for the current wired network and the new wireless network.
Understand the OSI network model
- layer 3, network layer – Routed AP
- layer2, data link layer – Bridged AP
- layer 1, physical layer – radio transmission
IP masquerading provides a way of routing IP packets in and out of a wifi network. The process involves changing the packet’s addresses where the masquerade name is used and the packet’s addresses are hidden. In essence, the wired network only sees the masquerade names from the wireless network. You do not have to configure IP masquerading as NetworkManager automatically handles it manually.
Creating the Wi-Fi Access Point or “Hotspot”
Most of the software required is already installed in your Fedora, but you will have to install the dnsmasq package to get going. The dnsmasq package will automatically handle the DHCP and IP addresses of the new wifi network. You can also create more complex solutions using the hostapd RPM package and the OpenWRT distro.
If there is a thing or two you can learn from ‘ The Zen of Python ‘ is:
'Simple is better than complex.' 'Complex is better than complicated.'
We will keep it simple with a few nmcli commands.
Install dnsmag package
$ sudo dnf install dnsmasq
Creating a new Network Manager connection
Add wifi connection using the nmcli tool
Use the nmcli tool to tell the NetworkManager to add a new wifi connection. The step will create a new configuration file in the local directory etc/sysconfig/network-scripts/.
Step 1: Check available network configuration files in /etc/sysconfig/network-scripts/.
~]$ ls /etc/sysconfig/network-scripts/
The directory will be empty if you do not have any configuration files for the network interfaces.
Step 2: First nmcli command to create a network connection
nmcli con add \ type wifi \ ifname wlan0 \ con-name ‘Pifedora hotspot’ \ autoconnect yes \ ssid ‘Pifedora wifi’
Step 3: List available connections
$ sudo nmcli con add type wifi ifname wlan0 con-name 'Pifedora hotspot' autoconnect yes SSID 'Pifedora wifi.' Connection 'Pifedora hotspot' (e79d8ed3-752c-4973-ae4f-4be1a26a2648) successfully added.
$ sudo nmcli connection show NAME UUID TYPE DEVICE XXXX a98856a4-1070-470b-a4ed-19724629ef27 wifi wlp3s0 XXXX 18412596-9b23-49c3-824c-27c375809661 bridge virbr0 Pifedora hotspot e79d8ed3-752c-4973-ae4f-4be1a26a2648 wifi -- Wired connection 1 5e5fb648-17bd-3e96-a453-c5b60e64ae81 ethernet --
Step 4: Check if NetworkManager added a config file to the network-scripts folder. Run the command terminal to list all the available wired and wireless connections.
~]$ ls /etc/sysconfig/network-scripts/ ifcfg-Pifedora_wifi ~ ] $ sudo nmcli device wifi list ..... ...... C4:27:95:C1:8B:D7 XXXX Infra 1 130 Mbit/s 47 ▂▄__ WPA1 WPA2 44:32:C8:9C:B4:FB XXXX Infra 6 130 Mbit/s 32 ▂▄__ WPA1 WPA2 88:F7:C7:A0:B6:D0 XXXX Infra 1 130 Mbit/s 10 ▂___ WPA1 WPA2
Step 6: You can remove the new wifi hotspot config and restart the configuration with the following command.Step 5: List available Access Points (AP’s) to connect.
$ sudo nmcli con delete 'Pifedora hotspot.'
Change connection mode
1: Use the following command to view the configuration settings of your hotspot ‘Pifedora hotspot.’
$ sudo nmcli con show ‘Pifedora hotspot’ connection.id: Pifedora hotspot connection.uuid: e79d8ed3-752c-4973-ae4f-4be1a26a2648 connection.stable-id: -- connection.type: 802-11-wireless connection.interface-name: wlan0 connection.autoconnect: yes connection.autoconnect-priority: 0 connection.autoconnect-retries: -1 (default) connection.multi-connect: 0 (default) connection.auth-retries: -1 connection.timestamp: 0 connection.read-only: no connection.permissions: -- connection.zone: -- connection.master: -- connection.slave-type: -- connection.autoconnect-slaves: -1 (default) connection.secondaries: -- connection.gateway-ping-timeout: 0 connection.metered: unknown connection.lldp: default
The nmcli con show ‘Pifedora hotspot’ command will show many configuration settings like 802.11 wifi protocols, connection id, connection UUID e.t.c.
Pi hotspot config
You will notice that your new wifi connection is in infrastructure mode. It implies that our connection is ready to connect to available wifi access points. However, we aimed to make the Raspberry Pi an Access Point (AP), and it should not connect to another AP.
2: Change the wifi connection infrastructure mode to AP
sudo nmcli connection \ modify "Pifedora hotspot" \ 802-11-wireless.mode ap \ 802-11-wireless.band bg \ ipv4.method shared
802-11-wireless.mode ap: The configuration tells the NetworkManager to use 802.11b and 802.11g IEEE standards. It will configure the radio to use a 2.4Ghz frequency band instead of the 5GHz band.
ipv4.method shared: It will share the connection with others. The command will start the connection automatically.
3: Manually start the hotspot
$ sudo nmcli con up "Pifedora hotspot."
4: Manually stop the hotspot
$ sudo nmcli con down "Pifedora hotspot."
Connect a device
The next step is to test your hotspot by connecting using a wifi-enabled device like your smartphone. You can also watch the connection logs by running the following command.
$ journalctl --follow -- Logs begin at Mon 2021-04-05 11:10:17 BST. -- Apr 06 13:11:58 …...
Increase security with WPA-PSK
WPA_PSK (wifi Protected Access with Pre-Shared Key) is a wifi password protection system for home and small office users. You can add a password for your hotspot using the following command.
$ sudo nmcli con modify "Pifedora hotspot" witufi-sec.key-mgmt wpa-ps $ sudo nmcli con modify "Pifedora hotspot" wifi-sec.psk "hotspot-password"
If your wireless client (smartphone, laptop) has access to your Raspberry Pi or AP hotspot, you have successfully set up a wifi hotspot on a Pi running Fedora. There is much you can do with a Raspberry PI Access Point. You can connect to it using SSH or run the Raspberry Pi as a headless computer. To test it as a headless computer, follow these steps;
Power off the Raspberry Pi >> Remove the keyboard and monitor >> Power on >> Wait a couple of minutes >> Connect to the AP or connect to the Raspberry Pi using SSH.