RaspberryPi

How to set a static IP address for RaspberryPi

This article shows you how to set a static IP address of RaspberryPi.

By fixing the IP address, you can remote-control the RaspberryPi through SSH connection or VNC connection with the same IP address
every time.

Contents

  • How to check current IP address
  • How to check current IP addresses can be used for a static IP address
  • How to check the IP address of the default gateway and DNS server
  • Two methods of setting a static IP address for Raspberry pi :
    1. Adding to configuration file
    2. Setting from the desktop icon

sponsored link

How to check current IP address

First, I will show you how to check current IP address.

Enter the following command in the terminal.

$ ifconfig

( Sorry, Japanese is included. )

For wireless LAN, the current IP address is displayed in "wlan0".

"192.168.11.11" after "inet" is the IP address.

sponsored link

How to check current IP addresses can be used for a static IP address

I will show you how to check current IP addresses can be used for a static IP address.

By using ping command, you can check if the IP address is already in use.

By using ping command, the responses from that IP address and the response time are displayed.

Let's check "192.168.11.11" and "192.168.11.12".

"192.168.11.11" is the IP address that RaspberryPi is currently using.

Enter the following command in the terminal.

$ ping 192.168.11.11

This IP address is in use because a response time is indicated.

Since the command will continue to be sent, stop it with "ctrl + C" after checking responses.

Next, check "192.168.11.12".

Enter the following command in the terminal.

$ ping 192.168.11.12

This IP address is not used because the signal is not reaching the host.

I will set up "192.168.11.12" as static IP address.

sponsored link

How to check the IP address of the default gateway and DNS server

The IP addresses of the default gateway and DNS servers are also required to set up static IP address.

Therefore, the IP addresses of the default gateway and DNS servers must also be checked.

Two methods are presented, one using RaspberryPi and the other using Windows PC.

~ Using RaspberryPi ~

Enter the following command in the terminal.

$ route -n
Check the default gateway using RaspberryPi.

( Sorry, Japanese is included. )

Under "Gateway," the IP address of the default gateway is displayed.

The default gateway in the author's environment is "192.168.11.1".

The default gateway and DNS servers have the same IP address because the router also serves those functions.

~ Using WindowsPC ~

RasberryPi and Windows PC are connected to the same Wi-Fi, so they share the same default gateway.

Enter the following command at the Windows PC command prompt.

ipconfig /all

( Sorry, Japanese is included. )

default gateway : 192.168.11.1
DNS server : 192.168.11.1

sponsored link

How to set a static IP address for Raspberry pi

I will explain two methods of setting.
1. Adding to configuration file
2. Setting from the desktop icon

Adding to configuration file

I will show you setting static IP address by editing the configuration file.

Open the configuration file by using "nano", the standard RaspberryPi editor.

Enter the following command in the terminal.

$ sudo nano /etc/dhcpcd.conf

After opening the file, scroll to the bottom and add the following items.

  • static ip_address
  • static routers
  • static domain_name_servers

( Sorry, Japanese is included. )

Writing : 「ctrl + O」 → Enter

close : 「ctrl + X」

Reboot to reflect settings.

$ reboot

Check if static IP address is reflected.

$ ifconfig

Setting from the desktop icon

I will show you setting static IP address from the desktop icon.

Right-click the network icon at the top of the RaspberryPi desktop screen.

Then, click on "Wireless & Wired Network Settings".

( Sorry, Japanese is included. )

Next, click on the "empty cell" to the right of "interface".

For wireless LAN, select "wlan0".

( Sorry, Japanese is included. )

Uncheck "Automatically configure empty options" and enter the IP address manually.

Enter the IP address, default gateway, and DNS server.

Note that "/24" in the IP address field can be omitted.

( Sorry, Japanese is included. )

Reboot to reflect settings.

$ reboot

Check if static IP address is reflected.

$ ifconfig

sponsored link

-RaspberryPi
-