element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog How to Set-up a Static (Fixed) IP Address on Raspberry Pi 2 and 3
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 2 Apr 2015 5:50 PM Date Created
  • Views 1572 views
  • Likes 5 likes
  • Comments 0 comments
Related
Recommended
  • pi
  • rpi3
  • rpi2
  • raspberry-pi
  • networking
  • raspbian
  • feature_tutorial
  • linux

How to Set-up a Static (Fixed) IP Address on Raspberry Pi 2 and 3

Former Member
Former Member
2 Apr 2015

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.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube