Python Mercenaries

My Ubuntu 12.04's Statically Dynamic IP Address

written by Joseph Nix on 2013-05-03

I ran across a curious networking problem last week.

I have a few virtualizations running Ubuntu 12.04, that I keep that run a few development servers of various things. I recently gave one of them a static IP address so I could more easily access it in the near future, from wherever in my network I happen to be. This server was headless (no GUI), so I used my go-to method for setting a static IP address. That is, I opened up the network interfaces config file in /etc/network/interfaces, and modified it to make it look something like this:

auto eth0
iface eth0 inet static

This is exactly the protocol outlined in, in the section titled "Static IP Address Assignment," if you want to follow along. After a quick networking restart, I'm done! I've successfully got a brand new static IP. I ssh into my virtualization, and get to work! 

Now for the twist!

Later that day, while running an innocuous command via ssh, I get a broken pipe! My ssh session is broken! I soon find out that my 12.04 box has reacquired an IP address dynamically.

For some background, you should know that the router I was using does have dhcp running, and will hand out dynamic IPs when requested, to a specified range. So for example, everything over .128, which is where the new IP address was located. I also happen to know that the IP address the 12.04 box had was not being used by anything else; it was free, so nothing was fighting over it.

I've ran into this problem before, so I knew what to do. Unintuitively, even if you set a static IP in this config file, which I would think would be authoritative, it won't stick in Ubuntu if you still have a dhcp client installed. I think I've ran into this in older versions of Ubuntu as well. I am unaware though, if later versions have changed this.

There are a few variants of the dhcp client. I don't need them, so my quick fix is simply to remove them. So to catch them and set the static IP once and for all:

change your config file
sudo apt-get remove dhcp-client isc-dhcp-client dhcp3-client
sudo /etc/init.d/networking restart

Another link that explains how to set up a static IP in a very similar way, and includes this important step as well as

« Previous | My Ubuntu 12.04's Statically Dynamic IP Address | Next »