Home » Setting a Static IP Address on Raspberry Pi with Examples (Complete 2026 Guide)

Setting a Static IP Address on Raspberry Pi with Examples (Complete 2026 Guide)

SBC Tutorials

Networking is a fundamental part of using a Raspberry Pi, especially in projects involving servers, remote access, IoT systems, and automation. By default, most Raspberry Pi devices obtain their IP address dynamically through DHCP (Dynamic Host Configuration Protocol). While this works well for general use, it can become problematic when consistency and reliability are required.

A static IP address ensures that your Raspberry Pi always has the same network address. This is crucial for applications such as hosting a web server, setting up SSH access, running a database, or managing IoT devices. Without a static IP, the address may change after reboot or network reconnection, making it difficult to locate and connect to the device.

This guide provides a comprehensive explanation of static IP addresses on Raspberry Pi, including multiple methods for setting them, practical examples, troubleshooting techniques, and best practices.

Understanding IP Addressing

An IP address is a number that is unique to each device on a network. It lets devices talk to each other.

There are two main types of IP assignment:

  • Dynamic IP (DHCP): Automatically assigned by a router
  • Static IP: Manually configured and remains constant

Most home networks use routers that give out IP addresses on the fly. This is easy to use, but it can change over time.

By giving the Raspberry Pi a fixed address, a static IP solves this problem.

Why Use a Static IP Address?

There are a number of good reasons to set up a static IP on a Raspberry Pi.

First, it makes sure that remote access works. A static IP lets you connect without having to check the current address if you are using SSH or VNC.

Second, it is very important for hosting services. Clients need a consistent address to connect to web servers, file servers, and databases.

Third, it makes setting up the network easier. Fixed IP addresses are needed for port forwarding, firewall rules, and DNS settings.

Lastly, it makes IoT systems more stable, where many devices talk to each other.

Methods for Setting a Static IP

There are two primary approaches to assigning a static IP address:

  1. Configuring the Raspberry Pi itself
  2. Reserving an IP address on the router

This article focuses on configuring the Raspberry Pi directly, which provides full control over network settings.

Method 1: Setting Static IP Using dhcpcd.conf

The most common method involves editing the dhcpcd configuration file.

Step 1: Open Configuration File

sudo nano /etc/dhcpcd.conf

Step 2: Add Static IP Configuration

Scroll to the bottom and add:

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

Explanation

  • interface eth0: Ethernet connection
  • ip_address: Desired static IP
  • routers: Default gateway (router IP)
  • domain_name_servers: DNS servers

Step 3: Save and Reboot

sudo reboot

Step 4: Verify IP Address

hostname -I

Method 2: Static IP for Wi-Fi

For wireless connections, use wlan0 instead of eth0.

Example

interface wlan0
static ip_address=192.168.1.110/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 1.1.1.1

Example 1: Static IP for Web Server

If you are hosting a web server, a static IP ensures consistent access.

Setup

sudo nano /etc/dhcpcd.conf

Add:

interface eth0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8

Restart and test:

ping 192.168.1.200

Now your web server can be accessed reliably.

Example 2: Static IP for SSH Access

For remote management:

ssh pi@192.168.1.150

Setting a static IP ensures this command always works without checking the address.

Example 3: Static IP for IoT Device

In IoT systems, devices often communicate with a central hub.

interface wlan0
static ip_address=192.168.1.50/24

This ensures the device remains accessible within the network.

Example 4: Multiple Interfaces

If both Ethernet and Wi-Fi are used:

interface eth0
static ip_address=192.168.1.101/24

interface wlan0
static ip_address=192.168.1.102/24

Understanding Subnet and CIDR

The “/24” in the IP address represents the subnet mask.

  • /24 = 255.255.255.0
  • Defines the network range

This determines how devices communicate within the network.

DNS Configuration Explained

DNS servers translate domain names into IP addresses.

Example:

static domain_name_servers=8.8.8.8 1.1.1.1

Using multiple DNS servers improves reliability.

Troubleshooting Static IP Issues

No Network Connection

  • Check IP conflicts
  • Verify gateway address
  • Ensure correct subnet

Cannot Access Internet

  • Check DNS settings
  • Verify router IP
  • Test with ping
ping 8.8.8.8

IP Conflict

Ensure the static IP is outside the DHCP range.

Best Practices

  • Choose IP outside DHCP range
  • Document assigned IPs
  • Use consistent naming
  • Backup configuration files

Advanced Configuration

Using Static IP with DHCP Reservation

Instead of configuring on the Pi, assign IP via router.

Changing Hostname

sudo hostnamectl set-hostname mypi

Editing Hosts File

sudo nano /etc/hosts

Security Considerations

  • Use firewall rules
  • Disable unused ports
  • Secure SSH access

Advantages of Static IP

  • Reliable connectivity
  • Easier remote access
  • Better for servers
  • Simplifies networking

Limitations

  • Requires manual setup
  • Risk of conflicts
  • Less flexible than DHCP

Real-World Applications

Static IP is essential in:

  • Web hosting
  • Home automation
  • Surveillance systems
  • IoT networks
  • Database servers

Conclusion

Setting a static IP address on a Raspberry Pi is an important first step in making network-based projects that are reliable and can grow. Dynamic IP addresses are useful, but they don’t have the stability that advanced applications need.

Setting up a static IP address makes sure that your Raspberry Pi is always reachable, which makes it easier to access it from a distance, manage servers, and talk to other devices.

This guide gives you the information and examples you need to confidently set up and manage static IP addresses for a wide range of projects. If you want to work with Raspberry Pi in networking, automation, or IoT settings, you need to be able to do this.

You may also like