Você está na página 1de 12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

Login | Register
Select Language

Home Blog Tutorial - How to give your Raspberry Pi a Static IP Address

Tutorial - How to give your Raspberry Pi a


Static IP Address
July 19, 2013
To log in to your Raspberry Pi remotely, you'll need the IP of the Raspberry Pi this is basically like your
house address and tells the host computer where to look for it on the network. By default, the Raspberry Pi
will be given an IP automatically by the router (called Dynamic IP and denoted by DHCP) when you connect
to 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 your
postman 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 NOOBS
distribution and can be downloaded fromhttp://www.raspberrypi.org/downloads. This guide also assumes
that you've connected your Pi to a network via Ethernet. If you're going to be logging into your Pi remotely
for most tasks, then I recommend it's easiest and fastest to plonk it next to your router, and use ethernet to
access 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 no
need to log in to the GUI.
First, we need to list the network interface we currently have available:

cat /etc/network/interfaces

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

1/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

The line . . . .
iface eth0 inet dhcp
Implies that we're currently getting out IP address via DHCP, meaning it's being dynamically registered by
the 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 to
run to get this info. Have a pen and paper handy! . . .

ifconfig

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

2/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

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.)

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

3/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

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 always
use nano text editor. . .

sudo nano /etc/network/interfaces

Simply change the line that reads:


https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

4/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

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 we
gathered 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 usually
advisable to go higher rather than lower, or you could end up logging different devices to the same IP! I've
selected 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 this
off 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
UPDATE: Remove any existing leases
https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

5/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

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 the
address continuosly. To stop it press CTRL+C)

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

6/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

This should ping successfully and all packets should be recieved. If something's not right double check
through all your IP addresses, and make sure you're pinging the right address too. Remember you can
always revert back to DHCP by reversing the steps. The 'network' router IP address is sometimes a little
fiddly, 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, 2015
Related Products:

Raspberry Pi - Model B+
22.99

ADD TO BAG

Raspberry Pi - Model A (Made in UK, 256MB)


19.99

ADD TO BAG

Raspberry Pi - Model B (Made in UK, 512MB) & 8GB MicroSD Card Bundle
https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

7/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

Raspberry Pi - Model B (Made in UK, 512MB) & 8GB MicroSD Card Bundle
32.99

ADD TO BAG

Raspberry Pi - Model B (Made in UK, 512MB)


28.00

ADD TO BAG

Raspberry Pi - Model B+ & 8GB MicroSD Card Bundle


31.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)
https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

8/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

Raspberry Pi 2 - Model B (NEW) & 8GB MicroSD Card Bundle


34.00

ADD TO BAG

Sam Fitzgerald
February 04, 2016 02:52
My server was working perfectly fine until I updated to the Static IP, upon following the instruction to
sudo 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

chfakht
January 24, 2016 13:07
i have used raspberrypi_defconfig configuration under BUILDROOT to mount the OS on the pi ... this
method didn't work !!!
Reply

FAISAL
January 14, 2016 18:27
i cant understand how to give static ip address to raspbarry pi..?
Reply

waleed
December 23, 2015 13:50
I purchased my new raspberry pi 2 and i burn on it (raspbian wheezy) and then i opened my cmd and
write ( apt -a ) then it show dynamic IP address. i copied that IP and write on ( putty ) then its open small
screen 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 denied
please help me guys.
Reply

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

9/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

Coldus
January 18, 2016 08:30
I've had the same issue, connect it to a screen, turn it on, and press shift while it boots.... More
here:https://www.raspberrypi.org/forums/viewtopic.php?t=20397
For me it did help , Good luck :)

urs
December 16, 2015 22:45
the same as Hesham wrote: it does NOT work
after reboot it's the same address as before.
Reply

nobody
December 20, 2015 19:56
try this:
https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=124423

John
December 23, 2015 08:41
If 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

Hesham
December 11, 2015 19:40
Hello Jessi,
I do everything as written, but after reboot the interfaces file is refreshed as it was first time without any
of my changes! I tried this twice. Any clue?
Reply

PREV 1 of 18 NEXT

Leave a Comment
Leave a Reply
* Name:

* Comment:

* E-mail: (Not Published)

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

10/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

Website: (Site url with http://)

Verification code:

Submit

Information

Customer Service

Home

Contact Us

About Us

Site Map

Delivery Information
Returns Policy
Privacy Policy
Terms & Conditions
WEEE
Find us on Google+

My Account
My Account

Keep in the loop


Your Name

Order History
Wish List

Your Email

Newsletter
Submit

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

11/12

2/16/2016

ModMyPi|TutorialHowtogiveyourRaspberryPiaStaticIPAddress

https://www.modmypi.com/blog/tutorialhowtogiveyourraspberrypiastaticipaddress

12/12

Você também pode gostar