A Step-by-Step Guide for Beginners
Learn how to connect your Raspberry Pi to a wireless network using the command line interface and configure static IP address settings. …
Updated September 26, 2023
Learn how to connect your Raspberry Pi to a wireless network using the command line interface and configure static IP address settings.
Overview
Connecting a Raspberry Pi device to a Wi-Fi network can be done in multiple ways, but one of the most common and simplest methods is through the command line interface (CLI). This guide will walk you through the process step by step, making it easy for beginners to set up their Raspberry Pi with wireless connectivity.
Requirements:
- A Raspberry Pi device (3B, 3B+, 4 or Zero W)
- A Micro SD card with a fresh installation of the Raspberry Pi OS
- A Wi-Fi dongle or built-in Wi-Fi support (for Raspberry Pi 3B+ and newer models)
- A wireless network with internet access
- A monitor, keyboard and mouse (optional for headless setup)
Steps:
Boot up your Raspberry Pi: Insert the Micro SD card into your Raspberry Pi device and power it on. If you’re using a monitor, keyboard and mouse, log in to the desktop environment with the default username
pi
and passwordraspberry
.Open a terminal window: Press
Ctrl + Alt + T
or navigate to Menu > Accessories > Terminal to open a new terminal window.Check your Wi-Fi device: To verify that your Raspberry Pi recognizes your Wi-Fi dongle, type the following command and press Enter:
sudo iwconfig
You should see output similar to this:
wlan0 IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=15 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
If you don’t see wlan0
or a similar output, make sure your Wi-Fi device is properly connected to the Raspberry Pi.
- Enable Wi-Fi: Type the following command to enable Wi-Fi on your Raspberry Pi and press Enter:
sudo systemctl enable wpa_supplicant
- Configure Wi-Fi settings: Create a new file named
wpa_supplicant.conf
in the/etc/wpa_supplicant/
directory with your preferred text editor (e.g., nano or vim). For example, to use nano, type:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the following content to the file, replacing <your_network>
with your Wi-Fi network name and <your_password>
with your Wi-Fi password:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="<your_network>"
psk="<your_password>"
}
Save and exit the text editor (e.g., Ctrl + X
, then Y
to save, and Enter
to confirm).
- Reboot your Raspberry Pi: Type the following command to restart your device:
sudo reboot
After the reboot, your Raspberry Pi should automatically connect to the specified Wi-Fi network. You can verify the connection by typing iwconfig
again in the terminal.
Optional: Configure Static IP Address Settings
If you want to assign a static IP address to your Raspberry Pi device instead of using DHCP, follow these steps:
- Open the network configuration file: Type the following command to open the
dhcpcd.conf
file in your preferred text editor (e.g., nano):
sudo nano /etc/dhcpcd.conf
- Add static IP settings: Add the following content to the end of the file, replacing
<static_ip>
,<subnet_mask>
,<router_ip>
and<dns_server>
with appropriate values for your network:
interface wlan0
static ip_address=<static_ip>/<subnet_mask>
static routers=<router_ip>
static domain_name_servers=<dns_server>
Save and exit the text editor (e.g., Ctrl + X
, then Y
to save, and Enter
to confirm).
- Restart the DHCP client: Type the following command to restart the DHCP client on your Raspberry Pi:
sudo systemctl restart dhcpcd
- Verify static IP assignment: Use the
ifconfig
command to check if your Raspberry Pi has been assigned the correct static IP address:
ifconfig wlan0
You should see output similar to this:
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <static_ip> netmask <subnet_mask> broadcast <broadcast_ip>
...
If the IP address is correct, your Raspberry Pi is now connected to Wi-Fi with a static IP configuration.
And that’s it! Your Raspberry Pi is now connected to a wireless network and can access the internet. Enjoy your newfound freedom from Ethernet cables and wired connections.