Introduction
This article explains how to set up an Ad-hoc network with multiple Raspberry Pi 5 devices without using DHCP, static IP addresses, and no default route using the nmtui tool. Ad-hoc networks are useful when a wired connection is not available or when setting up a temporary network. In this setup, we will not be using DHCP (Dynamic Host Configuration Protocol) to assign IP addresses automatically. Instead, we will manually configure static IP addresses for each device. Additionally, we will not be setting up a default route, meaning that each device will only be able to communicate with other devices on the Ad-hoc network.
Prerequisites
Before we begin, ensure the following:
- You have at least two Raspberry Pi 5 devices.
- Each Raspberry Pi 5 device has an up-to-date Raspberry Pi OS installation.
- Both Raspberry Pi 5 devices are connected to power and a monitor.
- Both Raspberry Pi 5 devices have an active Wi-Fi connection.
Setting up the Ad-hoc Network
First, we need to set up the Ad-hoc network on one of the Raspberry Pi 5 devices (let's call it the "Access Point" Pi).
Step 1: Disable Wi-Fi and Enable Ad-hoc Mode
Open a terminal window on the Access Point Pi and run the following commands:
sudo systemctl disable wpa_supplicant
sudo systemctl disable wpa_supplicant-wifi
sudo systemctl disable networking
sudo raspberrypi-config
In the Raspberry Pi configuration tool, navigate to "Interfaces" and select "Wi-Fi." Enable "Ad-hoc mode" and save and reboot.
Step 2: Configure the Access Point Pi
Once the Access Point Pi has rebooted, open a terminal window and run the following commands:
sudo nano /etc/network/interfaces.d/wlan0.conf
Add the following lines to the file:
interface wlan0 address 192.168.42.1 netmask 255.255.255.0 broadcast 192.168.42.255 wpa-roam off wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Save and close the file. Then, create the wpa_supplicant.conf file:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the following lines to the file:
country=US
network={
ssid="RaspberryPiAdhoc"
psk="password"
key_mgmt=WPA-PSK
}
Replace "password" with a strong password for your network.
Step 3: Configure the Client Pi
Now, we need to configure the second Raspberry Pi 5 device (let's call it the "Client" Pi).
Open a terminal window on the Client Pi and run the following commands:
sudo nano /etc/network/interfaces.d/wlan0.conf
Add the following lines to the file:
interface wlan0 wpa-roam off wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Create the wpa_supplicant.conf file:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the following lines to the file:
country=US
network={
ssid="RaspberryPiAdhoc"
psk="password"
id_str="ClientPi"
priority=5
}
Replace "password" with the same password used on the Access Point Pi.
Step 4: Start the Network Services
On both the Access Point Pi and the Client Pi, run the following commands:
sudo systemctl start networking
sudo systemctl start wpa_supplicant
sudo systemctl start hostapd
Verifying the Connection
To verify that the Ad-hoc network is working, connect the Client Pi to the Access Point Pi's Wi-Fi network. You can check the IP addresses of both devices by running the following command:
ip a
The Access Point Pi should have an IP address of 192.168.42.1, and the Client Pi should have an IP address within the range of 192.168.42.2 to 192.168.42.255.
In this article, we learned how to set up an Ad-hoc network with multiple Raspberry Pi 5 devices without using DHCP, static IP addresses, and no default route using the nmtui tool. This setup is useful when a wired connection is not available or when setting up a temporary network. By following the steps outlined in this article, you can create a secure and reliable Ad-hoc network for your Raspberry Pi devices.