Categories

How to set a static IP in Raspberry Pi

How to set a static IP in Raspbian OS Raspberry Pi?

 

The following describes two ways to set a static IP for the Raspberry Pi:

 

Method #1

Using the settings of the router to assign a static IP to the MAC room (room can be downloaded, for example, with the command ifconfig).

 

Method #2

Setting a permanent IP address in the configuration files of the Raspberry Pi. For this you need to change the file using for example nano text editor by typing the command in the terminal:


sudo nano /etc/dhcpcd.conf


The default IP is loaded from the DHCP server to set static IP to connect via Ethernet and wi-fi, you must add the following code to the end of the file:


interface eth0

static ip_address=192.168.1.101/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0

static ip_address=192.168.0.201/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1


Then save the file and exit the text editor (Ctrl+X) confirming the overwriting of the file by the letter "Y".

After the restart we will set a static IP for the cable connection. To connect via wi-fi you need to make changes to the file:


sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


adding the following entry:


network={

ssid="NAZWA_SIECI"

psk="PASSWORD"

}


Explanation:
ssid – network identifier
psk password is the network


After the changes save the file and exit the text editor (Ctrl+X).


sudo reboot


Now our raspberry already has a permanent IP, which you can check in any time with the command ifconfig.

In order to check if all is configured correctly, you must call from any


ping 192.168.1.201


of course, changing the IP specified in the earlier configuration.