How to set up static IPs in Raspbian Raspberry Pi?

Here are two ways to set up a static IP for Raspberry Pi:

Way #1

Using the router's settings, assign IP constants for a given MAC number (the number can be downloaded, e.g. using the command ifconfig).

Way #2

By setting a fixed IP address in the Raspberry Pi configuration files. To do this, change the file using, for example, a nano text editor by entering a command in the terminal:

sudo nano /etc/dhcpcd.conf


By default, IPs are downloaded from the DHCP server, to set up a static IP for the Ethernet and WiFi connection, the following code must be added at 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 leave the text editor (Ctrl+X) confirming the overwriting of the file with the letter "Y".

After reboot we will have a static IP set for the cable connection. For a WiFi connection, the file must be modified:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


by adding the following entry:

network={

ssid="NAME_SIGNAME"

psk="PASSWORD"

}


Explanation:
ssid - network identifier
psk - network password


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


sudo reboot


From now on, our raspberry has a fixed IP, which can be checked at any time using the ifconfig command .

In order to check if everything has been configured correctly, call from any


ping 192.168.1.201


of course changing the IP to the one established in the previous configuration.

Botland.store - shop for makers!