Troubleshooters.Com and T.C Linux Library Present

DHCP

Copyright (C) 1998, 1999 by Steve Litt, All rights reserved. Material provided as-is, use at your own risk.

Steve Litt is the author of Troubleshooting Techniques of the Successful TechnologistRapid Learning: Secret Weapon of the Successful Technologist, and Samba Unleashed.

Explanation

A Windows client needs an IP address. But it doesn't need the IP assignment to be hard-coded into the machine's configuration. Instead, it can receive its IP address from a server. The most common way to do that is via DHCP, standing for Dynamic Host Configuration Protocol. The DHCP server can be on an NT machine, or it can be on your Linux machine. This tutorial explains enabling your Linux machine to be a DHCP server.

Preliminaries

Your Linux machine might already be functioning as a DHCP server. The first step in finding out is to do this command:

ps -ax | grep dhcpd

If that command brings back an invocation of dhcpd, then it's running and most likely working. At that point, from the Windows machine, you'd ping the Windows machine and the Linux machine, and make sure they're in the same subnet. If so, it's most likely your DHCP is configured. However, if there's no dhcpd running, or if the Windows and Linux machines are on different subnets, you'll need to configure the dhcp server on the Linux box.

 find . -type f -exec grep -l 192.168.100.3 {} \;

Hello World

By Steve Litt, Steve Litt's email address
First, do the command

ps -ax | grep dhcpd

If it finds a running dhcpd, kill it. Now log in as root, and run the following command:

dhcpd -f

The -f makes it print to the screen instead of running in background. You might see it fail with a message something like this:
 
Can't open /etc/dhcpd.conf: No such file or directory

This tells you it can't open its configuration file. Create the above mentioned file, with just these few lines:
 
subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.200 192.168.100.240;
    }

Now try running dhcpd -f again. You might see if fail with a message something like this:
 
Can't open lease database /etc/dhcpd.leases: No such file or directory -- check for failed database rewrite attempt! 

Here it's telling you it can't open the leases file. A lease is a record of an assigned ip address, which is given to the client for a fixed amount of time (hence the name lease). As long as both the client and the server stay running and connected, the lease is constantly "renewed" so the client has a consistent ip address. If the client and server are disconnected for a long period, however, the lease expires and the client's next login may give him a different ip address.

Anyway, you have no leases file, so you must make one. Simply create a zero length file, with the name and location stated in the error message, using an editor. Now once again run the command

dhcpd -f

You'll probably see something looking like this:
 
[root@linuxhost /etc]# /usr/sbin/dhcpd -f
Internet Software Consortium DHCPD $Name: V2-BETA-1-PATCHLEVEL-6 $
Copyright 1995, 1996, 1997, 1998 The Internet Software Consortium.
All rights reserved.
Listening on Socket/eth0/192.168.100.0
Sending on   Socket/eth0/192.168.100.0

It's now running, listening for requests. And the next time your Windows machine logs in, it will receive an IP address and lease information will be added to the leases file. After the Windows machine logs in again, the leases file will look something like this:
 
lease 192.168.100.200 {
 starts 2 1998/12/01 20:03:10;
 ends 3 1998/12/02 08:03:10;
 hardware ethernet 00:00:e8:4c:5d:31;
 uid 01:00:00:e8:4c:5d:31;
 client-hostname "P2300";
}

Note that if your Windows machine previously received an IP from your Linux dhcp, and then your dhcpd.leases was erased and recreated, it might not write that info into it until the lease "expires" and then logs in again.
 

Full Client Autoconfiguration

DHCP can do a lot more than just give the client an IP address. In fact, a Windows client need only have a machine and workgroup name defined on its network identification tab, and DHCP can take care of the rest. Check out this /etc/dhcpd.conf:
 
subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.200 192.168.100.240;
        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.100.255;
        option routers 192.168.100.3;
        option domain-name-servers 192.168.100.3;
        option domain-name "mydomain.cxm";
        option ip-forwarding on;
        option netbios-node-type 8;
    }

 

Back to Troubleshooters.Com * Back to Linux Library