Setting a static IP on your Raspberry Pi / Linux
This page explains how to configure a static IP on your Raspberry Pi / Linux machine, presuming you already know the IP address to use, the gateway IP and the netmask. Things are different on Raspbian Jessie, which is where I will start. For Wheezy, see further down.
So, they changed the way you configure your network interfaces in Raspbian Jessie and not for the better! In /etc/network/interfaces there is a comment telling you:
# Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
So, lets go there:
sudo nano /etc/dhcpcd.conf
In previous versions (see below), we set up the netmask, network and broadcast IP's, but in Jessie, we just use the netmask bits (eg /24) after our actual IP to set these automatically. Also, we no longer set our name servers in /etc/resolv.conf but in /etc/dhcpcd.conf
Add these lines at the bottom of /etc/dhcpcd.conf
#Static IP Setup interface eth0 static ip_address=10.10.10.10/26 static routers=10.10.10.1 static domain_name_servers=22.214.171.124 126.96.36.199
Adjust to suit. Most people would use /24 netmask bits, for 254 useable IP's.
Now for the usual 'old' settings before Jessie!
Open the interfaces file in nano:
sudo nano /etc/network/interfaces
The default looks like:
auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Now, we dont need wlan0 or any default settings, or DHCP on eth0, so we can change the file to a manually configured eth0, like this (these are my settings, so change yours to suit!):
auto lo iface lo inet loopback iface eth0 inet static address 10.10.10.10 netmask 255.255.255.192 network 10.10.10.0 broadcast 10.10.10.63 gateway 10.10.10.1
To work out the network and broadcast IP's, we use the netmask. I use a netmask of 255.255.255.192 (or /26 netmask bits), as it gives me 62 useable IP addresses and thats more than enough for my home network, therefore my 'network' is 10.10.10.0, my 'broadcast' is 10.10.10.63 and my gateway (router) is 10.10.10.1. The 62 IP's inbetween are the useable IP's.
Most home networks will be using the netmask 255.255.255.0 (or /24 netmask bits), giving 254 useable IP's. In this case, the 'network' will be x.x.x.0 and the 'broadcast' would be x.x.x.255. There are many online calculators to help you find these values.
You should know how your router/gateway is set up with regards to IP addresses (or set it up yourself), so you know which are available for static use and what range is in the DHCP pool. This is how I have mine:
Most of the equipment on my home network is setup with a static IP, however I have set my DHCP (v4) pool to have 10.10.10.31 to 10.10.10.62 which is plenty. This leaves me with 10.10.10.1 to 10.10.10.30 to assign myself, although I have used 10.10.10.1 for my gateway.
Good luck setting up your home network and learning along the way!