How to configure a Raspberry Pi with a Static IP

sudo nano /etc/dhcpcd.conf

Scroll to the bottom of the file and add the following lines:

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

#Remove these and reboot to return to dynamic IP
interface eth0
static ip_address=192.168.11.101/24
static routers=192.168.11.1
static domain_name_servers=192.168.1.1

Save the file: Ctrl+O, then Enter
Exit the nano editor: Ctrl+X
Reboot the computer

sudo reboot

Notes:
The subnet mask is written in CIDR notation at the end of the static IP address.
‘static routers=’ is the default gateway
‘static domain_name_servers=’ can be followed by multiple IP addresses, with each address separated from the previous by a single space ‘ ‘.

 

To return the interface back to using DHCP:

#Remove these and reboot to return to dynamic IP 
interface eth0
# static ip_address=192.168.11.101/24
# static routers=192.168.11.1
# static domain_name_servers=192.168.1.1

You’ll need to reboot the system to make this take effect.

Adding a second or multiple IPs to eth0 interface on a Raspberry Pi

Create the primary static IP

Follow the steps outlined above using the /etc/dhcpcd.conf file.

  • Note: This works even if you use DHCP for the primary address

 

Add additional static IPs by:

sudo nano /etc/network/interfaces.d/eth0-subs
auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
vlan-raw-device eth0
address 172.22.22.21
netmask 255.255.255.0
gateway 172.22.22.1

 

How to release a DHCP configured IP address

  • I could not personally get this to work
# Release the current IP
sudo dhclip a ient -v -r eth0
# Acquire a new IP
sudo dhclient eth0

 

Comments

So empty here ... leave a comment!

Leave a Reply

Sidebar