Setup Ubuntu Static IP

Step 1. Assign static IP, gateway, broadcast, etc

Edit the file

/etc/network/interfaces

and change as below (say you want to assign static IP to eth0):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

 
# The loopback network interface

auto lo
iface lo inet loopback
 
# This is a list of hotpluggable network interfaces.

# They will be activated automatically by the hotplug subsystem.

# uncomment them if you do hotplug sybsystem
mapping
hotplug
    script grep
    map eth0
 
# The primary network interface

auto eth0
iface eth0 inet static
address
192.168.0.200
netmask 255.255.255.0
network
192.168.0.0
broadcast
192.168.0.255
gateway
192.168.0.1

Step 2. Assign name server

Edit the file

/etc/resolv.conf

And put your name server into the file (the example below uses a internal name server at 192.168.0.100):

nameserver 192.168.0.100

 

Step 3. Stop dhcp client from updating resolv.conf

On an Ubuntu desktop, the dhcp client always update the resolv.conf upon network restart. For a box with static IP, this is not desired. If the package "dhcp-client" or "dhcp3-client" cannot be removed due to dependencies from other package, you can do a hack by editing or creating the file /etc/dhcp3/dhclient-enter-hooks, and add the following content:

make_resolv_conf() {
          echo "do nothing with resolv.conf"
}

This works for me on one box, but not the other. I checked and found a file /etc/dhcp3/dhclient-enter-hooks.d/resolvconf, inside which there is a function "make_resolv_conf()". Turning that function into one that does nothing will solve the problem.

 

Step 4. Restart your network

Just run

# /etc/init.d/networking restart

Then review your network setting:

# ifconfig