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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
Documents Static IP Address for my Pi
  • 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!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: PEarle
  • Date Created: 28 Apr 2013 1:13 PM Date Created
  • Last Updated Last Updated: 8 Oct 2021 5:29 AM
  • Views 3674 views
  • Likes 3 likes
  • Comments 14 comments
Related
Recommended

Static IP Address for my Pi

Like most people, I want to run my Pi 'headless' - i.e. I want to connect to it remotely using my laptop keyboard and screen. It means that I don't have to hook anything up to the Pi, and I don't need to get a second screen and keyboard. There's several ways of doing this - using VNC for example, or Putty (for a command line interface) and there's lot of information on the web about how to set these up. However, if like most people, you are behind a broadband router that assigns dynamic IP addresses, then you will find that the IP address of your Pi keeps changing. This means that you can't connect to it remotely unless you know the IP address - and to find that out you have to connect a screen, which rather misses the point of trying to run headless!

 

Fortunately its fairly easy to do this - there's several pieces I found on the 'Net, and the following is a record of my own successful attempt. If this doesn't work its probably because of the way your router is set up, and you will need more help than given in this article - but this worked for me!

 

The first thing you need to do is to find out what range of addresses is available to you. If you do an ipconfig command on your PC you find out what its IP address is, and that will give you an idea of the range of IP addresses being used assigned by your router.

As you can see below the IP address for my PC is 192.168.1.3 - so my router is assigning addresses in the range 192.168.1.nnn

There are a couple of other bits on information which we will need in a minute - the subnet mask and the gateway - circled below in red.

image

 

I picked an IP address to assign ion the range that the router is using, but high enough so that it wouldn't assign it to a device I was already using. That isn't the most scientific way of doing it, but it seemed to work for me! I decide to use 192.168.1.10 for my Pi.

 

Logging on to the PI, all I e to do was to edit file /etc/network/interfaces as follows;

 

At a command prompt on the pi enter sudo nano /etc/network/interfaces

 

In the file you will see the line iface eth0 inet dhcp as shown below

 

image

 

Edit the line iface eth0 inet replacing dhcp with static

Then add the following lines

 

address the ip address you are going to use

netmask the subnet mask shown in tthe PC ipconfig screen

gateway the default value shown in the PC IP config scree

 

e.g.

 

address 192.168.1.10

netmask 255.255.255.0

gateway 192.168.1.1

 

The file should look like this

 

image

 

 

Thats it! - save the file and reboot your Pi. You should now be able to access it using the IP address you have decided - as a test, ping it from your PC, and you should see something like this;

 

