CentOS: DHCP Server and DHCP relay on same machine

centosdhcpdhcp-server

  • eth0 IP: 192.168.1.100
  • Alias interface eth0:dhcp IP: 10.10.1.100

dhcpd.conf:

authoritative;
local-address 10.10.1.100;

subnet 10.10.1.0 netmask 255.255.255.0 {

    range 10.10.1.10 10.10.1.50;
    option routers 10.10.1.1;
    option domain-name-servers 8.8.8.8, 8.8.4.4;

}

Running processes:

# ps -elf | grep [d]hcp
4 S root      1876  1867  0  80   0 -  1661 poll_s 11:11 pts/2    00:00:00 dhcrelay -i eth0 10.10.1.100 -i eth0:dhcp -d
5 S dhcpd     1947     1  0  80   0 - 12121 poll_s 11:38 ?        00:00:00 /usr/sbin/dhcpd -user dhcpd -group dhcpd eth0:dhcp

I see DHCP DISCOVERs coming on eth0 and the relay agent forwards it to 10.10.1.100:

Forwarded BOOTREQUEST for <mac_address> to 10.10.1.100
Forwarded BOOTREQUEST for <mac_address> to 10.10.1.100
Forwarded BOOTREQUEST for <mac_address> to 10.10.1.100
Forwarded BOOTREQUEST for <mac_address> to 10.10.1.100

but DHCP server logs the following message:

Sep  4 11:13:47 localhost dhcpd: DHCPDISCOVER from <mac_address> via 192.168.1.1: unknown network segment
Sep  4 11:13:50 localhost dhcpd: DHCPDISCOVER from <mac_address> via 192.168.1.1: unknowk network segment
Sep  4 11:13:54 localhost dhcpd: DHCPDISCOVER from <mac_address> via 192.168.1.1: unknown network segment
Sep  4 11:13:59 localhost dhcpd: DHCPDISCOVER from <mac_address> via 192.168.1.1: unknown network segment

IP forwarding is enabled:

net.ipv4.ip_forward = 1

Basically the server must be on 192.168.1.0/24 network however it should distribute IPs from 10.10.1.0/24 range.

Best Answer

Assuming ISC DHCPD you do not need dhcp relay but you need shared-network in your dchpd.conf:

authoritative;
local-address 10.10.1.100;

shared-network eth0 {

    subnet 192.168.1.100 netmask 255.255.255.0 {
    }

    subnet 10.10.1.0 netmask 255.255.255.0 {

        range 10.10.1.10 10.10.1.50;
        option routers 10.10.1.1;
        option domain-name-servers 8.8.8.8, 8.8.4.4;

    }
}