Upload
max
View
222
Download
0
Embed Size (px)
Citation preview
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
1/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address
Login| Register
Select Language
Home Blog Tutorial - How to give your Raspberry Pi a Static IP Address
Tutorial - How to give your Raspberry Pi aStatic IP AddressJuly 19, 2013To log in to your Raspberry Pi remotely, you'll need the IP of the Raspberry Pi this is basically like yourhouse address and tells the host computer where to look for it on the network. By default, the Raspberry Piwill be given an IP automatically by the router (called Dynamic IP and denoted by DHCP) when you connectto a network. However, this can change whenever you remove the Pi from the network e.g. turn it off.
Having a static IP isn't essential, however it will make repeated access to the Raspberry Pi via SSH much
simpler, as you'll always know that the Raspberry Pi has the same address. Imagine how much trouble yourpostman would have if your house constantly changed location :)
This task assumes that you have the official Raspian OS release installed. This is available in the NOOBSdistribution and can be downloaded from http://www.raspberrypi.org/downloads. This guide also assumesthat you've connected your Pi to a network via Ethernet. If you're going to be logging into your Pi remotelyfor most tasks, then I recommend it's easiest and fastest to plonk it next to your router, and use ethernet toaccess the internet anway!
A. Checking Set Up
Boot into Raspian and log in (Username. pi, Password. raspberry), this will all be command line stuff, so noneed to log in to the GUI.
First, we need to list the network interface we currently have available:
cat /etc/network/interfaces
http://www.raspberrypi.org/downloadshttp://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-addresshttp://www.modmypi.com/bloghttp://www.modmypi.com/index.php?route=common/homehttps://www.modmypi.com/index.php?route=account/registerhttps://www.modmypi.com/index.php?route=account/loginhttp://www.modmypi.com/index.php?route=common/home7/24/2019 How to Give Your Raspberry Pi a Static IP Address
2/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 2
The line . . . .
iface eth0 inet dhcp
Implies that we're currently getting out IP address via DHCP, meaning it's being dynamically registered bythe router. This is what we want to change!
B. Gathering Information
Fist of all we need to grab some information from our router and Pi. There's a couple of command we need torun to get this info. Have a pen and paper handy! . . .
ifconfig
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
3/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 3
This reveals your router information, the bit you want is after eth0 (the ethernet connection). . . .
eth0 Link encap:Ethernet HWaddr b8:27:eb:b3:fc:2c
inet addr:192.168.1.81 Bcast:192.168.1.255 Mask:255.255.255.0
Write down the following information. . .
inet addr 192.168.1.81 (Pi's Current IP Address)
Bcast 192.168.1.255 (The Broadcast IP Range)
Mask 255.255.255.0 (Subnet Mask Address)
We need a little more information before we proceed. Use the command. . .
netstat -nr
(route -n will give you the same info.)
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
4/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 4
We need:
'Gateway' Address 192.168.1.254
'Destination' Address 192.168.1.0
C. Editing Network Configuration
We now need to plug this information into the Pi's network configuration file using a text editor. I alwaysuse nano text editor. . .
sudo nano /etc/network/interfaces
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
5/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 5
Simply change the line that reads:
iface eth0 inet dhcp
to
iface eth0 inet static
Then directly below this line enter the following (Please Note. You will need your own addresses wegathered in Part B, more details below). . . .
address 192.168.1.81
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
To clarify what each part means. . . .
address The address you want to give your Pi, this can be any IP in the network range, but it's usuallyadvisable to go higher rather than lower, or you could end up logging different devices to the same IP! I'veselected 192.168.1.81, as we're already registered to that address (denoted by 'inet addr'), but this can be any
IP address from the range192.168.1.1 to 192.168.1.255.
netmask The 'Mask' address we wrote down earlier.
network The router IP address, this is the 'Destination' Address was found earlier. You can also grab thisoff your router, it will say on the side somewhere.
broadcast The 'Bcast' address we wrote down earlier.
gateway This is the 'Gateway' address we found earlier.
So, it should look something like the above, but with your values! Remember to save before exit, CTRL+X(exit) then yes to save changes!
D. Re-check Static IP Configuration
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
6/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 6
UPDATE:Remove any existing leases
sudo rm /var/lib/dhcp/*
Then we'll need to reboot and check your changes. . .
sudo reboot
Log back in and run
ifconfig
Which should reveal your new settings. .
To double checks all is working as it should, ping your 'Gateway' Address. . .
ping 192.168.1.254 -c 10
(the -c 10 command simply denotes that you want to ping it 10 times, if you forget to add this, it will ping theaddress continuosly. To stop it press CTRL+C)
7/24/2019 How to Give Your Raspberry Pi a Static IP Address
7/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 7
Raspberry Pi - Model B+
22.99
ADD TO BAG
Raspberry Pi - Model A (Made in UK, 256MB)19.99
ADD TO BAG
This should ping successfully and all packets should be recieved. If something's not right double checkthrough all your IP addresses, and make sure you're pinging the right address too. Remember you canalways revert back to DHCP by reversing the steps. The 'network' router IP address is sometimes a littlefiddly, so check that if you're still having issues!
Hopefully however, your Raspberry Pi is now set up with a static IP address!
Tags: raspberry-pi, static-ip, static, ip, address, static-ip-address, ip-address, raspberry, pi, Last update:September 10, 2015Related Products:
http://www.modmypi.com/index.php?route=product/search&filter_tag=pihttp://www.modmypi.com/index.php?route=product/search&filter_tag=raspberryhttp://www.modmypi.com/index.php?route=product/search&filter_tag=ip-addresshttp://www.modmypi.com/index.php?route=product/search&filter_tag=static-ip-addresshttp://www.modmypi.com/index.php?route=product/search&filter_tag=addresshttp://www.modmypi.com/index.php?route=product/search&filter_tag=iphttp://www.modmypi.com/index.php?route=product/search&filter_tag=statichttp://www.modmypi.com/index.php?route=product/search&filter_tag=static-iphttp://www.modmypi.com/index.php?route=product/search&filter_tag=raspberry-pihttp://www.modmypi.com/raspberry-pi-model-b-made-in-uk-512mb-and-8gb-microsd-card-bundlehttp://www.modmypi.com/raspberry-pi-model-a-made-in-uk-256mbhttp://www.modmypi.com/raspberry-pi-model-a-made-in-uk-256mbhttp://www.modmypi.com/raspberry-pi-model-b-plus-newhttp://www.modmypi.com/raspberry-pi-model-b-plus-new7/24/2019 How to Give Your Raspberry Pi a Static IP Address
8/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 8
Raspberry Pi - Model B (Made in UK, 512MB) & 8GB MicroSD Card Bundle32.99
ADD TO BAG
Raspberry Pi - Model B (Made in UK, 512MB)28.00
ADD TO BAG
Raspberry Pi - Model B+ & 8GB MicroSD Card Bundle31.00
ADD TO BAG
Raspberry Pi - Model A+ (NEW)17.99
ADD TO BAG
Raspberry Pi 2 - Model B (NEW)29.99
ADD TO BAG
107 Comments(46 Replies)
http://www.modmypi.com/raspberry-pi-2-model-b-newhttp://www.modmypi.com/raspberry-pi-2-model-b-newhttp://www.modmypi.com/raspberry-pi-model-a-plus-newhttp://www.modmypi.com/raspberry-pi-model-a-plus-newhttp://www.modmypi.com/raspberry-pi-model-b-plus-new-and-8gb-microsd-card-bundlehttp://www.modmypi.com/raspberry-pi-model-b-plus-new-and-8gb-microsd-card-bundlehttp://www.modmypi.com/raspberry-pi-model-b-made-in-uk-512mbhttp://www.modmypi.com/raspberry-pi-model-b-made-in-uk-512mbhttp://www.modmypi.com/raspberry-pi-model-b-made-in-uk-512mb-and-8gb-microsd-card-bundle7/24/2019 How to Give Your Raspberry Pi a Static IP Address
9/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address 9
Raspberry Pi 2 - Model B (NEW) & 8GB MicroSD Card Bundle34.00
ADD TO BAG
Sam FitzgeraldFebruary 04, 2016 02:52My server was working perfectly fine until I updated to the Static IP, upon following the instruction tosudo reboot, it just sits at"[ ok ] Starting system message bus: dbus.[ ok ] Starting periodic command scheduler: cron.
[ ok ] Starting OpenBSD Secure Shell server: sshd.My IP address is 10.0.0.15_"This has been sitting here for a half hour now and this also the second attempt with the same result...
Reply
chfakhtJanuary 24, 2016 13:07i have used raspberrypi_defconfig configuration under BUILDROOT to mount the OS on the pi ... thismethod didn't work !!!
Reply
FAISALJanuary 14, 2016 18:27i cant understand how to give static ip address to raspbarry pi..?
Reply
waleedDecember 23, 2015 13:50I purchased my new raspberry pi 2 and i burn on it (raspbian wheezy) and then i opened my cmd andwrite ( apt -a ) then it show dynamic IP address. i copied that IP and write on ( putty ) then its open smallscreen and ask to enter login name?. i entered ( pi ) password ( raspberry ) but its say ( access denied ).now what i do?.in login (pi) its accepted but password deniedplease help me guys.
Reply
http://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-addresshttp://www.modmypi.com/raspberry-pi-2-model-b-new-and-8gb-microsd-card-bundlehttp://www.modmypi.com/raspberry-pi-2-model-b-new-and-8gb-microsd-card-bundle7/24/2019 How to Give Your Raspberry Pi a Static IP Address
10/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to- give-your-r aspberry-pi-a-static-ip-address 10
ColdusJanuary 18, 2016 08:30I've had the same issue, connect it to a screen, turn it on, and press shift while it boots.... Morehere:https://www.raspberrypi.org/forums/viewtopic.php?t=20397
For me it did help , Good luck :)
ursDecember 16, 2015 22:45the same as Hesham wrote: it does NOT workafter reboot it's the same address as before.
Reply
nobodyDecember 20, 2015 19:56try this:https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=124423
JohnDecember 23, 2015 08:41If you are using Raspbian Jessie have a look at th link :http://raspberrypi.stackexchange.com/questions/37920/how-do-i-set-up-networking-wifi-static-ip
HeshamDecember 11, 2015 19:40Hello Jessi,
I do everything as written, but after reboot the interfaces file is refreshed as it was first time without anyof my changes! I tried this twice. Any clue?
Reply
PREV 1 of 18 NEXT
Leave a CommentLeave a Reply* Name: * Comment:
* E-mail: (Not Published)
http://www.modmypi.com/?route=blog/article/comment&art_id=54&cmt_page=2https://www.modmypi.com/odootec.comhttps://www.raspberrypi.org/forums/viewtopic.php?f=91&t=1244237/24/2019 How to Give Your Raspberry Pi a Static IP Address
11/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess
https://www.modmypi.com/blog/tutorial-how-to- give-your-r aspberry-pi-a-static-ip-address 1
Website: (Site url with http://)
Verification code:
Submit
Information
Home
About Us
Delivery Information
Returns Policy
Privacy Policy
Terms & Conditions
WEEE
Find us on Google+
Customer Service
Contact Us
Site Map
My Account
My Account
Order History
Wish List
Newsletter
Submit
Keep in the loop
Your Name
Your Email
https://www.modmypi.com/index.php?route=account/newsletterhttps://www.modmypi.com/index.php?route=account/wishlisthttps://www.modmypi.com/index.php?route=account/orderhttps://www.modmypi.com/index.php?route=account/accounthttp://www.modmypi.com/index.php?route=information/sitemaphttp://www.modmypi.com/index.php?route=information/contacthttps://plus.google.com/113850289123856902066http://www.modmypi.com/weeehttp://www.modmypi.com/terms-and-conditionshttp://www.modmypi.com/privacy-policyhttp://www.modmypi.com/returns-policyhttp://www.modmypi.com/delivery-informationhttp://www.modmypi.com/about-ushttps://www.modmypi.com/7/24/2019 How to Give Your Raspberry Pi a Static IP Address
12/12
2/16/2016 ModM yPi | Tutor ial - How to gi ve your Raspber ry Pi a Stati c IP Addr ess