Raspberry Pi – Set a Static IP Address
- Set a static address.
- Reliably connect to the Raspberry Pi.
- No more fumbling in DHCP logs to find the current IP.
Setting a static IP allows you to run a web server, file server or any other service that relies on clients knowing where to look.
It will also simplify general maintenance as we will always know where to find our Raspberry Pi.
IP Address (IP)
An IP address is a unique (numeral) address that is used to identify a device on the network. Every computer has an IP address and these are used by computers to talk to one another.
Think of it like your postal address or telephone number. If someone wants to contact you they use your unique address, this is the same for a computer and its IP.
Click here for a full detailed description of IP address.
DHCP stands for Dynamic Host Configuration Protocol and a DHCP server is the server tasked with giving computers without an IP address their address. It is similar to going to the theater and the box office assigning you a seat. They make a note of your seat row and number so if you’re needed during the performance someone can find you. This is the same job the DHCP server has, it gives computer A an IP address and then gives that address to the DNS server so when other computers want to find computer A they are told where they can find them.
A server usually has a range of IP addresses it is allowed to hand out. E.g. 10.8.110.100 To 10.8.10.199. If you are using a static IP address you’ll want to pick one outside of the range.
Click here for a full detailed description of DHCP.
SSH stands for secure shell. SSH is an encrypted connection established between two computer programs. On the server side (the computer being connected to) a service is running that listens for another computer trying to contact it via SSH.
Click here for a full detailed description of SSH.
This guide assumes you have a fresh install of Raspbian on a headless server.
Set a Static IP
Most projects we undertake will benefit from a static IP address so it’s worth setting up as a matter of course as it’ll make SSHing into our Raspberry Pi much easier because we already know it’s address.
First we’re going to update dhcpcd.conf to assign a static IP.
SSH into your Raspberry Pi using it’s IP or hostname and open dhcpcd.conf for editing:
sudo nano /etc/dhcpcd.conf
Scroll to the very bottom of the file (or Page Down) and at the very bottom paste the following. If you want to assign a static IP to the WiFi interface, the default name is wlan0:
interface eth0static ip_address=*Desired IP address*
static routers=*Router IP address*
static domain_name_servers=*DNS server IP address*
In between the asterisks you’ll have put the static IP address of the Raspberry Pi and the IP address of your router. For example, mine are:
interface eth0static ip_address=10.8.10.115
static routers=10.8.10.1static domain_name_servers=10.8.10.1
Press Ctrl+x to exit and you’ll be prompted to Save modified. Type Y and then return to save the file.
Reboot the Raspberry Pi to ensure the new IP address is set:
Once your Raspberry Pi has rebooted SSH back in using it’s new IP address. At any time to check the IP address of your Raspberry Pi use:
ip -c a
Congratulations you’ve now got a static IP address!