Configuring your interface with a static IP address (via /etc/network/interfaces)

Sun, 08/26/2012 - 19:28 -- jamie

Sometimes, it's useful to configure you computer with a static IP address rather than a dynamic one provided via DHCP.

When manually configuring an interface, you will need at least three pieces of information:

  • IP address - The IP address that you want to assign to your device
  • The gateway IP address - The IP address of the gateway on your network
  • The subnet mask - the information that allows your network stack to know what addresses are local and what addresses can only be reached via the gateway

In order to access this information, you can run the following command as root:

route -nee

You should then see output similar to this (note: this gives you the gateway and the subnet mask):

root@virilio:~# route -nee
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface    MSS   Window irtt
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0    0     0      0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0    0     0      0
root@virilio:~# 

One method for configuring a static IP address is to edit your /etc/network/interfaces file.

Before editing this file, be sure to bring down the interface you want to assign a static IP address to (e.g. ifdown eth0).

Then, you can add the following, modify the address, gateway and netmask values as appropriate, based on the values from the output of 'route -nee':

iface eth0 inet static
   address 192.168.69.76
   gateway 192.168.69.1
   netmask 255.255.255.0

When you are done, bring up your interface with:

ifup eth0