Raspberry Pi Zero W – Static IP Address

After installing my Raspberry Pi Zero W in my previous blog here. All I have to do is configure a static IP address and my Raspberry Pi Zero W is ready for use. Here I will show you how to set a static IP address on your Raspberry Pi Zero W on Raspbian OS.

I recommend doing this on a fresh install, however if you have attempted to set a static IP address already, you may have found yourself editing the interfaces file (/etc/network/interfaces). I hope you made a backup, because you’ll need to remove any edits you have made, and revert it back to its original state!

The following is done over SSH as I use the lite version of Rasbian OS lite version, but you could just as well plug your Pi into a monitor, hook up a keyboard and mouse, and use the Terminal instead, if you use the full version of Rasbian OS.

Connect the Raspberry Pi to your Wi-Fi router

In order to configure the Wi-Fi connection when starting the Pi, we will create the wpa_supplicant.conf file in the boot partition.

by typing:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

The file must contains the following lines:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1


network={
    ssid="Your_SIDD"
    scan_ssid=1
    key_mgmt=WPA-PSK
    psk="Your_Password"
}

 

Then you need to edit the dhcpcd.conf file

sudo nano /etc/dhcpcd.conf

Scroll all the way to the bottom of the file and add one, or both of the following snippets.
Depending on whether you want to set a static IP address for a wired connection or a wireless connection eth0 = wired, wlan0 = wireless.




You’ll need to edit the numbers in the snippet so they match your network configuration.

interface eth0

static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

interface wlan0

static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

interface = This defines which network interface you are setting the configuration for.
static ip_address = This is the IP address that you want to set your device to. (Make sure you leave the /24 at the end)
static routers = This is the IP address of your gateway (probably the IP address or your router)
static domain_name_servers = This is the IP address of your DNS (probably the IP address of your router). You can add multiple IP addresses here separated with a single space.

To exit the editor, press ctrl+x. To save your changes press the letter “Y” then hit Enter. Now all you need to do is reboot, and everything should be set!

sudo reboot

You can double check by typing

ifconfig

And checking the interfaces IP address, with the one you provided. That’s it!

Scroll to Top