Everyday Thaumaturgy
(It's a Miracle If I Get Anything Done Around Here)
a blog by William S. Statler

Obscure problem using DHCP from a dual-boot (Linux/Windows) computer

Fri, 27 Mar 2009 13:00:00 PDT

I added a second Ethernet card to my wife's Ubuntu 8.04 desktop system, and (using Firestarter) set it up to be the router and DHCP server for our two-computer home network. This worked great when I connected my laptop computer and booted up Ubuntu Linux. It continued to work when I rebooted the laptop with Windows XP. But then when I booted Ubuntu again, BLAARP! no network connection.

Duh? How did running Windows manage to break the network for a subsequent restart with Linux?

This turned out to be a rather obscure feature (or bug) of DHCP, and most people will never run into this problem. But since I found it rather hard to track down, I'll document it here, to the extent I understand it.

How DHCP works (or doesn't)

First, for my totally confused readers, here's a nice explanation of DHCP from the Firestarter site:

DHCP [Dynamic Host Configuration Protocol] is a network protocol that among other things can dynamically distribute IP addresses and other network setting to computers. ...

...a DHCP server is started ... that distributes DHCP leases to the client machines. A lease supplies the clients with all the information needed to connect to the network. This information includes a unique IP address for each client, the default gateway, the subnet mask and the domain name servers in use. ...

So that is what is supposed to happen when my laptop computer gets connected to our home network or rebooted. The best place to see what actually happened is in the log messages generated by the DHCP daemon, and those messages are in /var/log/daemon.log on the computer that's acting as the DHCP server.

But log files are dull and confusing, so here's the story in another format:

Scene: a dock. Enter stage left: DHCP DAEMON, dressed in black, dragging a large fishing net, within which are the LADIES OF THE NET.

DHCP DAEMON:I am the monarch of IP
The Daemon of DHCP
The local network's big celeb
LADIES OF THE NET:And we are the E-Mail and the Torrents and the Web
And we are the E-Mail and the Torrents and the Web
The E-Mail and the Torrents and the Web!

Enter stage right, in a dinghy: LAPTOP, dressed as a cuddly penguin.

LAPTOP:I'm a little Linux laptop, longing to link with the Ladies of the Net.
DHCP Daemon, do you have an IP address for me?
My Ethernet hardware MAC address is 01:23:45:67:89:AB.
DHCP DAEMON:Hello, Hardware #01:23:45:67:89:AB. I can offer you 192.168.1.2.
And you'd better like it, because it's all I've got.
LAPTOP:I would be delighted to have 192.168.1.2!
DHCP DAEMON:Ickity ackity oop! It's yours.

LAPTOP and the LADIES OF THE NET interface gleefully for many hours. Suddenly, the sun sets, a full moon rises, wolves howl, and LAPTOP convulses in the throes of rebooting. When he stands up again, he is wearing a Bill Gates mask.

LAPTOP:I'm a wonderful Windows laptop, wanting to work with the Ladies of the Net.
DHCP Daemon, do you have an IP address for me?
My Ethernet hardware MAC address is 01:23:45:67:89:AB.
And my UID is "Gibberish"!
DHCP DAEMON:Hello, Hardware #01:23:45:67:89:AB. You can keep using 192.168.1.2.
And I'm updating your lease with your new UID, "Gibberish".
LAPTOP:Thanks, Bud, I'll take that 192.168.1.2.
DHCP DAEMON:Ickity ackity oop! It's yours.

LAPTOP and the LADIES OF THE NET share data until moonset. Again LAPTOP convulses and reboots, and the first rays of dawn reveal him dressed once again as a cuddly penguin.

LAPTOP:I'm a little Linux laptop, longing to link with the Ladies of the Net.
DHCP Daemon, do you have an IP address for me?
My Ethernet hardware MAC address is 01:23:45:67:89:AB.
DHCP DAEMON:Nope, sorry. UID "Gibberish" is using the only IP address I've got.
LAPTOP:But, but, but — He is me! I am he!
DHCP DAEMON:Sorry, kid. Only "Gibberish" can dock here, so shove off!

The DHCP server daemon gives priority to the UID if it's known. Windows always gives a UID when it contacts the DHCP server; Linux never does. So, if a dual-boot computer contacts the server while running Windows, it will not be recognized as the same machine if it later contacts the server while running Linux — even though it identifies itself as the exact same piece of hardware. This will persist until the expiration of IP address lease that was used under Windows.

For most people, this doesn't matter. The DHCP server will simply assign a different IP address when the dual-boot system shows up running Linux. The problem will only arise if the server doesn't have any spare addresses available.

Well, I'd created exactly that situation, on purpose. I wanted my laptop computer to always have the same fixed IP address (192.168.1.2) whenever it's connected to our home network. (A fixed address makes it simpler to share an old printer that is connected to the laptop.) So when I set up DHCP (using Firestarter), I'd told it to assign only this one address. Oops.

There is an option, deny duplicates, which is supposed to fix this behavior. Add that option to your /etc/dhcp3/dhcpd.conf file, and the DHCP server will pay attention to the Ethernet hardware MAC address instead of the UID. The only problem is, it doesn't work. I don't know why; it just doesn't.

So there's another option — and, in fact, this is a better way to assign a fixed IP address to a specific machine than the trick I'd been using. It looks like this:

host my-computer-name {
     hardware ethernet xx:xx:xx:xx:xx:xx;
     fixed-address xxx.xxx.xxx.xxx;
}

I added this to my /etc/dhcp3/dhcpd.conf file, and customized it for my network and computer ("my-computer-name" = the name of my laptop machine, "xx:xx:xx:xx:xx:xx" = the Ethernet MAC address of the laptop, and "xxx.xxx.xxx.xxx" = the fixed IP address I wanted to use). And, by golly, it worked!

Addendum: How to edit dhcpd.conf

1: Stop the DHCPD daemon:

sudo /etc/init.d/dhcp3-server stop

2: Edit the file:

gksu gedit /etc/dhcpd3/dhcpd.conf

Or use your favorite editor. Always use gksu to start a Gnome-based (GUI) program with root privileges; use sudo for text-based programs (ones that run in the terminal window).

3: After editing and saving the file, restart the DHCPD daemon:

sudo /etc/init.d/dhcp3-server start

If you're logged in as root, you can skip all the sudo and gksu stuff.

Copyright © 2009 William S. Statler (except for quotes and
contributions from other authors). This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
which grants limited rights of non-commercial distribution and reuse. Please read
http://creativecommons.org/licenses/by-nc-sa/3.0/us/
for details. All other rights reserved.