How to Set-up a Static IP Address for Raspberry Pi?

set-up-a-static-ip-address-for-raspberry-pi
Spread the love

If you’re using your Raspberry Pi as a NAS server or you need to access raspberry pi remotely from anywhere by ensuring the device’s private IP address does not change.  you’ll have to find it at the same Raspberry Pi static IP address every time, rather than a new address being set dynamically whenever raspberry pi is rebooted. Setting up a static IP on Raspberry Pi is necessary to avoid access issues.

This tutorial shows you the quick process to set-up a static IP address for Raspberry Pi to make it permanent.

Set-up a Static IP Address for Raspberry Pi

Follow the steps below and enter the following command in a raspberry pi terminal to configure a static IP address for Raspberry Pi system.

Step 1: To find the Raspberry Pi’s current IP address.

hostname -I

Note down the IP address which is displayed in the command output.

Step 2: To find the IP address of the default interface.

ip r | grep default

Note down the router’s address displayed in the command output.

The screenshot below shows the router’s address.

Set-up a Static IP Address for Raspberry Pi-1

Step 3: To find the name of the network interface.

route | grep '^default' | grep -o '[^ ]*$'

Note down the name of the network interface.

The screenshot below shows the name of the network interface.

Set-up a Static IP Address for Raspberry Pi-2

Step 4: To find the router DNS IP address

Open the resolv.conf file in a text editor.

sudo nano /etc/resolv.conf

Look for the line that starts with the word nameserver and write down the DNS IP address.

The screenshot below shows the DNS IP address.

Set-up a Static IP Address for Raspberry Pi-3

Step 5: Set up Static IP Address via CLI

Open the dhcpcd.conf file in a text editor.

sudo nano /etc/dhcpcd.conf

Add the lines below with the information you obtained in the previous steps.

interface [interface-name]
static ip_address=[ip-address]/[cidr-suffix]
static routers=[router-ip-address]
static domain_name_servers=[dns-address]

The screenshot below shows an example configuration.

Set-up a Static IP Address for Raspberry Pi-4

Save the file and exit.

Step 6: Reboot Raspberry Pi using the following command.

sudo shutdown -r now

After the system boots up, your Raspberry Pi system will be configured to a static IP address.

Step 7: To check if it is working correctly or not, enter the following bellow command.

hostname -I

You will see that the static IP address for raspberry pi is configured as you set in dhcpcd.conf file.

Also Read: How To Build Your Own Raspberry Pi NAS Server using Samba


Spread the love

Be the first to comment

Leave a Reply

Your email address will not be published.


*