Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
14.4. Configuring a Multihomed DHCP Server
A multihomed
DHCP
server serves multiple networks, that is, multiple subnets. The examples in these sections detail how to configure a DHCP
server to serve multiple networks, select which network interfaces to listen on, and how to define network settings for systems that move networks.
Before making any changes, back up the existing
/etc/dhcp/dhcpd.conf
file.
The
DHCP
daemon will only listen on interfaces for which it finds a subnet declaration in the /etc/dhcp/dhcpd.conf
file.
The following is a basic
/etc/dhcp/dhcpd.conf
file, for a server that has two network interfaces, enp1s0 in a 10.0.0.0/24
network, and enp2s0 in a 172.16.0.0/24
network. Multiple subnet
declarations allow you to define different settings for multiple networks:
default-lease-time 600; max-lease-time 7200; subnet 10.0.0.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 10.0.0.1; range 10.0.0.5 10.0.0.15; } subnet 172.16.0.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 172.16.0.1; range 172.16.0.5 172.16.0.15; }
-
subnet 10.0.0.0 netmask 255.255.255.0;
- A
subnet
declaration is required for every network yourDHCP
server is serving. Multiple subnets require multiplesubnet
declarations. If theDHCP
server does not have a network interface in a range of asubnet
declaration, theDHCP
server does not serve that network.If there is only onesubnet
declaration, and no network interfaces are in the range of that subnet, theDHCP
daemon fails to start, and an error such as the following is logged to/var/log/messages
:dhcpd: No subnet declaration for enp1s0 (0.0.0.0). dhcpd: ** Ignoring requests on enp1s0. If this is not what dhcpd: you want, please write a subnet declaration dhcpd: in your dhcpd.conf file for the network segment dhcpd: to which interface enp2s0 is attached. ** dhcpd: dhcpd: dhcpd: Not configured to listen on any interfaces!
-
option subnet-mask 255.255.255.0;
- The
option subnet-mask
option defines a subnet mask, and overrides thenetmask
value in thesubnet
declaration. In simple cases, the subnet and netmask values are the same. -
option routers 10.0.0.1;
- The
option routers
option defines the default gateway for the subnet. This is required for systems to reach internal networks on a different subnet, as well as external networks. -
range 10.0.0.5 10.0.0.15;
- The
range
option specifies the pool of availableIP
addresses. Systems are assigned an address from the range of specifiedIP
addresses.
For further information, see the
dhcpd.conf(5)
man page.
Warning
To avoid misconfiguration when DHCP server gives IP addresses from one IP range to another physical Ethernet segment, make sure you do not enclose more subnets in a shared-network declaration.
14.4.1. Host Configuration
Before making any changes, back up the existing
/etc/sysconfig/dhcpd
and /etc/dhcp/dhcpd.conf
files.
Configuring a Single System for Multiple Networks
The following /etc/dhcp/dhcpd.conf
example creates two subnets, and configures an IP
address for the same system, depending on which network it connects to:
default-lease-time 600; max-lease-time 7200; subnet 10.0.0.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 10.0.0.1; range 10.0.0.5 10.0.0.15; } subnet 172.16.0.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 172.16.0.1; range 172.16.0.5 172.16.0.15; } host example0 { hardware ethernet 00:1A:6B:6A:2E:0B; fixed-address 10.0.0.20; } host example1 { hardware ethernet 00:1A:6B:6A:2E:0B; fixed-address 172.16.0.20; }
-
host example0
- The
host
declaration defines specific parameters for a single system, such as anIP
address. To configure specific parameters for multiple hosts, use multiplehost
declarations.MostDHCP
clients ignore the name inhost
declarations, and as such, this name can be anything, as long as it is unique to otherhost
declarations. To configure the same system for multiple networks, use a different name for eachhost
declaration, otherwise theDHCP
daemon fails to start. Systems are identified by thehardware ethernet
option, not the name in thehost
declaration. -
hardware ethernet 00:1A:6B:6A:2E:0B;
- The
hardware ethernet
option identifies the system. To find this address, run theip link
command. -
fixed-address 10.0.0.20;
- The
fixed-address
option assigns a validIP
address to the system specified by thehardware ethernet
option. This address must be outside theIP
address pool specified with therange
option.
If
option
statements do not end with a semicolon, the DHCP
daemon fails to start, and an error such as the following is logged to /var/log/messages
:
/etc/dhcp/dhcpd.conf line 20: semicolon expected. dhcpd: } dhcpd: ^ dhcpd: /etc/dhcp/dhcpd.conf line 38: unexpected end of file dhcpd: dhcpd: ^ dhcpd: Configuration file errors encountered -- exiting
Configuring Systems with Multiple Network Interfaces
The following host
declarations configure a single system, which has multiple network interfaces, so that each interface receives the same IP
address. This configuration will not work if both network interfaces are connected to the same network at the same time:
host interface0 { hardware ethernet 00:1a:6b:6a:2e:0b; fixed-address 10.0.0.18; } host interface1 { hardware ethernet 00:1A:6B:6A:27:3A; fixed-address 10.0.0.18; }
For this example,
interface0
is the first network interface, and interface1
is the second interface. The different hardware ethernet
options identify each interface.
If such a system connects to another network, add more
host
declarations, remembering to:
- assign a valid
fixed-address
for the network the host is connecting to. - make the name in the
host
declaration unique.
When a name given in a
host
declaration is not unique, the DHCP
daemon fails to start, and an error such as the following is logged to /var/log/messages
:
dhcpd: /etc/dhcp/dhcpd.conf line 31: host interface0: already exists dhcpd: } dhcpd: ^ dhcpd: Configuration file errors encountered -- exiting
This error was caused by having multiple
host interface0
declarations defined in /etc/dhcp/dhcpd.conf
.