Выбрать главу

 max-lease-time 172800; # 2 days

 # Dynamic configuration

 range 192.168.1.128 192.168.1.191

 # Static configuration for various hosts

 host prime {

  hardware ethernet 00:0c:0d:99:99:99 ;

  fixed-address 192.168.1.1 ;

 }

 host cabinet {

  hardware ethernet 00:0c:0d:aa:aa:aa ;

  fixed-address 192.168.1.2 ;

 }

 host chatterbox {

  hardware ethernet 00:0c:0d:bb:bb:bb ;

  fixed-address 192.168.1.3 ;

 }

 host laser1 {

  hardware ethernet 00:0c:0d:cc:cc:cc ;

  fixed-address 192.168.1.64 ;

 }

 host multifunction1 {

  hardware ethernet 00:0c:0d:dd:dd:dd ;

  fixed-address 192.168.1.65 ;

 }

 host webcam1 {

  hardware ethernet 00:0c:0d:ee:ee:ee ;

  fixed-address 192.168.1.66 ;

 }

 host gateway1 {

  hardware ethernet 00:0c:0d:ff:ff:ff ;

  fixed-address 192.168.1.254 ;

 }

}

Table 7-3. Sample hardware addresses

Hardware MAC address Hostname
00:0c:0d:99:99:99 prime
00:0c:0d:aa:aa:aa cabinet
00:0c:0d:bb:bb:bb chatterbox
00:0c:0d:cc:cc:cc laser1
00:0c:0d:dd:dd:dd multifunction1
00:0c:0d:ee:ee:ee gateway1

Once your configuration has been saved in /etc/dhcpd.conf , restart dhcpd to activate it using the Services graphical tool or this command:

# service dhcpd restart

If there are errors in your configuration file, dhcpd may not start. Check the end of the file /var/log/messages to see if there are any error messages:

# tail -50 /var/log/messages|less

If there are no error messages, clients can begin using the dhcpd server to obtain their IP addresses.

You will need to open port 68 UDP in your firewall configuration in order to permit clients to reach dhcpd. You should also verify that no other DHCP servers are running on your network (check router and gateway appliances in addition to computers). 

If configured to obtain IP information through DHCP, the client systems will contact the DHCP server when they are booted. You can also force them to contact the DHCP server at any time:

 On a Fedora Core 4 or later system, use dhclient to configure an Ethernet port using DHCP:

# dhclient eth0  

 In this case, the port being configured is eth0 , the first Ethernet connection. On other Linux systems, you may need to use dhcpcd or pump in place of dhclient .

 On a Windows system, you can use ipconfig to obtain or renew a DHCP lease:

 C:> ipconfig /renew

 Windows IP Configuration

 Ethernet adapter 1:

 Connection-specific DNS Suffix . : fedorabook.com

 IP Address. . . . . . . . . . . . : 192.168.1.207

 Subnet Mark . . . . . . . . . . . : 255.255.255.0

 Default Gateway . . . . . . . . . : 192.168.1.254

7.2.2. How Does It Work?

Table 7-4 shows the sequence of messages that flow between a DHCP client and a DHCP server during initial negotiation and during lease renewal.

Table 7-4. DHCP messages.

Context Message type Origin Description
Initial negotiation Lease renewal      
*   DHCPDISCOVER Client Client tries to discover the DHCP server.
*   DHCPOFFER Server The DHCP server offers its location and possible lease details.
* * DHCPREQUEST Client The client requests a lease.
* * DHCPACK/DHCPNACK Server The server acknowledges (approves) or negatively acknowledges (rejects) the lease request.

Early DHCP messages are sent using UDP to the broadcast address 255.255.255.255. This is necessary because the client does not have an IP address at the start of the negotiation.

dhcpd stores lease information in the file /var/lib/dhcpd/dhcpd.leases so that if it is stopped and restarted, it still has an idea of what leases are outstanding. In a similar way, dhclient stores its lease information in /var/lib/dhcp/dhclient-<eth0>.leases (where <eth0> is the interface name).