How to ensure that Raspberry Pi always has the same IP address

A step-by-step guide to configure the router to assign a static DHCP IP address in the LAN to the Raspberry Pi

I recently got a Raspberry Pi to test and set up some project ideas. After installing Raspbian (a Linux version of Debian made specifically for Raspberry Pi), I ran into problems.

I connected the Raspberry Pi to the TV using an HDMI cable, and connected a USB mouse and USB keyboard to install the operating system and "connect".

Then, I set up a VNC server on the Pi to be able to connect to it from the Mac.

When I removed all these cables, in order to only connect the Raspberry Pi to the power cord, I realized that as long as I restarted it, the IP address assigned to it would change.

This is because of DHCP, the protocol used by WiFi routers. It does not assign a fixed IP to each connected device: the IP is always changing.

Sometimes192.168.1.2. Sometimes192.168.1.30. Sometimes192.168.1.43.

I really don't want to spend time looking up what the Raspberry Pi IP address is every time, right? It is annoying.

Therefore, I found that it is possible to assign a fixed IP to a specific device by identifying its MAC address. The MAC address (also known as the media access control address) is a unique identifier. Each device has a different device.

So I connected to a WiFi router running on IP192.168.1.1On my local network, I wentDHCP servermenu.

In it, click "Static DHCP", and then you can assign a specific IP to the Raspberry Pi's MAC address:

The Router Admin Panel

How do I find the MAC address of the Pi?

I know the IP address because the VNC server panel on the Raspberry Pi shows it:

The VNC Connect panel

Then using MacBook Air, I scanned the network using the following method:

ifconfig | grep broadcast | arp -a

This prints the IP and MAC addresses of all devices connected to the network, including the Raspberry PI that I am interested in:

? ( at dc:a6:32:60:20:81 on en0 ifscope [ethernet]  

More computers tutorials: