Raspberry Pi 3 – Static IP setup

GREETINGS TO ALL FROM MALICE-CORP.COM.  Hey guys, it is now time to get your Raspberry Pi dialed in with it’s own static IP.  Why would you want to do this?  Well it is a simple reason really. For the most part you are going to be accessing the device via SSH or maybe VNC.  It will help if you have the same IP every time on the device so you can always find it.  This can get really important if you plan to use a Wi-Fi connection as your router could assign a different IP each time your Pi connects.  Remember we are working off Rasbian OS here so if you have a different OS the process maybe slightly different for you.

You all remember Thor my trust Pi?  Well he is all ready to work with us on this example.  So, lets dive into it.


We are going to be using some new and old stuff we used in the past articles

  1. sudo – remember this is superuser do.  It is the command string that tells the pi to follow what comes after with superuser privileges.  Boils down to do what I tell you, because I am the boss.
  2. nano – this is a text editing process.   There are lots of other process that can be used like vi or vim.  But we are going to use nano because, well it is the one I like.

New Linux and networking terms:

I am going to break down some terms here in simple plain language.  The descriptions and definitions might not be exactly accurate from a technical point of view but they are close enough for NERD work.

  1. Static IP – This is a fixed IP address in your network that is always assigned to the same device.
  2. DHCP – Dynamic Host Configuration Protocol (DHCP) this basically is allowing one device to assign an IP to another.  This device is sometimes called a DHCP server, in our home networks that is normally our router.
  3. Interface –  We are talking specifically about the port that we are configuring.  The Pi is pretty simple as it only has two interfaces; eth0 and wlan0 for the Wi-Fi.  Today we are only going to work with eth0. If the font makes it hard for you to tell that is a zero at the end of eth0.
  4. route – this is all the network connections a Pi or devices has to the outside world.
  5. flags – these are add-ons to a command or string to modify it for a specific action.  Normally a flag is denoted by a ‘-‘.  example: netstat -ng.  The ‘-ng’ are flags for the netstat process.
  6. process – A process in Linux speak is pretty much a program for those more used to Windows/Mac based, in laymen’s terms.
  7. gateway – The device that is the gateway to the internet or outside of our network.  In our case here we are talking about our home router

Let’s get started.

There are several diffrent ways to set up a static IP on a Pi.  You can work through the GUI or through the CLI (command line interface).  I am going to work through the CLI today.  We are going to use PuTTY again.  If you need help with that go ahead and jump back over to this article here for some details.

Once you have you PuTTY connection and you are logged in, there are only a few steps you need to make this work.  You can do a lot more if you want, that are actually more correct, but in a home network with a home personal router they are kind of over kill and I will explain why when we get to them. Oh, just a note on the steps below please don’t include the step number in the command.  I am just tossing that out there before I get a bunch of comments that 1.route -ne doesn’t work.

  1. route -ne
    1. we use this proccess and the accociated flags here to find out what are gateway
      route -ne example
      route -ne example

      IP is for our router.  You may already know yours  from previous articles, but this will tell you without having to go back and look it up.  We want the IP address listed under gateway here.  Check out the gateway example picture here for some help spotting it.

  2. Your next step should be to get you nameserver IP(s) and domains.  That would be the correct way to do it but since we are using a home router, it is the only access we have to the internet. If it stops working we are kind of hosed any way, we are just going to use it.  So long story short we will use the gateway IP as the nameserver IP.  If that makes no sense it is ok.  You will understand more below.
    1. If you really want to see what your name servers are on your Pi you can check them with the ‘cat /etc/resolv.conf’.  If there are any questions about the ‘resolv.conf’ file or want help editing ask in the comments below.
  3. sudo nano /etc/dhcpcd.conf
    1. This is going let us edit the dhcpcd.conf file and drop all this info we got above into it.
    2. we need to do the following:
      1. Scroll down to the bottom using the arrow keys on your keyboard.  If you use the scroll bar on PuTTy that is just going to move you up and down in the session.  You are looking for the ‘interface eth0’ entry.  There should be on there if you have your Pi hooked up to your router.
      2. Now you are going to remove or comment out everything below the ‘interface eth0’.  Comment out in Linux means to make the Pi ignore it by placing a “#” at the beginning of the line.

        thor's dhcp.conf as an example
        thor’s dhcp.conf as an example
      3. Next you are going to add in the following lines. The IP address are going to be the information we gathered and the IP we have decided to use for the Pi
        1. static ip_address=192.168.X.Y     –  This is the new static IP select something higher up in the range.  The X will be the same as your routers third octet.  The Y will be what ever you want it to be as long is not being used by another device and somewhere between 2 and 254.
        2. static routers=192.168.A.B      –  This is your gate we gather from the route -ne command
        3. static domain_name_servers=192.168.A.B     –  This again is your router cause we are cheating.
      4.  Now we ‘ctrl+x’ then ‘y’ then enter
      5. Now we need to restart the networking. The easiest way to do this is again by cheating. Because we have a Pi here not a large Linux box, is to just reboot it with ‘sudo reboot’.  This again is not the most correct way for a Linux admin to do things, but hey we are in a hurry here.
      6. This is going to disconnect you from the Pi via PuTTY and OH NO we can’t get back in!  Did you set the Pi’s new static IP to something different then you have in the PuTTY field?  OOPS!! your screwed.  Nah, just kidding change it in PuTTY to the IP and try and connect again.  If you can’t remember what you set it to, check out your router connected devices and look for your Pi there you will find it.

Now we have a static IP on the Pi.  This is not the most correct way to do it, but like I said it is good enough for NERD work.  If you have any questions or need me to clarify something, just comment below.  Maybe you know a better way to set up a Static IP.


Jack Malice, Contributor and founder.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.