# Give your Raspberry Pi a static IP address

> Learn how to give your Raspberry Pi a fixed LAN IP by setting up a static DHCP lease on your router, bound to the Pi's MAC address that you find with arp.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-03-05 | Topics: [Computer](https://flaviocopes.com/tags/computers/) | Canonical: https://flaviocopes.com/raspberry-pi-static-address-lan/

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, so that only the Raspberry Pi was left 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.

By the way, all those `192.168.1.x` addresses come from your router's subnet. If you want to understand how IP ranges and netmasks work, I built a free [CIDR calculator](https://flaviocopes.com/tools/cidr-calculator/) that shows it visually.

So I found out that I can assign a fixed IP to a specific device, by identifying its 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](https://flaviocopes.com/images/raspberry-pi-static-address-lan/Screen_Shot_2020-02-09_at_18.42.48.png)

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](https://flaviocopes.com/images/raspberry-pi-static-address-lan/Screen_Shot_2020-02-09_at_18.45.35.png)

Then using my MacBook Air I scanned the network using:

```sh
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]
```
