DHCP on an RPM-based OS

From Alteeve Wiki
Jump to navigation Jump to search

 Alteeve Wiki :: How To :: DHCP on an RPM-based OS

Note: This is an older tutorial written for EL5 and EL6. New users should refer to the new EL7 based tutorial; Shorewall 5 on EL7.

Setting up a DHCP server on Fedora is quite easy. There are many ways that a DHCP server can be configured, but for now, we're going to setup a really simple server. This should be a good place to expand from, should you want to take advantage of advanced features.

Overview

You're probably familiar with DHCP from a client perspective; It's the method used to get an IP address from most networks when you join them. This is a pretty old and simple protocol and is easy to setup from the client's perspective. They simply plug into a network, and they have access; It just works.

What happens behind the scenes is that the client's computer broadcasts a DHCP request. If it's had an IP address from a DHCP server before, it might include a request to get that same IP address again. Failing that, the first DHCP server to respond with an offer will generally be accepted by the client and an IP address will be offered and configured. What we are doing here, then, is setting up a the server component that will listen for DHCP client requests.

A Word On Network Separation

Before you do though, you must take into account any other DHCP servers on your network. More to the point, you need to make sure there are no other DHCP servers on your network. The reason is that, when you try to PXE-boot a machine, it's up to the DHCP server that responds first to tell the client about the PXE server. If a "normal" DHCP server answers first, there simply won't be any instructions and your machine will not actually boot.

Installing the Server

Simply run the following.

yum install dhcp

The DHCP Configuration File

The core file to edit is /etc/dhcp/dhcpd.conf.

Note: On many systems, this *used* to be /etc/dhcpd.conf, but on Fedora 13+ and EL6+, it's been moved into it's own directory. If you are using EL5, please use /etc/dhcpd.conf.

vim /etc/dhcp/dhcpd.conf
### Global options
# General domain information
option domain-name "alteeve.ca";
option domain-name-servers 8.8.8.8, 8.8.4.4;

# Tell the server that it's authoritative on our network.
authoritative;

# This is required for EL5 operating systems but is optional on EL6 and newer
# Fedoras (F13+, at least). It controls how dynamic DNS updating is handled. In
# our case, we aren't concerned about DDNS so we'll set it to 'none'.
ddns-update-style none;

### Subnet options
subnet 10.255.0.0 netmask 255.255.0.0 {
	# This is the DHCP server, but not the actual Internet gateway. So this
	# Argument points our clients to the right box.
	option routers 10.255.255.254;
	
	# Set our range. This can be whatever you want so long as it fits in
	# your netmask.
        range 10.255.1.10 10.255.1.250;
	
	# If clients don't ask, make the lease available for the following
	# number of seconds. If the client does ask, allow up to this number of
	# seconds. 86,400s = 24h.
	default-lease-time 86400;
	max-lease-time 86400;
}

Starting the DHCP Server

Now set dhcpd to start with your machine and then start it up for the first time.

chkconfig dhcpd on
/etc/init.d/dhcpd start

Optional; Assign IPs by MAC Address

Perhaps the most common optional configuration is assigning IP addresses from the DHCP pool based on the MAC address of a client's network interface. This is accomplished by adding a small host directive for each client interface after the main subnet directive.

Let's see an example for two interfaces on a client's laptop; One for the wired interface and one for the wireless.

# Digimer's laptop; Wired
host lework_lan {
        hardware ethernet 00:24:7e:69:6f:0e;
        fixed-address 10.255.1.102;
}

# Digimer's laptop; Wireless
host lework_wlan {
        hardware ethernet 00:21:6a:58:f9:94;
        fixed-address 10.255.1.202;
}

Done!

This isn't meant to be a comprehensive dhcpd tutorial, so I am not showing a lot of options you may find useful. Please take the time to read the man 5 dhcpd.conf and man dhcp-options page to see all the other neat things you can do.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.