How to Set Static IP on Raspberry Pi Quickly and Easily
To set a static IP on Raspberry Pi, edit the
/etc/dhcpcd.conf file and add your static IP configuration at the end. Then restart the networking service or reboot the Pi to apply the changes.Syntax
The static IP configuration is added in the /etc/dhcpcd.conf file using this pattern:
interface [interface_name]: specifies the network interface (e.g., eth0 for wired, wlan0 for Wi-Fi).static ip_address=[IP_address]/[subnet_mask]: sets the static IP and subnet mask.static routers=[gateway_IP]: sets the default gateway IP.static domain_name_servers=[DNS_IPs]: sets DNS servers for name resolution.
bash
interface eth0 static ip_address=192.168.1.100/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 8.8.8.8
Example
This example sets a static IP for the wired interface eth0 to 192.168.1.100 with a subnet mask of 255.255.255.0, gateway 192.168.1.1, and DNS servers 192.168.1.1 and Google's 8.8.8.8.
After editing, restart the service or reboot to apply.
bash
# Open the dhcpcd.conf file with sudo privileges sudo nano /etc/dhcpcd.conf # Add these lines at the end of the file interface eth0 static ip_address=192.168.1.100/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 8.8.8.8 # Save and exit (Ctrl+X, then Y, then Enter) # Restart dhcpcd service to apply changes sudo systemctl restart dhcpcd # Or reboot the Raspberry Pi sudo reboot
Output
No output if successful; network will use static IP after restart.
Common Pitfalls
- Wrong interface name: Use
ifconfigorip ato check your interface name (e.g.,eth0orwlan0). - IP conflicts: Choose an IP outside your router's DHCP range to avoid conflicts.
- Incorrect subnet mask: Use CIDR notation like
/24for 255.255.255.0. - Forgetting to restart: Changes won't apply until you restart the dhcpcd service or reboot.
bash
## Wrong way (missing interface line) # static ip_address=192.168.1.100/24 # static routers=192.168.1.1 # static domain_name_servers=192.168.1.1 8.8.8.8 ## Right way interface eth0 static ip_address=192.168.1.100/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 8.8.8.8
Quick Reference
Remember these key points when setting a static IP on Raspberry Pi:
- Edit
/etc/dhcpcd.confto configure static IP. - Use correct interface name (
eth0for wired,wlan0for Wi-Fi). - Set IP address with subnet mask in CIDR format (e.g.,
192.168.1.100/24). - Specify router (gateway) and DNS servers.
- Restart networking service or reboot to apply changes.
Key Takeaways
Edit /etc/dhcpcd.conf to set static IP by specifying interface, IP, router, and DNS.
Use the correct network interface name to avoid configuration errors.
Choose an IP outside your router's DHCP range to prevent address conflicts.
Restart the dhcpcd service or reboot the Raspberry Pi to apply changes.
Verify settings with commands like ip a after reboot to confirm static IP is active.