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.
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.
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.
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.
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.
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.
You will see that the static IP address for raspberry pi is configured as you set in dhcpcd.conf file.