A static IP address is the opposite of a dynamic IP and it’s doesn’t change. To access raspberry pi with other devices over a long period of time and it’s needing a static IP address. Using the below command to check whether DHCPCD is already activated or not.
sudo service dhcpcd status
Here DHCPCD was activated. but if DHCPCD is not activated and follows the below commands.
sudo service dhcpcd start
sudo systemctl enable dhcpcd
Confirm the original status of the configuration of the file /etc/network/interfaces. the ‘iface’ configuration needs to be set at ‘manual’ for the interfaces. After a dhcpcd activation, run the below command to edit the dhcpcd.conf configuration file to set up a static IP for your Raspberry Pi.
sudo nano /etc/dhcpcd.conf
- The type of network connection is:
- wlan0 – Raspberry Pi is connected to the router wirelessly.
- eth0 – Raspberry Pi connected using an Ethernet cable.
- Scroll down to the bottom of the file and add below file.
Interface wlan0 // for wifi connection.
- static ip_address=192.168.0.XXX/24 // To change “X” value only.
- static routers=192.168.0.1
- static domain_name_servers=192.168.0.1
- To exit the editor, press “ctrl+x” and press the letter “Y” then hit enter.
- Now reboot a raspberry pi, and everything should be set.
Finalizing the Static IP
- The new static IP is assigned to the Raspberry Pi from the dhcpcd.conf file.
- Use the below command to check that it is working correctly.
Now the new static IP address is assigned to the raspberry pi.