Setting a static IP with Ubuntu Server 12.04

I decided to setup a web server (Ubuntu 12.04) on a spare box i’ve had laying around. Since there isn’t a GUI for the version I installed I was dropped right into the command line after the quick and easy install. Command line hasn’t really been my strong suite so I wanted to force myself to use it. Anyway, my first order of business after installing it was to set it up on a static IP so that I could SSH to it from my main computer to work with it. It proved to be a tad tricky (mostly because I made a stupid assumption!)

Step 1

Open up /etc/network/interfaces and look for the lines that reads:

auto eth0
iface eth0 inet dhcp

Change the dhcp to static

auto eth0
iface eth0 inet static

Then below that you should fill in the following (with your own network settings)

auto eth0
iface eth0 inet static

The one spot I got hung up on was that I had assumed my gateway ended in a .1 since that is how I normally set my router IPs. For some reason I had set my IP to be though and set my router to not assign IPs above .189. So if you are questioning what your gateway IP is and are on a mac give this a shot to see what it is:

route -n get default

It should output something similar to this:

 route to: default
destination: default
       mask: default
  interface: en0
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0

After that you need to restart your networking service with the following:

sudo service networking restart

Leave a Reply

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