Can a computer running a DHCP server assign its own IP address?
The DHCP server must have a static IP - this is because of a chicken-egg problem:
- During the DHCP process, the server communicates its IP address to the client
- If the server is also the client, this step can't succeed (as there is not yet an address to communicate).
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.
Now ...
- Can you run a DHCP client on the same system as a DHCP server
Absolutely.
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.