Blog2015 ≫ Static IP on a Raspberry Pi

I need a static ip address for some of my raspberry pis so I can route traffic to them from the outside world. If I want to see my security camera1 or remotely control my lights etc with the robot butler I need to know a) how to get to my house from the internet (I use dynamic dns for this, then b) how to get to the individual machine once we've got to my house. For this I need a static ip, so that the same machine is always on the same address. Since I upgraded to fibre optic from plus net I've lost the ability to have the router fix an ip address for each machine. So I have to do it the "proper" way now and do it on each machine...

Have tried this before, and failed, my raspberry pi disappeared from the network. And as I run them "headless" (no monitor, no keyboard) in an inaccessible place, then it's a pain. I have to find a monitor and keyboard and move stuff around, change the settings, then move it again when we're working again. But I made a change yesterday and all is good! Almost... All I need to do is update /etc/network/interfaces on each machine, here's an example:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.100 # the fixed address I want for this machine
netmask 255.255.255.0
gatweway 192.168.1.254 # the address of my [router](/wiki/#router)
  wpa-ssid "my [wifi](/wiki/#wifi) ssid goes here"
  wpa-psk "my [wifi](/wiki/#wifi) key goes here"

I say "almost"... all worked fine except at midnight, when something expired, one of the fixed machines stopped being able to connect out to the internet. So I've changed that machine back to dhcp while I investigate. But the rest is good!

raspberry pi: Credit card sized super cheap computer, awesome.

⬅️ :: ➡️

Paul Clarke's weblog - I live in A small town, Kent. Wed + dad to 2, I am a full-stack web engineer, + I do javascript / nodejs, some ruby, python, php ect ect. I like pubs, running, eating, home automation + other diy jiggery-pokery, history, tree stuff, TV, squirrels, pirates, lego, and TIME TRAVEL.