How Do I Set a Static IP Address on Raspberry Pi?
The Raspberry Pi is a popular microcomputer that has various applications, including as a media center, a web server, an automation controller, and many others. By default, the Raspberry Pi is configured to use dynamic IP addressing, which means that the IP address gets assigned automatically by a DHCP server when the device is connected to a network. However, in some situations, such as when running a server or remotely accessing the device, it’s better to set a static IP address on Raspberry Pi. Setting a static IP address on Raspberry Pi is easy, and in this article, we’ll show you how to do it.
Step 1: Identify the Network Interface
Before setting a static IP address on Raspberry Pi, you need to identify the network interface that you want to assign the IP address to. The Raspberry Pi typically comes with two network interfaces – Ethernet and Wi-Fi. If you’re using an Ethernet cable to connect to your network, then you’ll be using the eth0 interface. On the other hand, if you’re using Wi-Fi, then you’ll be using the wlan0 interface.
You can identify your network interface by running the following command in the terminal:
“`shell
ifconfig
“`
Step 2: Edit the dhcpcd.conf File
The dhcpcd.conf file is the configuration file for the DHCP client on Raspberry Pi. To set a static IP address, you need to edit this file. Open the file by running the following command in the terminal:
“`shell
sudo nano /etc/dhcpcd.conf
“`
Go to the end of the file and add the following lines for the network interface that you want to
configure:
“`shell
interface [interface_name]
static ip_address=[IP_address]/[subnet_mask]
static routers=[router_IP_address]
static domain_name_servers=[DNS_server_IP_address]
“`
Replace the [interface_name], [IP_address], [subnet_mask], [router_IP_address], and
[DNS_server_IP_address] placeholders with the appropriate values.
For example, if you want to set a static IP address on the Ethernet interface, you should add the
following lines:
“`shell
interface eth0
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
“`
Save and close the file by pressing Ctrl+X, followed by Y and Enter.
Step 3: Restart the dhcpcd Service
To apply the changes you’ve made to the dhcpcd.conf file, you need to restart the DHCP client. Run the following command in the terminal:
“`shell
sudo systemctl restart dhcpcd
“`
This will restart the dhcpcd service and apply the new configuration.
Step 4: Verify the Static IP Address
To verify that the static IP address has been set correctly, run the following command in the terminal:
“`shell
ifconfig
“`
You should see the network interface with the static IP address that you’ve just configured.