Static IP adress

Before that, you will need some information on your current network setup so you can add the required details to the configuration file. You will require the following info:

• The type of network connection. This is either wlan0 if your Raspberry Pi is connected to the router wirelessly, or eth0 if it’s connected using an Ethernet cable.

• The Raspberry Pi’s currently assigned IP address – it’s safest to reuse this for its static IP so that you can be sure the latter hasn’t already been to another device on the network. If not, make sure another device isn't already using it.

To find the Raspberry Pi’s current IP address, enter the following command in a Terminal window:

hostname -I

• Your router’s gateway IP address – the one used to contact it from the local network, not its public IP. It varies depending on the router model, but typically starts with 192.168.

To find it, enter the following command and note the first IP address given:

ip r | grep default

• Your router’s DNS (Domain Name System) IP address. This is typically the same as its gateway address, but may be set to another value to use an alternative DNS – such as 8.8.8.8 and 8.8.4.4 for Google.

To find the current DNS IP address, enter the command:

sudo nano /etc/resolv.conf


Note the IP address after nameserver – that's the DNS address – and then press Ctrl + X to close the file.


Now you have found all your network connection information, it’s time to edit the dhcpcd.conf configuration file to add the settings you need to set up a static IP address for your Raspberry Pi:

sudo nano /etc/dhcpcd.conf

At the end of the file insert these data and change accordingly your needs

interface eth0 or wlan0

static ip_address=192.168.178.29/24

static routers=192.168.178.1

static domain_name_servers=8.8.8.8 8.8.4.4

With the dhcpcd.conf configuration file modified, restart your Raspberry Pi to effect the changes and set the static IP address for it:

sudo reboot

Rather than using an address assigned automatically by DHCP, the Raspberry Pi will now attempt to connect to the router using the new static IP address that you set in the dhcpcd.conf file.

To check that it is working correctly, enter the following command:

hostname -I

You should now see the static IP address that you set in the dhcpcd.conf configuration file.