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.1
On 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:
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:
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:
? (192.168.1.42) at dc:a6:32:60:20:81 on en0 ifscope [ethernet]
More computers tutorials:
- Finite State Machines
- The Decimal Number System
- The Binary Number System
- Converting Numbers from Decimal to Binary
- Printable ASCII characters list
- Non-printable ASCII characters list
- How to connect to a Raspberry Pi using a Mac
- How to make sure the Raspberry Pi has always the same IP address
- A very short introduction to COBOL