Définir une IP fixe.

Give a fixed local IP to your Raspberry Pi.

Updated the 24 August 2020 - 0 Comments - , , , ,

ⓘ Cet article peut avoir été partiellement ou totalement traduit à l'aide d'outils automatiques. Nous nous excusons des erreurs que cela pourrait engendrer.

As you may know, each device connected to your box has a local IP address which allows it to be identified within your network.

However, these IPs can change each time the machine is restarted, and it is very annoying when you want to access the Raspberry from a computer, for example in SSH.

In this tutorial we will see how to give a fixed local IP to our Raspberry Pi and thus avoid looking for it each time.

What do we need ?

We will only need a working Raspberry Pi connected to the internet, with Raspbian installed.

Please note, we are talking about a local IP address, used to access the Raspberry from your network and not directly from the internet. We will be doing a tutorial on this specific topic in the coming weeks.

Assign a static IP to the Raspberry Pi

First connect to your pi, either physically or by SSH, and open a terminal there.

We will start by finding the current local IP address of your Raspberry Pi. To do this, type one of the following two commands (adapt according to your case):

#Si la Raspberry Pi est connectée à votre box en ethernet
ip route | grep eth0

#Sinon si la pi est connectée en wifi 
ip route | grep wlan0

You should get a return that looks something like this:

default via 192.168.0.1 dev wlan0 src 192.168.0.101 metric 303 
192.168.0.0/24 dev wlan0 proto dhcp scope link src 192.168.0.101 metric 303

Note this return to the side so that you can return to it easily.

Once done, open the file /etc/dhcpcd.conf with nano (or some other text editor, whatever), go to the end and add the lines below, replacing:

  • wlan0 by eth0 if you are connected via Ethernet.
  • 192.168.0.101/24 by the following address src in the previous command, followed by /XX after the first IP.
  • 192.168.0.1 by the following address via.
interface wlan0
static ip_address=192.168.0.101/24
static routers=192.168.0.1

What does it all do? Well quite simply, in our example, it tells the Raspberry Pi that we want:

  • Whether its IP address for the Wi-Fi connection in the local network is static, that is to say always the same, and whether 192.168.0.101, with the subnet mask /24
  • That it must use the machine at address as a router 192.168.0.1, that is to say your box.

For information, you can quite choose another address than the following one src, the only constraints are to stay in the correct subnet mask (/24 means to modify only the last group) and to choose an address which is not already in use by another machine. We
have chosen to use the current address of the Raspberry Pi since we are sure that no other machine has it. uses.

All you have to do is restart your Raspberry Pi to apply the change and check that it still has internet access.

After each restart, the IP of your Raspberry Pi will always remain the one you have defined.

4/5 - (4 votes)
Share
Newsletter
Author:
Raspberry Pi FR
Join the Raspberry Pi community
A $35 computer already sold 10 million copies
BUY THE NEW RASPBERRY PI 4
Related tutorials
Create a Wi-Fi hotspot in less than 10 minutes with Pi Raspberry! Install Android on his Raspberry Pi How to install a web server on the Raspberry Pi (Apache + PHP + MySQL) Create a NAS with your Raspberry Pi and Samba How to recover the password of your Raspberry Pi if you lost it. 2018 Update.
No Comments

Share
Newsletter Sign-Up
Subscribe to the newsletter.
¿Te gustó este artículo?
¡Suscríbete y mantente informado!