Tested on 23 May 2003 on Red Hat9

dhcp-3.0PL1-23 (DHCPD)

Description

dhcpd - Dynamic Host Configuration Protocol Server

The Internet Software Consortium DHCP Server, dhcpd, implements the Dynamic Host Configuration Protocol (DHCP). DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached.

Configure

  1. Install DHCP from Red Hat CD
  2. # rpm -ihv dhcp-3.0PL1-23.i386.rpm
    
  3. Copy a configuration file
  4. # cp /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample /etc/dhcpd.conf
    
  5. Edit /etc/dhcpd.conf
    ddns-update-style interim;
    ignore client-updates;
    
    subnet 192.168.0.0 netmask 255.255.255.0 {
    
    # --- default gateway
            option routers                  192.168.0.1;
            option subnet-mask              255.255.255.0;
    
            option nis-domain               "domain.org";
            option domain-name              "domain.org";
            option domain-name-servers      192.168.0.1;
    
    # Eastern Standard Time GMT -05:00 = -5x60x60 = -18000
    #        option time-offset              -18000; 
    # Eastern Standard Time GMT +06:00 =  6x60x60 =  21600
            option time-offset              21600; 
           option ntp-servers              192.168.0.1;
           option netbios-name-servers     192.168.0.2;
    # --- Selects point-to-point node (default is hybrid). Don't change this unless
    #       option netbios-node-type 2;
    
            range dynamic-bootp 192.168.0.128 192.168.0.255;
            default-lease-time 21600;
            max-lease-time 43200;
    
            # we want the nameserver to appear at a fixed address
            host ns {
                    next-server ns.domain.org;
                    hardware ethernet 12:34:56:78:AB:CD;
                    fixed-address 192.168.0.3;
            }
    }
    
  6. Start the service
    # /etc/rc.d/init.d/dhcpd start
    
  7. Run DHCPD as a service when it restarted. (ntsysv or redhat-config-services also ok)
    # chkconfig dhcpd on
    

Setup client

  • Windows 95/98/Me

    Run winipcfg.exe to check IP Address

  • Windows NT/2000

    Open DOS Command Prompt and type ipconfig. example
    SampleDescription
    ipconfig Show information
    ipconfig /all Show detailed information
    ipconfig /renew EL* renew all adapters
    ipconfig /release *ELINK?21* release all matching adapters

  • Red Hat Linux 8.0 and 9
    SampleDescription
    ifconfig Show information
    dhclient Get IP Address
    dhclient -r Release
    dhclient -1 Try once to get a lease
  • Old Red Hat Linux
    SampleDescription
    ifconfig Show information
    pump Get IP Address
    pump -k End pump daemon and return IP Address to DHCP Server
    pump -s Show information

    Showing leased list by PHP on the web

    <html>
    <head>
    <title>DHCPD Leased List</title>
    </head>
    <body>
    <h1>DHCPD Leased List</h1>
    <?
    $fileleases = "/var/lib/dhcp/dhcpd.leases";
    $dl=file($fileleases);
    $ln=0;
    for ( $i = 0 ; $i <= sizeof($dl) ; $i++) {
    	$item=chop(ltrim($dl[$i]));
    	if ( substr($item, 0, 5) == "lease" ) {
    		$ln++;
    		$dhcplist[$ln]['ip']=substr($item, 6, strpos($item, " ", 7)-6);
    		}
    	elseif ( substr($item, 0, 1) != "}") {
    		switch( substr($item,0,3)) {
    			case "sta";
    				$dhcplist[$ln]['sta'] = substr($item, 9, strrpos($item, ";") -9);
    				break;
    			case "end";
    				$dhcplist[$ln]['end'] = substr($item, 7, strrpos($item, ";") -7);
    				break;
    			case "uid";
    				$dhcplist[$ln]['uid'] = substr($item, 4, strrpos($item, ";") -4);
    				break;
    			case "har";
    				$dhcplist[$ln]['har'] = substr($item, 9, strrpos($item, ";") -9);
    				break;
    			case "cli";
    				$dhcplist[$ln]['cli'] = substr($item, 17, strrpos($item, ";") -18);
    				break;
    			case "aba";
    				$dhcplist[$ln]['aba'] = TRUE;
    				break;
    			}
    		}
    	}
    ?>
    <table width=100% border=1 align=center>
    <tr><th>#</th><th>Hostname</th><th>IP</th><th>Hardware</td><th>Start</th><th>End</th></tr>
    <?
    $count=0;
    for ($i=1; $i<=$ln; $i++) {
    	if (!$dhcplist[$i]['aba']) {
    		$count++;
    		echo "<tr>";
    		echo "<th>" . $count . "</th>";
    		echo "<td>" . $dhcplist[$i]['cli'] . "</td>";
    		echo "<td>" . $dhcplist[$i]['ip'] . "</td>";
    		echo "<td>" . $dhcplist[$i]['har'] . "</td>";
    		echo "<td>" . $dhcplist[$i]['sta'] . "</td>";
    		echo "<td>" . $dhcplist[$i]['end'] . "</td>";
    		echo "</tr>";
    		}
    	}
    ?>
    </table>
    <p align="right">Last Updated;
    <? echo date("Y/m/d (D) H:i:s", filemtime($fileleases)); ?>
    </p>
    </body>
    </html>
    

    Back
    Google
    Web www.grape-info.com