← Back to Garden
evergreen ·
raspberry-pi networking linux

Raspberry Pi: Static IP Configuration

This document covers the foundational step of preparing a Raspberry Pi for a server role by assigning it a static IP address.

The Goal

Any server on a network (like our future DNS server) needs a permanent, predictable address. If its IP address changed every time it rebooted, other devices wouldn't know how to find it. This process removes the Pi from the router's automatic (DHCP) IP assignment pool and gives it a fixed address.

The Process

The setup was performed on a Raspberry Pi running Raspberry Pi OS, which uses dhcpcd for network configuration.

1. Initial Connection

After flashing the OS with SSH enabled, the first step was to connect to the Pi.

  • Find the IP: The Pi was initially assigned a dynamic IP by the router. It was found by running ping raspberrypi.local from another machine on the network.
  • Connect via SSH: An SSH connection was established using the discovered IP: ssh pi@[initial-dynamic-ip]

2. Configuring the Static IP

The configuration is done by editing the /etc/dhcpcd.conf file.

sudo nano /etc/dhcpcd.conf

The following block was added to the end of the file:

# Define the static IP configuration for the wired network interface
interface eth0
static ip_address=192.168.1.13/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1

Explanation of a Static IP Configuration

Here's a breakdown of each line added to the /etc/dhcpcd.conf file, which is a crucial step in setting up a reliable server on a local network:

  • interface eth0: This line specifies that the configuration applies only to the eth0 network interface. On a Raspberry Pi, eth0 is typically the built-in Ethernet (wired) port. This ensures that these settings don't accidentally apply to the wireless interface (wlan0).

  • static ip_address=192.168.1.13/24: This is the core of the configuration.

    • ip_address=192.168.1.13: This assigns the fixed IP address 192.168.1.13 to the Raspberry Pi.
    • /24: This is the CIDR (Classless Inter-Domain Routing) notation for the subnet mask. /24 corresponds to a subnet mask of 255.255.255.0, defining the local network as 192.168.1.x.
  • static routers=192.168.1.1: This line tells the Raspberry Pi the IP address of the gateway. The gateway is the device (usually your main router) that connects the local network to the internet. When the Pi needs to send traffic to an external network, it sends it to this address.

  • static domain_name_servers=1.1.1.1: This sets the upstream DNS server for the Raspberry Pi itself.

    • When the Pi needs to look up an IP address (e.g., when downloading software with apt or pacman), it will ask the server at 1.1.1.1 (Cloudflare's public DNS).
    • This is important because our Pi-hole isn't installed yet. Once Pi-hole is running, Pi-hole itself will use an external DNS server, and all other devices on the network will use the Pi for their DNS needs. This line ensures the Pi can resolve domains during its own setup.

3. Applying the Configuration

The networking service needs to be restarted for the changes to take effect. A simple reboot accomplishes this and confirms the settings persist.

sudo reboot

After the reboot, a new SSH connection was established to the Pi's new, permanent address: ssh pi@192.168.1.13.

Next Steps

The Raspberry Pi is now ready for its server software. The next step is to install Pi-hole.