Wednesday 30 May 2012

Raspberry Pi - Setting a Static IP Address

Anyway, I needed to change my Raspberry Pi so it had a static IP address.  I've got a typical network at home, wireless router in the cupboard under the stairs, a couple of powerline ethernet plugs and broadband provided by someone who offers little support for anything out of the ordinary and using dhcp to dynamically allocate the IP address to the Pi was causing a few headaches - just because it kept changing!

Setting the Pi to use a static IP address was the way forward.

Modify /etc/network/interfaces
The Raspberry Pi's network configuration is stored in the file /etc/network/interfaces, so this needs to be modified in order to change it from using dhcp to get an IP address to assigning a static one.

sudo nano /etc/network/interfaces

First step is to comment out the line:

iface eth0 inet [dhcp]/[manual]

by placing a # at the start:

# iface eth0 inet [dhcp]/[manual]

Next step is to add the static IP configuration to the end of the file, this will be specific to your network setup, but for most 'home' users it will be pretty similar.

You will need to know the IP address of your router, it is probably or, but you can check by logging into your router and checking the configuration.

You will also need to decide on an IP address for your Pi that is within the range of your routers IP address e.g.

So in my setup, where I wanted to give the Raspberry Pi an address of and my router has the address; I added the following to the bottom of the /etc/network/interfaces file.

iface eth0 inet static

Ctrl X to save the changes

I found that using the raspbian distro I had to reboot the Pi for the network changes to take effect:

sudo shutdown -r now

I tested the change by making sure I could still ping my router



  1. Hi, am new to all this so sorry if this is an obvious question, but how would I also set up the RPi with a host name eg "MyRPi" so i can reference it with something a little less clunky than using the ip address the whole time.

    Many thanks

    1. Alex, If you are going across OS (e.g. Windows -> Linux) and you dont have the appetite to setup a DNS service, you might find yourselves in a world of pain (for me it just seemed to much touble!), see the following posts of rPi forum., . Mart

  2. How do you also specify a DNS server?

    1. Ive never done this before, but 'the internet' tells me that you add dns-nameservers after the gateway tag.

  3. when i save it says so sutch file or directory what do i do

    1. Dont know... Type the name of the file properly!

  4. Hi, how to change the static IP by a Python script ? Any help please. Thank you very much.

  5. DNS entry goes in /etc/resolv.conf as:


  6. this was completely useless to me, what do you mean within range of my routers ip address? what are those numbers after netmask, network and broadcast?!?!?!?!!?!?!?! can you explain this in idiot to me please

    1. Apologies if the post was 'completely useless' and yet you ask for advice?!

  7. I understand it, and it helped me. Thanks bro.

  8. I understand it, and it helped me. Thanks bro.


Note: only a member of this blog may post a comment.