Networking / Beginners

Configuring DHCP

You configure DHCP settings through a file called dhcpd.conf that lives in the /etc directory. Fedora provides you with a sample configuration file located in the directory /usr/share/doc/dhcp-version/dhcpd.conf. sample. Open this file in the text editor and then save it to the /etc directory, changing its name from dhcpd.conf.sample to just dhcpd.conf. Then, edit the file to reflect the settings that you want to use.

Listing-1 shows the sample configuration file that comes with Fedora.

Listing-1: A Sample dhcpd.conf File
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.1.1;
	option time-offset 	-18000; # Eastern Standard Time
# 	option ntp-servers 	192.168.1.1;
# 	option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this
# -- unless you understand Netbios very well
# 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 marvin.redhat.com;
		hardware ethernet 12:34:56:78:AB:CD;
		fixed-address 207.175.42.254;
		}
}

The following paragraphs describe some of the key points of this file:

  • ddns-update-style: The DHCP standards group is in the midst of deciding exactly how DHCP will handle changes to DNS data. This option specifies that the interim method should be used. This line is required - so don't mess with it.
  • subnet: This line specifies a subnet that's managed by this DHCP server. Following the subnet ID and netmask is an opening bracket; all the options that appear between this bracket and the closing bracket in the last line of the file belong to this subnet. In some cases, your DHCP server may dole out IP configuration information for two or more subnet groups. In that case, you need additional subnet groups in the configuration file.
  • option routers: This line provides the IP address of the Default Gateway.
  • option subnet mask: This line provides the subnet mask for the subnet.
  • option nis-domain: This line provides the NIS domain name. This line is important only if you've set up one or more NIS servers.
  • option domain-name: This line provides the domain name for the network.
  • option domain-name-servers: This line provides the IP addresses of your DNS servers.
  • range: This line specifies the range of addresses that the DHCP server will assign for this subnet.
  • default-lease-time: This line determines the default lease time in seconds.
  • max-lease-time: This line determines the maximum life of a lease.
  • host: This line specifies a reservation. The host group specifies the MAC address for the host and the fixed IP address to be assigned.

Starting DHCP

After you've set up the configuration file, you can start DHCP by opening a terminal window or virtual console and entering the following command:

dhcpd start

If an error exists in the configuration file, a message to that effect is displayed. You have to edit the file in order to correct the error and then start the DHCP service again.

You should also restart the service whenever you make a change to the configuration file. To restart DHCP, enter this command:

dhcpd restart

To automatically start DHCP whenever you start the computer, run this command:

chkconfig -level 35 dhcpd on
[Previous] [Contents] [Next]