Can a computer running a DHCP server assign its own IP address, or does it have to be set statically? If this is a question which depends on the DHCP software, then my configuration is a Debian server running PiHole.
Technically, by the standards this could happen, but no network admin in his right mind will count on it working.
Most operating systems come up with an APIPA IP (169.254.1.0 to 169.254.254.255) when starting up. Therefore, the DHCP server might be able to run and possibly even answer requests.
In theory, if on the server the DHCP client daemon stays running and keeps on trying, it should in time be answered by the DHCP server daemon running on the same server. Then it should be able to set its own proper IP address, while continuing to answer DHCP requests from other computers.
This actually working depends a lot on the implementation of the DHCP client and server software of the operating system of the server computer.
I feel the other answers overlook a couple of things.
Can a computer running a DHCP server assign its own IP address
A DHCP server will give out IPs.
Before continuing - a DHCP server is a program running on a system that may also be running other things (it's not equivalent to a device). A DHCP server follows a process and expects things at certain times and in certain formats, that's described in the DHCP protocol.
A DHCP server isn't responsible for taking an offered IP and changing network configuration on a system - that's the responsibility of a DHCP client.
So the technical answer to this is no, because DHCP servers are not also DHCP clients.
Also: please understand that systems or servers don't really have IP addresses - it's network interfaces on those systems (or the systems servers run on) that do, and many systems have multiple interfaces. Your laptop has a wired Ethernet and wireless LAN interface most likely for example, and each can have its own distinct IP - so saying "What's the IP of my laptop" is really a misnomer - you should say "What's the IP of my wireless network adapter" to be 100% correct.
- Can you run a DHCP client on the same system as a DHCP server
And in the case of most home routers, this is already happening.
However, the router's DHCP server is listening on the LAN+WLAN interfaces, and the router's DHCP client is listening on the WAN or Internet interface.
This way, your router gets an IP from your ISP, and your router gives out private IPs to hosts on the LAN. Since client and server are listening on different interfaces, they don't interfere with one another.
- Can you make a DHCP server listen on an interface without an IP? This should work because it listens for broadcast addresses, right?
No. When the DHCP responds to the client, it has to set a source IP in the packet it's sending. IK will get the request from someone, but since the requestor has no IP, there's no source IP to set.
Setting that source IP to broadcast would allow any computer to respond to the DHCP offer and break DHCP.
So I imagine most DHCP server software won't listen on an interface without an IP.
So you can't have a DHCP server assign an IP to itself.
Yes, it is possible.
Computer, that is the host, and network address, is not the same. A host may have several physical network interfaces or one physical with a couple of virtual network interfaces.
The DHCP server has to have a static IP address. It is theoretically possible to have the DHCP server running on one interface with a static IP address, and have a DHCP client requesting a dynamic IP address on another interface on the same computer.
Say the host has two interfaces, enp2s0 and enp3s0. enp2s0 gets a static IP address for the DHCP server. A DHCP client configures enp3s0 with a dynamic IP address which it receives from the DHCP server listening on enp2s0 on the same host.
Probably not. Although it is technically possible to configure a DHCP server to listen on an autoconfigured address (169.254.xxx.xxx), most DHCP server software will fail with the message
no subnet declaration for eth0 or something similar and never start handing out IP addresses. So a static IP is pretty much required for DHCP servers.