Setting up a static IP address on ubuntu

When you install a new Ubuntu release on your system, it sets things up to using DHCP by default.   It’s a handy default that will work for most people but if you intend on running this particular machine as a serer (NAS box, squeezebox server, print server…), you may find more convenient to have a static IP address which can easily be mapped to a name without the use of a DNS server.    The instructions below are based on ubuntu (10.x / 11.x and older/newer versions). 

How to setup a static / fixed IP address

  1. cd /etc/network
  2. sudo cp interfaces  interfaces.DHCP   (always good to make a copy of original files)
  3. sudo emacs intervaces   (substitute emacs for your favorite editor:  vi, gedit …)

Replace the content of the file with the following:

 # The loopback network interface
 auto lo
 iface lo inet loopback

 # The primary network interface
 auto eth0
 iface eth0 inet static
 address 192.168.1.X   (replace X with your host address)

Here we assume a home network of:  (most common behind NAT firewalls/routers).    Substitute with your own internal home network number.   Next follow those steps:

  • First find out what your current IP Address is:   sudo ifconfig | grep inet
  • Restart networking: sudo  /etc/init.d/networking restart
  • You will now be kicked out of the server if you had connected via ssh/telnet.
  • Check that the new IP Address is is now effective:   sudo ifconfig | grep inet
  • Then you must setup a static DNS server entry:

How to setup Static DNS server entry:

Since you are no longer getting your IP Address from DHCP, you also have to setup a static entry for your DNS server.   In most cases,  people don’t run an in-house DNS server and rely instead on their ISP to provide one.    Most home routers/firewalls acts  act as an intermediary DNS server  by relaying all requests to the upstream ISP configured DNS server.    In my case, using Cox or Comcast cable as the ISP,   my router obtains an IP address using DHCP which also configures DNS server info in my router.

To configure the static DNS server entry for my host:  (again my editor is emacs)

  • sudo emacs /etc/resolv.conf
  • Leave only the following line in the file:

(substitute for the IP address of your own router)

Configure /etc/hosts with our your home devices:

Most people don’t bother to run a DNS server internally (not worth it for 2-5 machines!).  the simplest way to map your host names (PCs, printers, Boxee box etc…) is to edit the “hosts” file:

sudo emacs /etc/hosts

Here is what mine looks like:       localhost    greenbug    jumbo     tomato     unas    vonage-biz    vonage-home   BigBubba-Printer

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

With the last lines were already in the hosts file, setup by ubuntu to support IPV6 (leave it alone).    These three simple setups should have your system properly configured with a static IP address.

NOTE:  I also make a copy of the /etc/network/interfaces file as interfaces.STATIC to have a backup of this configuration.  This way if I travel with my laptop and need to access DHCP at the hotel room, I can just copy the interfaces.DHCP and restart my networking (or reboot) and the system then behaves as a normal dhcp client.


About admin

My name is Christian Marcotte. I live in San Diego with my wife Carolyn and our son Jeremiah. This site is a recording of my currrent ponderings, hobbies and interest.
This entry was posted in Linux, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *