Setting up a static IP

Setting up a static IP address for your Raspberry Pi.

Advertisements

When connecting to the Pi via the network, by default, DHCP is enabled.  This way it is possible for your Pi to change IP address from time to time.

That’s annoying when creating bookmarks, and having to find out the address time and again.

That’s why I’m going to setup a static IP for my Pi now.

Just connect to the Pi using ssh and type

sudo ifconfig

This outputs some text where you can find your wireless adapter (probably called wlan0) .

Take a piece of paper and note down

  • The current address (inet addr)
  • Broadcast range (bcast)
  • Subnet Mask (mask)

after that, type the command

sudo route -n

Note down the address of the gateway (second column) and the destination (first column).

Next, we need to adjust a configuration file, for the Pi to read when booting.

Do this the following way :

sudo nano /etc/network/interfaces

This starts the nano text editor, while editing an existing file called “interfaces”.

Somewhere in the file you should find something like

iface wlan0 inet manual

change it to

iface wlan0 inet static

and type the following below it

address [your chosen fixed IP address]
netmask [your netmask]
network [your destination]
broadcast [your broadcast range]
gateway [your gateway]

Lastly, reboot your Pi

sudo reboot

That should do the trick.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s