Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

How to Assign Static IP Address on Raspberry Pi

February 20, 2020 by Rob Bazinet Leave a Comment

Tweet

I have been setting up a Raspberry Pi 3 Model B to use as a Pi-hole server to help block the constant wave of ads my family and I keep seeing on the Internet.

One requirement for Pi-hole is the host Raspberry Pi needs to be configured to use a static IP address.

The Problem

I’ve been configuring and administering Linux servers from the command line for years, but the task of setting up a Raspberry Pi to use a static IP address was a lot more complicated than it should have been.

I started with the Raspbian GUI, expecting a Network Settings dialog where I could make the necessary changes. No such luck.

On to the obligatory Google search to find some instructions on the process. Many people are asking the same question.

Surprisingly, there are very few answers, and even less that worked. A total of 0 worked for me on my Raspberry Pi 3 Model B.

The Solution

After much trial and error, I discovered a combination that works. I wanted to write this up for a couple of reasons; first, to help others that have better things to do with their time and second, a reference I can go back to when I forget how I solved this problem.

It comes down to modifying a couple of files and adding a small bit of configuration.

The first file to update is /etc/dhcpcd.conf:

sudo nano /etc/dhcpcd.conf

Most of what needs to be added already exists in the file commented out. I left the file as-is and added the changes to the bottom of the file.

The first line indicates which interface (network card) I’m configuring, the wired port, if you’re on WiFi use wlan0 instead of eth0 for the interface.

Lines 2-4 should be pretty clear, set the IP addresses specific to your network. Line 4 indicates I am using Cloudflare DNS servers.

Line 5 sets up the static IP address even with no network cable attached. Probably not necessary but I wanted it in there.

interface eth0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1 1.0.0.1
nolink

Don’t forget to save your changes, Ctrl-x, then select Y and then press Enter to keep the file name.

The second file to update is /etc/network/interfaces:

sudo nano /etc/network/interfaces

I added this to the bottom of the file.

interface eth0 manual

This line means the interface is configured manually and does not use DHCP.

Again, don’t forget to save your changes, Ctrl-x, then select Y and then press Enter to keep the file name.

Restart the DHCP daemon or reboot.

sudo service dhcpcd restart
sudo reboot

Finally

After much trial and error and the static IP address set, configuring the Pi-hole is easy and works great.

I’m currently blocking ads at a feverish pace.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Raspberry Pi Tagged With: debian, raspberry pi, raspbian

Recent Posts

  • How to Fix Rails Flash Rendering When Using Hotwire
  • Hotwire Fix for CORS Error when using Omniauth
  • Fix Installation of Ruby using rbenv on macOS Big Sur
  • RailsConf 2021 and the Future of Conferences
  • Fixing Out of Diskspace Errors on Amazon EC2

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet (ruby.social/@rbazinet)
@rbazinet

  • Working to wrap up my current consulting gig by mid-April. I will be looking for the next thing soon. If anyone has… https://t.co/sg3cSV9yqM
    about 13 hours ago
  • I’ve been spending some time using Notion AI lately and it surprisingly good. Since all the rage lately is ChatGPT,… https://t.co/cUXFWIRCVV
    about 3 days ago
  • I think these steps are true for any target audience. https://t.co/0ht6rIzOW3
    about 3 days ago
  • I’ve been enjoying a show from the Magnolia network called The Craftsman. It’s mainly about woodworking but his phi… https://t.co/sWTUBbSsl6
    about 4 days ago
  • I found the resource I was looking for last night that is similar to https://t.co/Pyn0IIjRdP, it is… https://t.co/U7TMe77FMF
    about 4 days ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon