10

This may seem a daft question (and i fear it might be), but would it be possible for a server acting as a network's sole DHCP server send out a request for an IP address to the network, then catch its own request and answer it?

All of my intuition points to a no answer and ideally i would test it out but i don't have the time/spare resources currently so i was hoping someone else may have had the same thought and tried it out.

This is meant to be a generic question but if anyone is interested i'm running isc-dhcp on ubuntu 11.04

2
  • I don't, but the devil was making work for idle minds.
    – user67678
    Commented Aug 12, 2011 at 9:35
  • 4
    The devil makes packets for idle networks. Commented Aug 12, 2011 at 11:30

5 Answers 5

9

Technically the specs would allow for that to happen but it would be beyond stupid to try to do so.

2

In theory I think it SHOULD be possible since most linux distros these come up with an apipa (169.254.0.1 to 169.254.255.254) address if none is configured or provided. Therefore the dhcp server should be able to run and possibly answer requests. Now if you configure a reserved (fixed) ip address for the server's own mac-address, and if the dhcp client daemon stays running and keeps trying, it should in theory be able to be answered by the dhcp server daemon. Then it should be able to set its own proper ip-address, and continue to answer dhcp requests from other machines.

I'm not sure if dhcp servers can have an apipa address, an I think the server daemon needs to be restarted after the ip change, but other than that... I still cannot think of any sensible use case for this.

1

As far as I know this is NOT possible. DHCP is not just broadcast based. The initial part of the DHCP protocol is broadcast based, but at some point the server and client talk using their IP-addresses.

If I recall correctly (don't have the RFC's at hand) the server is the first one in the conversation that needs to send real ip-address information.

This automatically makes it impossible to have the server serve itself.

Of course it is possible that the server itself is a DHCP client that receives it's DHCP config from ANOTHER DHCP server (usually a reserved-fixed ip). It's a bit odd, but I can imagine some use-cases for such a setup.

1

It's a bad idea in two ways but yes it is possible.

  1. The server can't assign an IP during boot-up when the DHCP server on the same machine hasn't been started yet. So you have to make sure that the DHCP server is up before trying to assign the IP.
  2. If the DHCP also updates the DNS for the dynamically assigned hosts then it is quite hard to know where your DHCP server is when the DNS fails (for whatever reason)
1

Perhaps you are looking for a single source of truth deployment strategy by using a single copy of dhcpd.conf to keep all network information like option routers, option domain-name-servers, option domain-name. You may try these steps (Debian):

Define a static IP address for network interface

This is require or else dhcp server won't start.

$ cat /etc/network/interfaces
auto eth0
allow-hotplug eth0
iface eth0 inet static
  address 192.168.1.1/24

Optional: Define a fixed ip address in DHCP client configuration

This step is optional unless you want the IP address for your DHCP host.

$ cat /etc/dhcp/dhclient.conf
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

interface "eth0" {
  send dhcp-requested-address 192.168.1.1;
}

Define a DHCP pool range for the network

$ cat /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {
  option domain-name "example.lan";
  option subnet-mask 255.255.255.0;
  option routers 192.168.1.254;
  option domain-name-servers 192.168.1.253;

  pool {
    range 192.168.1.10 192.168.1.200;
  }
}

Restart the machine and check you have a static IP address and dhcp server running. Now execute these to get IP address from DHCP server:

# Flush the IP address of interface eth0
$ ip a flush dev eth0

# Remove dhclient lease
$ rm /var/lib/dhcp/dhclient.*

# Start dhclient for interface eth0
dhclient -v eth0

A new IP address shall get allocate for the interface eth0 with DHCP requested options.

You must log in to answer this question.