Learn how to set a static / fixed IP address for your Raspberry Pi Pico W. When your Pico connects to a network, some routers may assign a different IP address each time it reboots. This can be inconvenient if you need to access or communicate with your board using its IP address. In this guide, we’ll show you how to assign a static IP address to your Raspberry Pi Pico W.

Recommended reading: Raspberry Pi Pico W: Getting Started with Wi-Fi (MicroPython)
Prerequisites
To follow this tutorial, you need:
1) A Raspberry Pi Pico W or Raspberry Pi Pico 2W board (these models support Wi-Fi).
2) MicroPython firmware installed on your Raspberry Pi Pico board, and an IDE to write and upload code. Follow this tutorial: Programming Raspberry Pi Pico using MicroPython.
Setting a Static/Fixed IP Address on the Raspberry Pi Pico
In the case of my network, even if I restart the Raspberry Pi Pico several times, my router will always assign it the same IP address. However, that’s not the case for some other networks. In that scenario, it’s nice to have a way to set a static IP address to your board, so that it doesn’t change every time it resets.
Additionally, setting a static IP address is also useful for projects that are not connected to your computer or don’t have a way to display the IP address.
You can use the ifconfig method of the network.WLAN object to set a static IP address. For example, use the following line after connecting to your network.
wlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))
The following example connects your board to your network and then sets a static IP address.
# Rui Santos & Sara Santos - Random Nerd Tutorials
# Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-w-wi-fi-micropython/
import network
import time
# Wi-Fi credentials
ssid = 'REPLACE_WITH_YOUR_SSID'
password = 'REPLACE_WITH_YOUR_PASSWORD'
# Static IP configuration
static_ip = '192.168.1.100' # Replace with your desired static IP
subnet_mask = '255.255.255.0'
gateway_ip = '192.168.1.254'
dns_server = '8.8.8.8'
# Init Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Connect to your network
wlan.connect(ssid, password)
# Wait for Wi-Fi connection
connection_timeout = 10
while connection_timeout > 0:
if wlan.status() >= 3:
break
connection_timeout -= 1
print('Waiting for Wi-Fi connection...')
time.sleep(1)
# Set static IP address
wlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))
# Check if connection is successful
if wlan.status() != 3:
raise RuntimeError('Failed to establish a network connection')
else:
print('Connection successful!')
network_info = wlan.ifconfig()
print('IP address:', network_info[0])
Static IP Configuration
Replace the values in the static_ip, subnet_mask, gateway_ip, and dns_server variables with the appropriate values for your network.
# Static IP configuration
static_ip = '192.168.1.100' # Replace with your desired static IP
subnet_mask = '255.255.255.0'
gateway_ip = '192.168.1.254'
dns_server = '8.8.8.8'
How to find those values?
There are different ways to get information about the subnet mask and the gateway IP. The easiest way is to open a Terminal window on your computer and run the following command:
On Windows:
ipconfig
On MacOS or Linux:
ifconfig

It will return the information you’re looking for: the gateway IP (the IP address of your router) and the subnet mask.

In my case, the subnet mask is 255.255.255.0 and the gateway IP address is 192.168.1.254.
For the DNS server, you can always use 8.8.8.8, which is Google’s public DNS server.
When choosing the static IP address for your Raspberry Pi Pico, make sure that the address is not already being used by another device. To do that, you can use software like Angry IP Scanner (compatible with Windows and Mac OS). Or you can login to your router dashboard and check which IP addresses are already assigned.
Setting a Static IP Address
After assigning the proper values for the configuration variables, we can simply use the ifconfig() method and pass as arguments the static IP, the subnet mask, the gateway IP, and the DNS server, in this order.
wlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))
Inserting Your Network Credentials
To test this code, don’t forget to insert your network credentials in the following lines so that your board can connect to your router:
ssid = 'REPLACE_WITH_YOUR_SSID'
password = 'REPLACE_WITH_YOUR_PASSWORD'
Testing the Code
After inserting your network credentials and desired IP address settings, you can run the code on your Raspberry Pi Pico.
Notice that it will have the IP address you defined in the code. In our case, 192.168.1.100.

You can also check your router’s dashboard or AngryIP Scanner to confirm that your RPi Pico has been assigned the IP address you chose.

Restart your board, and check that it remains with the same IP address.
Wrapping Up
This was a quick guide showing you how you can modify your MicroPython scripts to set a static/fixed IP address to your Raspberry Pi Pico. We have other Wi-Fi and network-related guides for the Raspberry Pi Pico that you may like:
- Raspberry Pi Pico W: Getting Started with Wi-Fi (MicroPython)
- Raspberry Pi Pico W: Getting Started with HTTP GET Requests (MicroPython)
- Raspberry Pi Pico: Web Server (MicroPython)
Learn more about the Raspberry Pi Pico with our resources:



