Raspberry Pi OS ( Rasbian ) Networking
On newer Raspbian / Raspberry Pi OS systems the network is setup using the dhcpcd daemon. This is used for both DHCP and static IP setups. If you want to use DHCP you can stick with the default. If you want to setup a static IP you can configure the daemon to apply a specific IP that you provide.
Here is an example showing how to set a static IP using the dhcpcd.conf file:
/etc/dhcpcd.confinterface eth0 static ip_address=10.1.1.30/24 static routers=10.1.1.1 static domain_name_servers=10.1.1.1 interface wlan0 static ip_address=10.1.1.31/24 static routers=10.1.1.1 static domain_name_servers=10.1.1.1
The Interfaces File ( old way )
On older systems the network was configured using the interfaces file. Currently this file is not used. If you prefer to set things up this way you can still use this file but you will need to disable dhcpcd and re-enable networking.
Here is an example showing how you would setup static IP addresses using the interfaces file.
/etc/network/interfacesauto eth0 iface eth0 inet static address 10.1.1.30 netmask 255.255.255.0 gateway 10.1.1.1 allow-hotplug wlan0 iface wlan0 inet static address 10.1.1.31 netmask 255.255.255.0 gateway 10.1.1.1 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
For this to work you would need to disable dhcpcd and enable networking like this:
sudo systemctl disable dhcpcd
sudo systemctl enable networking
sudo reboot
Raspberry Pi Wifi Networking
There are multiple different options available for setting up Wifi on a Raspberry Pi.
Headless - Raspberry Pi Imager
Wifi can be configured using the Raspberry Pi Imager when you create your SD card. This can be done with the advanced menu.
To reach the advanced menu use the following key sequences:
[Ctrl] + [Shift] + x | Windows / Linux |
[CMD] + [Shift] + x | MacOS |
Headless - Preconfigure on the SD Card
Another way to configure a headless system is to place your preconfigured wpa_supplicant file in your boot directory on your SD card here:
- /boot/wpa_supplicant.conf
The file will be moved here on boot and will be used to configure wirelss networking:
- /etc/wpa_supplicant/wpa_supplicant.conf
See the section below for an example wpa_supplicant file._
Use the GUI
If your system is already setup and you are using a keyboard and monitor you can use the GUI to configure Wifi. To do this you can just click on the Wifi widget on the bar at the top of the screen.
Use Raspi-config
If your system is already running and you want to setup wifi using the commandline you can use the raspi-config tool. Just use the following command and follow the menu options:
sudo raspi-config
Manually Configure wpa_supplicant
If your system is already up and running you can manually configure wpa_supplicant.
Here is an example config file. You may want to change your country code as well as your SSID and password.
/etc/wpa_supplicant/wpa_supplicant.confctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ ssid="SSIDHERE" psk="PASSWORDHERE" scan_ssid=1 }
After this you can either reboot or run the following command ( you should reboot anyway to make sure it works ).
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Setup SSH on Raspberry Pi - Headless
If you want to enable SSH on a headless Raspberry Pi you can create an empty file on your SD card in the boot directory here:
- /boot/SSH
On boot the system will enable SSH and remove the file.
You can also enable it using Raspberry Pi Imager when you create your SD card. Just use either of these key combos to reach the advanced menu:
[Ctrl] + [Shift] + x | Windows / Linux |
[CMD] + [Shift] + x | MacOS |
Once your system is up you should be able to SSH to it from the same network like this ( swap in an IP for your network ):
ssh pi@192.168.0.5
If you happen to be using Windows you can SSH using either PowerShell or Putty. I would recommend PowerShell. On Linux or MacOS you should have a builtin terminal that will work fine.