This Answer is technically incorrect.
You should follow How to set up networking/WiFi
or if you really want Static IP How to set up Static IP Address
This is not a direct answer but going to be useful to anyone trying to set up their raspberry pi to use static IP, because /etc/dhcpcd.conf will in fact change the IP of raspberry PI, even if you set a static profile, if another device is using that IP on the network. This can be a big security issue for some projects.
In addition to disabling dhcpcd using systemctl, you can set a static IP by editing /etc/network/interfaces
The latest Raspbian distributions ship with this file empty, but I tested that after disabling dhcpcd, you can set the static IP you want to use by adding this to the end of /etc/network/interfaces
file
auto eth0
iface eth0 inet static
address 192.168.1.51
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255
dhcpcd
] is a bad idea (...) you should get used tosystemd
→systemd
hassystemd-networked
, which requires disablingdhcpcd
. – WoJ Jul 16 '22 at 14:54