How to make sure the Raspberry Pi has always the same IP address
A step by step guide to configuring a router to assign a static DHCP IP address in your LAN to the Raspberry Pi
I recently got a Raspberry Pi for testing, and to build some projects ideas I have, and right after installing Raspbian, the Linux version of Debian specifically made for the Raspberry Pi, I had a problem.
I attached the Raspberry Pi to the TV, using the HDMI cable, and I attached an USB mouse and USB keyboard to install the OS and get all “wired up”.
I then set up the VNC Server on the Pi to be able to connect to it from the Mac.
As I was removing all those cables, in order to only let the Raspberry Pi attached to the power cable, I realized that as soon as I restarted it, the IP address assigned to it would change.
This is because of DHCP, the protocol that is used by the WiFi router. It does not assign a fixed IP to every device connected: the IP changes all the time.
Sometimes it’s 192.168.1.2.
Sometimes it’s 192.168.1.30.
Sometimes it’s 192.168.1.43.
I don’t really want to spend time every time to find what’s the Raspberry Pi IP address, right? It’s annoying.
So I found out that I can assign a fixed IP to a specific device, by identifying its the MAC address. The MAC address, aka Media Access Control Address, is a unique identifier. Every device has a different one.
So I connected to my WiFi router, which is running on IP 192.168.1.1 on my local network, and I went to the DHCP Server menu.
In there, I clicked “Static DHCP” and I was able to assign a specific IP to the MAC address of my Raspberry Pi:

How did I find the MAC address of the Pi?
I knew the IP address because the VNC Server panel on the Raspberry Pi showed it:

Then using my MacBook Air I scanned the network using:
ifconfig | grep broadcast | arp -a
This printed the IP and MAC addresses of all devices connected to the network, including the one I was interested in, the Raspberry PI:
? (192.168.1.42) at dc:a6:32:60:20:81 on en0 ifscope [ethernet] download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.