Complete Guide to Setting a Static IP on Raspberry Pi: Enhance Network Stability and Access

Complete Guide to Setting a Static IP on Raspberry Pi: Enhance Network Stability and Access

April 22, 2024

DALL·E 2024-04-22 16.59.13 - A realistic blog cover image for a post about setting a static IP address on a Raspberry Pi. The cover features a Raspberry Pi device prominently disp(1).png__PID:2ca1e43d-bd09-445f-a941-dc0008cde723

When you set a static IP address for your Raspberry Pi, you're essentially assigning it a fixed address that doesn't change, unlike a dynamic IP that can change each time the device connects to the network.

Setting a static IP address on a Raspberry Pi can be beneficial for several reasons:

Consistent Access

With a static IP, you always know the IP address of your Raspberry Pi. This makes it easier to access services running on the Pi (like a web server, SSH or VNC) because the address doesn't change.

图片1.png__PID:0cc8be85-c494-411c-8312-437ce5a050c6

Network Stability

Dynamic IPs can change each time a device reconnects to the network, which can cause interruptions in services. A static IP ensures that the Raspberry Pi maintains a stable connection with a fixed address.

Port Forwarding

If you want to access your Raspberry Pi from outside your local network (for example, over the internet), you'll likely need to set up port forwarding on your router. Having a static IP simplifies this process because you don't have to update the forwarding rule whenever the IP changes.

Example with remote access to a Raspberry Pi with static ip: 192.168.1.124 via VNC from internet.

图片2.png__PID:c8be85c4-9451-4cc3-9243-7ce5a050c648

Server Hosting

If you're hosting services or applications on your Raspberry Pi (like a media server or a web server), a static IP ensures that clients can always reach your Pi using the same address.

Networked Device

If you have multiple devices on your network that need to communicate with the Raspberry Pi (such as IoT devices or other computers), a static IP makes it easier to configure network settings and establish reliable connections.

Network Monitoring and Management

For network administrators or enthusiasts who want more control over their network infrastructure, assigning static IPs allows for better organization, monitoring, and management of devices.

To set a static IP address on a Raspberry Pi running Raspberry Pi OS, you must know 5 fundamental parameters:

interface_name: This is typically eth0 for Ethernet or wlan0 for Wi-Fi.

static_ip_address: Enter the desired static IP address for your Raspberry Pi.

static_router: Enter the IP address of your router or gateway.

static_dns: Specify the DNS server's IP address. You can use a public DNS like Google's (8.8.8.8) or your router's DNS.

By Terminal

图片3.png__PID:be85c494-511c-4312-837c-e5a050c64816

1.Open Terminal:

You can either connect directly to your Raspberry Pi via SSH or open a terminal window if you're using a monitor and keyboard connected to the Pi.

2.Edit dhcpcd.conf:
sudo nano /etc/dhcpcd.conf

Use the following command to open the dhcpcd.conf file in a text editor (e.g., nano):

3.Configure Static IP

Scroll to the bottom of the file and add the following lines (replace interface_name,
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8


static_ip_address, static_router, and static_dns with your desired values):

4.Save and Exit:

After making changes, press Ctrl + X, then Y to confirm saving, and press Enter to exit nano.

5.Restart dhcpcd:
sudo systemctl restart dhcpcd

To apply the changes, restart the dhcpcd service with the command:

6.Verify IP Configuration:
ip addr show

Check if the static IP is configured correctly by running:

After completing these steps, your Raspberry Pi should now have a static IP address configured. You can test the connectivity to ensure everything is working as expected.

By GUI

1.Open the panel Wireless & Wired Network Settings

图片4.png__PID:85c49451-1cc3-4243-bce5-a050c64816aa

2.Select the Interface and complete IPv4, Router and DNS Servers

图片5.png__PID:c494511c-c312-437c-a5a0-50c64816aa7e

3.Clic Apply and reboot

Pironman 5 Launching Soon: Raspberry Pi 5's Newest NVMe Case – Exclusive Discounts for Group Members! Back to News How to Update Raspberry Pi OS