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

  • 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

  • Everything I read these days mentions ChatGPT or AI as the answer to everything. So many red flags. I hate trends l… https://t.co/ITLxsfAvd9
    about 1 week ago
  • If anyone knows any projects looking for some dev help, mainly Rails, as a lead who can manage small teams…I’d love… https://t.co/u0ClZ8x5wB
    about 3 weeks ago
  • This is such the truth…Even Amazon can't make sense of serverless or microservices https://t.co/0zK9YVMdrj
    about 4 weeks ago
  • I’m not sure I’d subscribe to content on Twitter when I already follow someone. Maybe I’m missing something.
    about 1 month ago
  • This looks really cool and a great real world use of AI. https://t.co/DzX5BbgDdY
    about 1 month ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon