To set up a Raspberry Pi with Wi-Fi and a static IP, you need to configure the network interface manually in the operating system—typically Raspberry Pi OS. This ensures the device always uses the same local IP address, which is essential for remote access, hosting services, or consistent device discovery on your network. You’ll need a Raspberry Pi (any model with Wi-Fi, like Pi 3, 4, or Zero W), a microSD card with Raspberry Pi OS installed (desktop or Lite), power supply, and access to your router’s IP address and subnet mask (usually found in router labels or admin settings).
What You'll Need
- Raspberry Pi (Model 3, 4, 400, or Zero W with built-in Wi-Fi)
- microSD card (16 GB minimum) preloaded with Raspberry Pi OS (2023 or newer)
- Power adapter compatible with your Pi model
- Computer to initially configure the Pi (for headless setup) or monitor/keyboard (for direct setup)
- Wi-Fi network name (SSID) and password
- Access to your router’s admin page (to find gateway IP, subnet mask, and DNS server)
Step-by-Step
- Boot your Raspberry Pi and log in: If using desktop, log in with your credentials. If using SSH (headless), connect via Terminal (macOS/Linux) or PuTTY (Windows) using the default hostname
raspberrypi.localand userpi(passwordraspberry, unless changed). Ensure Wi-Fi is already connected—either via GUI (desktop) or pre-configured inwpa_supplicant.confduring initial setup. - Identify your current network details: Run
ip route showto find your default gateway (e.g.,192.168.1.1). Runip addr show wlan0to confirm your current IP address (e.g.,192.168.1.45) and note the subnet mask (e.g.,255.255.255.0, which corresponds to/24). Also runcat /etc/resolv.confto see your DNS server (often the same as the gateway). - Open the dhcpcd configuration file: Run
sudo nano /etc/dhcpcd.conf. Scroll to the bottom of the file (press Ctrl+V repeatedly if needed). - Add static IP configuration: Append the following lines, replacing placeholders with your network values (use your actual gateway, IP, and DNS—do *not* use the example values):
interface wlan0
static ip_address=192.168.1.50/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
Replace192.168.1.50with an IP *outside* your router’s DHCP range (e.g., if DHCP assigns 100–200, pick 50 or 210). The/24matches a255.255.255.0subnet; use/16for255.255.0.0if your network uses that. - Save and exit: Press Ctrl+O, then Enter to write the file, then Ctrl+X to exit nano.
- Restart the networking service: Run
sudo systemctl restart dhcpcd. Alternatively, reboot the Pi withsudo rebootfor a clean reload—this is recommended. - Verify the static IP: After reboot, run
ip addr show wlan0again. Confirm the IP matches your configured static address. Runip route showto verify the gateway is set correctly. - Test connectivity: Run
ping -c 4 8.8.8.8to test internet access via IP, thenping -c 4 google.comto confirm DNS resolution works. If both succeed, your static IP is active.
Common Mistakes
Avoid these frequent errors when setting a static IP:
- Duplicate IP conflict: Picking an IP already assigned by the router’s DHCP pool causes intermittent connectivity loss. Always check your router’s DHCP range (e.g., via
192.168.1.1admin page) and choose an address outside it. - Incorrect subnet mask: Using
/24when your network uses/16(e.g.,10.0.0.0/16) breaks routing. Match the mask to your network—ip addr show wlan0shows your current mask before editing. - Missing or wrong gateway: Omitting
static routers=prevents internet access beyond your local network. Include it even if your DNS seems to work. - Editing the wrong file: Raspberry Pi OS uses
dhcpcd.conf, *not*/etc/network/interfacesorwpa_supplicant.conffor static IPs. Confusing these causes the Pi to ignore your settings. - Forgetting to restart networking: Changes don’t apply until
systemctl restart dhcpcdor a reboot. A simpleifdown/ifupis unreliable on newer OS versions.
Tips
- Reserve IPs in your router: For extra reliability, reserve your Pi’s static IP in the router’s DHCP settings. This prevents other devices from claiming it, even if you misconfigure later.
- Use a consistent naming scheme: Assign IPs like
192.168.1.100for servers,192.168.1.101for NAS, etc. This avoids confusion and simplifies future management. - Test before rebooting: Run
sudo dhcpcd -k wlan0 && sudo dhcpcd wlan0to restart only the Wi-Fi interface without rebooting—saves time during testing. - Keep a backup: Before editing, copy the original config:
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak. Restore withsudo mv /etc/dhcpcd.conf.bak /etc/dhcpcd.confif needed. - Headless setup trick: If setting up headless, add Wi-Fi credentials *and* static IP settings to
/boot/dhcpcd.confon the microSD card *before first boot* (on Windows/macOS). This allows automatic connection with a static IP on first power-up.
Troubleshooting
If your Pi loses network access after setting a static IP:
- Check physical Wi-Fi status: Run
nmcli device statusor look forwlan0inip addr. If it showsNO-CARRIER, the Wi-Fi adapter isn’t connected—re-enter your SSID/password in/etc/wpa_supplicant/wpa_supplicant.confand restartwpa_supplicant. - Verify the static configuration: Re-run
cat /etc/dhcpcd.confand confirm yourinterface wlan0block has no typos (e.g.,static ip_addressnotstatic ipaddress). - Confirm router reachability: From the Pi, run
ping -c 4 192.168.1.1(replace with your gateway). No response means local network issues—check Wi-Fi password, router status, or try a wired connection to isolate the problem. - Test DNS resolution: If IP ping works but domain ping fails, edit
/etc/resolv.conftemporarily to addnameserver 8.8.8.8and retry. If DNS then works, your router’s DNS is misconfigured; use public DNS like Google (8.8.8.8) or Cloudflare (1.1.1.1). - Roll back changes: If stuck, restore the backup config:
sudo mv /etc/dhcpcd.conf.bak /etc/dhcpcd.conf, then reboot. Or remove your static block manually insudo nano /etc/dhcpcd.conf. - Check for conflicting services: Ensure
systemd-networkdisn’t enabled—it conflicts withdhcpcd. Runsudo systemctl is-enabled systemd-networkd; if active, disable withsudo systemctl disable systemd-networkdand reboot.
Frequently Asked Questions
Can I use a static IP over Ethernet instead of Wi-Fi?
Yes—simply replace interface wlan0 with interface eth0 in the /etc/dhcpcd.conf block. The rest of the configuration (IP, gateway, DNS) remains the same.
What if my router uses IPv6?
Raspberry Pi’s default dhcpcd handles IPv4 static IPs. For IPv6, you’d need additional configuration (e.g., static ip6_address=), but most home networks rely on IPv4 for local devices. Stick to IPv4 unless you specifically need IPv6.
Does setting a static IP affect my internet speed?
No—static IPs only fix the address assignment; they don’t alter bandwidth, latency, or throughput. Performance depends on your router, Wi-Fi signal strength, and ISP.
Can I assign different static IPs for different networks?
Not directly with static settings—you’d need to manually edit /etc/dhcpcd.conf each time you move the Pi. For dynamic switching (e.g., home vs. office), use DHCP reservations in each network or consider tools like connman.
Why does my Pi show two IP addresses for wlan0?
This usually means both static and DHCP addresses are assigned. Check /etc/dhcpcd.conf for duplicate entries (e.g., leftover inform lines) or if nohook resolv.conf is missing. Remove duplicates and restart dhcpcd.
Is it safe to use the router’s own IP as the static IP for the Pi?
Absolutely not—assigning the Pi the same IP as the router (192.168.1.1) will cause a conflict and break your entire network. Always pick an unused address outside the DHCP range.