Skip to content

How to make sure the Raspberry Pi has always the same IP address

New Course Coming Soon:

Get Really Good at Git

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:

The Router Admin Panel

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:

The VNC Connect panel

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]
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: