Setting up static IP on Raspberry PI | Raspberry PI home server series | Article 2

This is the second article in the Raspberry PI home server series. Check out other articles in this series.

Astitva Sood
3 min readAug 7, 2021
  1. Installing Docker on Raspberry Pi.
  2. Setting up static IP on Raspberry Pi.

In this article, we will be configuring static IP for our Raspberry Pi.

An IP address is a unique address that identifies a device on the internet or a local network. By default, this IP address will be dynamic, meaning it will keep on changing after a certain time. For most networks, the IP addresses are assigned by the DHCP server, running on the modem.

A DHCP Server is a network server that automatically provides and assigns IP addresses, default gateways, and other network parameters to client devices. It relies on the standard protocol known as Dynamic Host Configuration Protocol or DHCP to respond to broadcast queries by clients.

Raspberry PI running on Raspberry OS comes with the DHCPCD DHCP client. This client is responsible for communicating with the DHCP server and setting the IP address on the device. We will be changing the configuration of this client and set a default static IP address.

Tested on raspberry pi 4 running on Raspberry Pi OS on August, 2021

Steps:

  1. Collect network-related information.
  2. Change the configuration
  3. Reboot
  4. Verify

1. Collect network-related information:

Among the different roles of DHCPCD client, are setting network-related configurations like DNS and router’s IP address. Since we are setting static IP, we need to add these configurations manually.

Run the following commands to get these configurations.

ip r | grep default

Note down the IP address in the output string, this is the IP of your router. Also, note the interface in the output string

Next, we need DNS IP. For this, run the command

sudo cat /etc/resolv.conf

Note down this IP as the DNS IP.

2. Change the configuration of DHCPCD client

Now we are ready to change the configuration of our DHCP client. We need to add the following lines in the /etc/dhcpcd.conf file.

interface wlan0static ip_address=192.168.1.100/24static routers=192.168.1.1static domain_name_servers=192.168.1.1

Open the file /etc/dhcpcd.conf in your favorite text editor and add the lines as above.

3. Reboot

Now, we need to reboot the Raspberry Pi. This will flush out the old configuration and load the new one. To reboot, run the following command:

NOTE: If you are connected to Raspberry PI via SSH connection, use the new IP to SSH again.

sudo reboot

4. Verification

To verify that the configuration has successfully taken effect, run the following command

hostname -I

This will give a list of IP addresses, make sure that that IP you assigned statically is part of the list.

--

--

Astitva Sood
Astitva Sood

Written by Astitva Sood

0 Followers

Raspberry PI | Linux

No responses yet