DHCP stands for Dynamic Host Configuration Protocol. DHCP uses UDP port 67 and UDP port 68.
In early computing days, a user would have to manually configure their IPv4 address configuration. You’d have to enter your IP address, subnet mask, gateway, DNS Servers, NTP servers, etc. DHCP was created to provide automatic address and IP configuration for most devices.
When you connect a device to a network for the first time, it automatically gets configured with an IP address, subnet mask, and other details. It does this by using DHCP. To do this a DHCP server must reside somewhere on the network, either as an actual server, or an appliance, or integrated into a SOHO router, etc. Your client computer talks to the DHCP server via UDP port 67 and UDP port 68.
IP addresses are assigned in real time from a pool. The assigned IP address is only leased for a set period of time. Before the lease expires, the workstation must check back into the DHCP server to ensure it can still use that IP address.
DHCP servers can be configured for DHCP reservations. This means that when a server or workstation checks in with DHCP, DHCP will recognize the MAC address of the device and will assign it the same IP address every time.
When a client workstation connects to the network and doesn’t have an IP address it sends a broadcast out to UDP Port 67 over the network. The broadcast will be seen be all of the devices on the local subnet, and will eventually be seen by the DHCP servers on the network. If the DHCP server has an available IP address, it will make an offer to the client workstation using a broadcast to UPD Port 68. If there are multiple DHCP servers, all servers will send an offer, and the client workstation will just select the first offer that it sees. The client workstation then sends a request via broadcast to UDP Port 67. The DHCP sees the request and sends an acknowledgement via broadcast to UDP Port 68. Now the client can configure itself with that IP address.
You can have a DCHP server off of the local subnet (is on a different IP subnet). This is accomplished by having a router with a DHCP relay enabled. This is also called an IP helper address. This means that if the router ever sees a request for DHCP, the IP helper knows to send them to the DHCP server that’s outside of the local subnet. The IP Helper sits in between the local subnet and the DHCP server that’s off of the local subnet.
When a request for an IP is received, the DHCP server assigns an IP address from the first available IP from a large pool of addresses. This means that a client workstation IP address may occasionally change. However, if you want to ensure that a device (such as a server or printer) always has the same IP address, this can be configured. One way to do this would be to disable DHCP on the device and configure the IP address information manually. However, this requires additional administration to manually enter the IP address, default gateway, subnet mask, DNS settings, and any other information relating to IP. If any changes need to be made the administrator would need to revisit the device and manually make the updated changes. A better option to keep a static IP is to configure an IP reservation on the DHCP server. With an IP reservation you can association a s specific device MAC address with an IP address. If you need to make IP changes, you simply make the change in the DHCP server which will then propogate the changes to all of the devices.