image

  • pi
  • ip_address
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • mgt6910
    mgt6910 over 12 years ago +1
    How about setting up a fixed address for the Pi in the router ? After that you can rewrite the Pi's Sd-card as often as you wish (or need), and still use DHCP to set up Pi's networking.
  • Gough Lui
    Gough Lui over 6 years ago in reply to koudelad +1
    Mikrotik user here too - love having the flexibility to lots of interesting and useful networking configurations that consumer gear doesn't allow. Setting up static DHCP leases (or bindings) is nice to…
  • shabaz
    shabaz over 6 years ago +1
    Things may have changed since this original blog post is now almost 6 years old, some routers may automatically assign the same IP address every time anyway, by default. With a cheap home router (as supplied…
  • colporteur
    colporteur over 5 years ago

    I found this post, fairly current, in a Raspberry Pi forums regarding Pi IP configuration.

    https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=244125

     

    Your submission motivated me to try and find the thread that if pulled leads back to the authoritative source for IP configuration. My inquiring mind would like to know.

     

    Sean

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 5 years ago

    After being involved in the support of servers for close to 20 years, I tend to look beyond just getting it working to ongoing support through sofware updates and upgrades. My developed knowledge has lead me to the understanding that two files are tweaked in order to "get working" IP network interfaces are:

     

         /etc/dhcpcd.conf -wireline IP configurations

         /etc/wpa_supplicant/wpa_supplicant.conf -wireless IP configuration

     

    In tracking the development of IP configuration over the years since Pi's inception, there have been different locations to hold the IP details.  It appears as the dust is settling these two file locations have started to become the familiar place for holding this data.

     

    I recently deviated from their use and discovered a Pi configured as an access point, won't work if the interface file is used. WHAT?

     

    I encourage individuals to check the date on posts they are using for IP configuration information. Anything greater than a year, I would be cautious. A lot changes in a year. Maybe you get it working. Then move all the family over to the new service and then after a apt-get upgrade, you have issues.

     

    I would like to know more about the evolution of Pi's IP configuration. What is truely the best practice or is it like PERL programming. You can accomplish the same task ten different ways, use the method you like best and the hell with the rest.

     

    Sean

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 5 years ago in reply to shabaz

    Well that is true but is not a guarantee.image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 6 years ago

    Things may have changed since this original blog post is now almost 6 years old, some routers may automatically assign the same IP address every time anyway, by default.

    With a cheap home router (as supplied by the ISP) I use a config where I've set the router to provide addresses within a certain range only. Anything that would benefit from a fixed IP address for "years" (e.g. security cams) is manually configured on the end device of course, at an IP address outside the range. Anything like a Pi, I just leave in the default configuration, with DHCP enabled. That cheap home router always assigns the same IP address anyway, regardless of how many months may pass, and regardless if the device is un-powered for weeks or months or (I believe) years. Screenshot below is how it looks in the router for BT users, but will vary for other makes/models.

    This is not a best-practice allocation incidentally.. ordinarily the DHCP address block is a lower range, and static IP addresses are at a higher range, but for some reason home router default configs often have it back-to-front and I didn't correct it.

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 6 years ago in reply to irishgeoff

    Hi Geoffrey,

     

    That's a slightly different thing.. you may be aware of it, but for the benefit of other readers, the website you refer to concerns a type of dynamic DNS, which is not necessary for running a Pi without a display attached, like a server (sometimes referred to as 'headless'). The website may be useful (if one trusts it) if the desire is to access the Pi from _outside_ of the network (e.g. if you're away) which is not what the OP is discussing. Also, such a thing can have security holes, so it's best not to do that by default unless there is some real need/advanced scenario.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Gough Lui
    Gough Lui over 6 years ago in reply to koudelad

    Mikrotik user here too - love having the flexibility to lots of interesting and useful networking configurations that consumer gear doesn't allow. Setting up static DHCP leases (or bindings) is nice to have as it requires no reconfiguration on the Pi to move it around and it persists based on MAC address.

     

    There are some instances where setting static IPs has its merits, especially when no DHCP server exists on the network or doesn't have the capability to memorise static leases. There are also some devices which have rather buggy clients which may not always accept the static lease doled out, especially on misconfigured networks with multiple DHCP servers. It also increases the possibility of the Pi on DHCP to be offered the wrong address by a malicious actor on the network, as DHCP is basically broadcast with no encryption, with often the first valid lease being chosen by the "victim" device. For critical intranet-only small networks, having static IPs can make sense.

     

    The method of using /etc/network/interfaces has been superseded by the use of dhcpd.conf on later versions of Debian based operating systems. See this thread from Raspberry Pi Foundation Forums about using the dhcpcd.conf to do this, although if you do delete the lines from /etc/network/interfaces and write in the old lines, this still seems to work for the time being but is generally not recommended.

     

    - Gough

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • koudelad
    koudelad over 6 years ago in reply to rew

    I also vote for doing this on your router.

     

    As you say, there are thousands of ISPs and almost every one has it's own branded hardware. So far I always had modems/routers with the capability of just bridging the connection, which disables the routing function of these boxes. Then it is possible to connect your own router to this modem  a rely on something you can learn "once" for longer periods of time. I personally use Mikrotik routers, a friend of mine is a fan of Ubiquity - both provide superior network functions compared to other consumer grade routers.

     

    David

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rew
    rew over 6 years ago in reply to PEarle

    I thought about making the same suggestion: "but you can do this in the router!", but your question explains why this advice has some drawbacks.

     

    Thousands of internet providers across the globe provide routers with their internet connection from hundreds of different brands with in total thousands different firmware versions, that might all have different user interfaces and different "lockdown configurations" depending on the provider.

     

    I'd start the article with:
    Go to the configuration page of your router. (the IP address can be found as the "default" line in the route output on your PC, enter http://<ipaddr of your router>/ into your browser.). Normally, with a few clicks on things like "lan configuration" you can click on the pi and configure it to use a fixed IP address. If you can easily find this, great! Fill in the fixed IP address that you want (or keep the one currently assigned) and you're done. If you cannot immediately find it there are too many different routers to describe here, so proceed below and we'll do it another way....

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • irishgeoff
    irishgeoff over 6 years ago

    What you can do is this. If you currently have a dynamic IP address

    you can use http://staticIP.io to do remote-access your raspberry pi.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mgt6910
    mgt6910 over 12 years ago

    Yep, I tried all that on my NETGEAR (see above). Lots of trouble documented on the internet about this : after a reset it

    took 3 days to forget the mac address (during which the RPi was not powered up). After that I added its mac-address to the table for a fixed ip-address :  connection from the RPi was impossible until I deleted the modification from the router and then waited 24 hours for the connection  to become permitted again.  The firmware must be VERY broken. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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