Site icon AranaCorp

Setting up a fixed IP address for your Raspberry Pi

For some projects, it may be necessary to configure a fixed IP address for your Raspberry Pi. This is because a dynamic IP address can be changed each time the power is switched on. A fixed IP address can come in handy when you’re connecting remotely to your microcomputer or if it’s communicating with other devices; or when setting up a server.

Hardware

Check your network’s IP address

To display your network’s local address, enter the following command

ip route | grep wlan0

or if your Raspebrry Pi is connected via ethernet

ip route | grep eth0

Here we obtain two addresses:

Setting up a fixed IP for the Raspberry Pi

To configure a fixed address, we will modify the DHCPCD client configuration file

sudo nano /etc/dhcpcd.conf

At the end of the file, add the following lines:

interface wlan0
static ip_address=192.168.1.46/24
static routers=192.168.1.254

Save and close the file.

Once the file has been modified, you can restart the Raspberry Pi and check that it still has access to the Internet.

It’s perfectly possible to use an address other than the one retrieved with ip route (192.168.1.46). The only constraints are to use:

To obtain the addresses used on your network, enter the following command

arp -a

You’ll then get a list of all the fixed and dynamic IP addresses of devices connected to the same network as the Raspberry Pi.

All you have to do is choose a different address.

N.B.: Boxes often have two networks, one in 2.5Gz and one in 5Gz. To choose a unique address, you should check the connections on all the router’s networks.

For a list of connected devices, you can go directly to your router’s management page by entering its IP address in your browser.

Sources

Exit mobile version