Things You Will Need
To follow this article, you will need the following:
- Raspberry Pi 3 or Raspberry Pi 4
- Micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter
- 16 GB or 32 GB microSD card with Raspberry Pi OS flashed
- Network connectivity on the Raspberry Pi
- Laptop or desktop computer for VNC remote desktop access or SSH access
NOTE: If you do not want to access your Raspberry Pi system remotely via SSH or VNC, you will need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi system, as well. I will not need any of these, as I will be connecting to my Raspberry Pi system remotely via VNC or SSH. My setup is called the headless setup of Raspberry Pi.
If you need any assistance with flashing the Raspberry Pi OS image on the microSD card, check out the article How to Install and Use Raspberry Pi Imager at linuxhint.com.
If you are a Raspberry Pi beginner and you need assistance installing Raspberry Pi OS on your Raspberry Pi system, check out the article How to Install Raspberry Pi OS on Raspberry Pi 4 at linuxhint.com.
Also, if you need any assistance with the headless setup of Raspberry Pi, check out the article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor at linuxhint.com.
Configuring Static IP Addresses Graphically
If you are running Raspberry Pi OS in a desktop environment, you can configure a static IP address for your desired network interface very easily from the graphical desktop environment.
Right-click (RMB) on the network icon and click Wireless & Wired Network Settings.
Make sure that interface is selected in the dropdown menu.
Click the empty dropdown menu, as marked in the screenshot below.
Select the network interface you want to configure.
eth0 – the wired ethernet network interface.
wlan0 – the wireless (Wi-Fi) network interface.
Suppose you want to configure the wlan0 Wi-Fi network interface of your Raspberry Pi system.
After selecting the network interface you want to configure, you should see the following window.
Type in your desired static IP address, gateway (Router) address, DNS server address, etc.
If you want, you can also type the IP address in CIDR notation, like 192.168.0.110/24. Here, 24 is the subnet mask length. 24 is equivalent to the subnet mask 255.255.255.0.
To add multiple DNS server addresses, simply separate them with a space, as shown in the screenshot below.
If you only know the IP address you want to set and nothing else about your home or office network, then selecting Automatically configure empty options will request the network configuration from a DHCP server, and will only configure the network information that you did not specify here.
If you know all the required network information, I recommend that you uncheck Automatically configure empty options, as this eliminates the need for a DHCP server on the network.
If you do not need IPv6, check the Disable IPv6 option.
Once you are done, click Apply.
Then, click Close to exit the Network Preferences window.
For the changes to take effect, reboot your Raspberry Pi system with the following command:
Once your Raspberry Pi boots, your desired static IP address should be set on your desired network interface.
You can confirm this with the following command:
Configuring Static IP Addresses via Command-Line
If you are running the minimal version of the Raspberry Pi OS (without any graphical desktop environment) on your Raspberry Pi, then you will not have access to any graphical tools to configure static IP addresses, as shown in an earlier section of this article.
Worry not! From the command line, configuring a static IP address on the wired (eth0) or wireless (wlan0) network interface of your Raspberry Pi system is very easy. In this section, I will show you how to do just that.
First, open the dhcpcd.conf configuration file with the nano text editor as follows:
To configure a static IP address for the wireless (Wi-Fi) network interface (wlan0), add the following lines at the end of the file.
static ip_address=192.168.0.110/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 4.4.4.4
static domain_search=
noipv6
NOTE: Make any necessary adjustments to the configuration (i.e., change IP address, change router/gateway address, change DNS servers) depending on your desired network configuration.
To configure a static IP address for the wired Ethernet network interface (eth0), add the following lines to the end of the file.
static ip_address=192.168.0.111/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 4.4.4.4
static domain_search=
noipv6
NOTE: Make any necessary adjustments to the configuration (i.e., change IP address, change router/gateway address, change DNS servers) depending on your desired network configuration.
Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the dhcpcd.conf configuration file.
For the network configuration changes to take effect, reboot your Raspberry Pi with the following command:
Once your Raspberry Pi boots, your desired static IP address should be set on your desired network interface.
You can confirm this with the following command:
Conclusion
This article showed you how to set up a static IP address on the wired and wireless (Wi-Fi) network interface of your Raspberry Pi system running the Raspberry Pi OS. I have shown both the graphical method and the command-line method of configuring a static IP address in Raspberry Pi.