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

  • Social Media Times Are Changing
  • It has certainly been a long time…
  • 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

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet
@rbazinet

  • Great little utility https://t.co/6AgboJv6oI
    about 21 hours ago
  • Funny watching the hate to show up in my time line for ChatGPT. People getting defensive about it.
    about 4 days ago
  • I just backed The SaaS Playbook, by Rob Walling on @Kickstarter https://t.co/1FpTWN9c9v
    about 4 days ago
  • This looks like an interesting project. I need to dig in a bit. https://t.co/gacEX9AmEn "Phlex — fast, object-orie… https://t.co/4AUL0Z0SBl
    about 5 days ago
  • I attempted to use ChatGPT today and asked a couple questions it couldn’t answer. I thought it was a magical black… https://t.co/uJGw0CgUAv
    about 5 days ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon