How To Setup a Static IP Address on Raspberry Pi – Guide

In this Raspberry Pi Static IP tutorial, we will show you how to configure your Raspberry Pi’s network so that it uses a static IP address. We’ll force the Pi to use a static IP by making modifications to the Raspberry Pi’s DHCP client daemon. This software controls how the operating system handles IP addresses. By modifying the DHCPCD configuration file, we can tell the software the local IP address it should use when connecting to the network. In addition to setting up your static IP on your router too, we recommend that you set it up on your computer too.

What is an IP address?

An IP address is unique to a device on a computer network or the Internet. It is written in ‘dot-decimal’ notation, with four decimal numbers separated by dots. An example is 192.168.1.107.

To keep the Raspberry Pi’s IP address unchanged when it reboots, you can use a command line tool to do this. This tool is called “raspberrypi-update”. To use it, type the following command at a prompt: raspberrypi-update

Private IP vs. public

Public IP addresses are used to identify your local network on the wider Internet. They usually change every time your router connects to the internet, although you can make it static depending on your internet service provider. You can find the public IP address on a Linux system by typing a special Terminal command or simply doing a web search for ‘What is my IP?’. It’s only necessary if you intend to connect to a device outside your network, which we won’t cover here. ..

To set a static IP of the Raspberry Pi, you will need to first create a new network connection and then set up your router. Once you have connected to the network and your router, open your router’s settings and add a new device - for example, the Raspberry Pi. In the “IP Address” field, enter 192.168.1.10 as the address. This will give your Raspberry Pi a unique IP address on its own local network.

DHCP configuration

The Raspberry Pi OS (formerly known as Raspbian) uses DHCP (Dynamic Host Configuration Protocol) to automatically assign an IP address to the Raspberry Pi whenever it reboots. This address is used by the Raspberry Pi to access the internet and other devices on the network. ..

To always use the same static IP address when connecting to the network, you will need to modify the DHCP client daemon configuration file, dhcpcd.conf. ..

-Your network’s name -The type of network (wired or wireless) -The address of your router or modem -The type of network connection you are using (wired, wireless, or cable) -The channels that your network is using (2, 4, 6, 8) -The time zone of your location (UTC/GMT+8) To add the necessary details to the configuration file for your current network configuration:

  1. Log in to your account on the website and open the Configuration Settings page.
  2. In the left hand column, click on Networking and then click on Add Network.
  3. In the Add Network dialog box, enter your name and type in the address of your router or modem. The information below will be displayed:
  4. Click on OK to add the new network connection and close the dialog box.

• If your Raspberry Pi is connected to the wireless router, it will use the wlan0 network connection. If it is connected using an Ethernet cable, it will use eth0.

The IP address currently assigned to the Raspberry Pi is safer to reuse because it has been used by other devices on the network and it’s not likely to be reused again. If another device is using the IP address, it needs to be checked.

ip addr show raspberrypi This will output the Raspberry Pi’s current IP address.

Your router’s gateway IP address is the one that your ISP uses to contact you from the local network.

ip addr The ip addr command returns the list of all IPv4 addresses in a given network.

The DNS IP address of your router. This is typically the same as the gateway address, but can be set to another value to use an alternate DNS, such as 8.8.8.8 for Google or 1.1.1.1 for Cloudflare

nslookup [domain name] For example, to lookup the IP address for “google.com,” you would enter: nslookup google.com ..

Add static IP settings

Edit the dhcpcd.conf file and add the following lines to your configuration: interface eth0 { address 192.168.1.1; } interface eth1 { address 192.168.2.1; } interface eth2 { address 10.0.0.2; } Save the file and reboot your Raspberry Pi for the changes to take effect: sudo reboot

This is a sample network file.

To edit it, first create a new file and save it as “network.txt”

Then open network.txt in your text editor and replace the names in bold with your own. ..

Your network connection type is either Ethernet or wireless. ..

The Raspberry Pi needs a static IP address in order to be accessible from the outside world. This address will be used by the Raspberry Pi to connect to the internet. ..

Your router’s gateway IP address is the IP address that your router uses to connect to the local network. This information can be found on your router’s documentation or in the router’s settings.

DNS_Hostname – the hostname of the DNS server.

configure " static IP 192.168.1.120 " set " wireless network 192.168.1.254 "

After entering the settings, press Ctrl + X and then Y and ENTER to close and save the new configuration file.

Restart the Raspberry Pi

sudo reboot cd /etc/dhcpcd.conf sudo nano dhcpcd.conf server “192.168.1.1” { address “192.168.1.2” } server “192.168.2.1” { address “192.168.2.”

dhcpcd -i 192.168.1.1 This will give you a list of all the devices on your network, including the Raspberry Pi, that have been assigned an IP address by DHCP. You can then check to see if the Raspberry Pi is connected to this address by typing the following command: ping 192.168.1.1

You should now see the static IP address defined in the dhcpcd.conf configuration file.

Final note

This guide will show you how to set up a static IP address on a Raspberry Pi. This is useful if you want to keep your Pi permanently connected to the same network, or if you just want to make it easier to access from one location. ..