Tips & Tricks
Featured Article: Using Dynamic Host Configuration Protocol (DHCP)


How can more than one machine use a single Internet connection? How can you set up a lab, such that students or faculty can roam with their own laptops? A small business or school or anyone who uses laptops or moves their computers around may need to assign IP addresses on the fly. And it's really pretty easy to see how, in this month's Tips and Tricks.

This exercise describes a simple DHCP example where mobile Linux and Windows computers use a portion of the 192.168.1.0 subnet.

Installing dhcpd

First, you have to install the DHCP on a server, as shown in the following steps:

  1. Install the DHCP server:
    up2date -i dhcp
  2. Create the /etc/dhcpd.conf file and enter the following information:
    option routers 192.168.1.254;
    shared-network YOUR.NET {
     subnet 192.168.1.0 netmask 255.255.255.0 {
     range 192.168.1.40 192.168.1.50;
     }
     }

    The first section describes the range of IP addresses, within the class C subnet 192.168.1.0, that the DHCP clients are going to use.

  1. Create the /etc/dhcpd.leases file:
    touch /etc/dhcpd.leases

    You don't need to put anything into this file. The dhcpd daemon dynamically puts information here about the computers that are getting their IP addresses from DHCP. Those addresses are called leases.

  1. Start the dhcpd server:
    /sbin/service dhcp start
    #starts the service now
    /sbin/chkconfig dhcpd on
    #makes sure it starts next time

Your dhcpd server is now ready for client computers to get their IP addresses and routing information.

Configuring Red Hat Enterprice Linux WS or Fedora to use DHCP

You can use Main Menu > System Settings > Network, highlight and edit the network device, and click "edit" to set it to use DHCP

You can also modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file to make a Linux box look to the dhcpd server for its network configuration. The file should look as follows:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

The next time that you boot your Linux computer, or restart the network, you'll obtain the IP address, netmask, broadcast address, and routing information from the dhcpd server.


Note

If you manually modify the ifcfg-eth0 file, you don't need to remove the static IP information. By modifying the PROTOCOL parameter to use DHCP, your system will ignore the static information and pick up its parameters dynamically. However, your computer will revert to using the static parameters if the DHCP service is unavailable.


Configuring Windows as a DHCP Client

Setting up a Microsoft Windows computer to use DHCP is very simple:

  1. Login to your Windows computer. (NT systems require you to login as the administrator).
  2. Open the Network Configuration dialog box:
    Start--> Control Panel --> Network
  3. Open the TCP/IP properties dialog box.
  4. Click on the IP Address tab.
  5. Click on the Obtain an IP address dynamically radio button.
  6. Click on OK.
  7. Click on the OK button in the Network dialog box.
  8. Click OK when asked if you want to restart you computer.
  9. When your Windows computer restarts, it'll be assigned an IP address between 192.168.1.40 and 192.168.1.50; the address will be 192.168.1.40 the first time that you use this system. You can prove this to yourself by looking at the /etc/dhcpd.aliases file and/or pinging the 192.168.1.40 address.

Your Windows computer will now obtain its address from the DHCP server on your network. For instance, you can now use your laptop on both your home and work network (if they both use DHCP) without reconfiguring it each time.

For more tips like this refer to http://www.redhat.com/docs/ or the Red Hat Press line of books.