This is a much-needed update to the blog entry that I wrote in April 2015 with respect to RPi2 and was last updated this past September.  Much thanks for comments by clem57 , anthonyworth , and sergiokob (RPi3 comments).

Why a static IP address for the Pi?  Well, you might not want it to change so that you can use a Pi in the following example repeated situations:

  • sshd (allow ssh clients to connect for various reasons)
  • rsync (copy from/to over SSH)
  • remmina (remote desktop server)
  • Samba (Windows file server emulation)
  • FTP

 

Keep in mind that a router would vary non-static dynamic address periodically during an automatic address renewal or after a Pi reboot (which usually causes a DHCP renewal).  So fixing the address of a set of common services is desirable.

 

Some administrative specifics about my LAN (router environment) to explain the addresses which appear later:

  • Router and DNS (combined in my router): 192.168.1.1
  • Dynamic address range: 192.168.1.{201, ..., 299}
  • Static (manual-assignment) address range: 192.168.1.{101, ..., 199}

 

The /etc/hosts file on one of my machines (biostar) contains the following static-address entries:

127.0.0.1    localhost

127.0.1.1    biostar

192.168.1.1     router

192.168.1.101    zotac

192.168.1.102    biostar

192.168.1.103    raspbian

192.168.1.104    pine64

 

The RPi2 file /etc/network/interfaces as installed today:

 

source-directory /etc/network/interfaces.d

 

auto lo

iface lo inet loopback

 

iface eth0 inet manual

 

allow-hotplug wlan0

iface wlan0 inet manual

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

allow-hotplug wlan1

iface wlan1 inet manual

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

So, it is not surprising that my Pi, according to `ifconfig`, was running eth0 at "inet addr" 192.168.1.235.

 

For the long-term, I want to fix my RPi2 using wired-Ethernet at 192.168.1.103.

For a WiFi test (EDUP USB/WiFi adapter), I will create a temporary WiFi static connection at 192.168.1.199.

 

It's most unfortunate that Raspbian-Jessie still does not include one of the network-manager GUIs found in many of the other LightDM-based distributions; this would have made this job simpler and not required manually editing of system configuration file(s).  On the other hand, this is an educational opportunity.

 

Keep in mind that the below-defined recipe may not work in future Raspbian releases.  For example, when I upgraded the "biostar" desktop Xubuntu image during 2015, I noticed that the network configuration strategy switched when migrating from the Ubuntu "upstart" service manager to the "systemd" service manager.  Surprise, surprise.  I had already gone through this once before from "SysV" to "upstart".  This is why Network Manage GUIs are so helpful and time-conserving.

 

Back to the task at hand - I followed this recipe today after a re-installation on my RPi2:

  • I left /etc/network/interfaces alone (Thank you, Sergio).  The 2015 strategy (SysV-oriented) of editing /etc/network/interfaces directly failed to work again in 2016.
  • I appended /etc/dhcpcd.conf with the following static information without the parenthetical comments:

interface eth0 (Wired-ethernet)

ipv4only (only using IPv4)

static ip_address=192.168.1.103 (following my /etc/hosts plan)

static routers=192.168.1.1 (my gateway address)

static domain_name_servers=192.168.1.1 (my router provides my DNS service which is fast enough for me)

interface wlan0 (WiFi)

ipv4only

static ip_address=192.168.1.199

static routers=192.168.1.1

static domain_name_servers=192.168.1.1

  • I appended /etc/wpa_supplicant/wpa_supplicant.conf with the following static information without the parenthetical comments:

network={

               ssid="It's-a-secret"

               psk="It's-a-secret"

}

  • Reboot

 

Sergio (mentioned above) put his wlan0 static IP address in the /etc/wpa_supplicant/wpa_supplicant.conf file.  It can, apparently, go in either file.  I'll guess that he did this because he only wanted to modify one file since he had no wired-Ethernet connection to configure.

 

NOTE that if you create two connections to the same host, ssh client will not be happy with trying to switch from one to another - "Host key verification failed".  Work-around for me:

ssh-keygen -f "/home/elkins/.ssh/known_hosts" -R 192.168.1.103

Start over (`ssh 192.168.1.103`)

 

Since this recipe worked on RPi2 and RPi3 before, I assumed that the RPi3 would still work with the above recipe (I don't have one to test with).  Any RPi3 assistance will be appreciated.  I will correct as necessary.