Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

You are here: Home / Raspberry Pi / How to Assign Static IP Address on Raspberry Pi

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

Related

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

Care about your privacy? I do and use Fathom Analytics on this site.

Fathom Analytics

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
@rbazinet

  • Just for the record and anyone who might consider it...Godaddy is a complete mess and scammy. I don't think I would… https://t.co/755jpkLbnE
    about 3 days ago
  • This is so true and has been my personal take on people complaining they are busy - https://t.co/YW8NTQLXtl
    about 1 week ago
  • Wow…https://t.co/h94ia053sL
    about 1 week ago
  • My Bills lost today but more importantly so did the Dallas Cowboys. Nice seeing the ‘boys done for the season.
    about 2 weeks ago
  • It looks like the Apple Xcode command line tools is a bit bloated for it to take this long… https://t.co/U0HObTvzXf
    about 2 months ago
  • RSS - Posts
  • RSS - Comments