Dynamic Host Configuration Protocol (DHCP)#
When you connected your laptop to your wireless router at home, or even your mobile, what IP address did you give it? That's right, you didn't. But if systems on a network need an IP address to communicate with one another and connect to systems in other networks across the Internet, how did your laptop and mobile get an IP address?
Unless your ISP has done something weird, your home router (residential gateway) will have a DHCP server running on it. That DHCP server gave IP address to your laptop, your mobile, and any and all other devices that connect to your home network (via a wired connection or a wireless one.)
DHCP is an excellent example of UDP in action. Remember that with TCP you must establish a connection before you can start exchanging data. This can take time, but with UDP it's "fire-and-forget". That means you send a UDP datagram and then move on. If you get a reply, great! If not then there's nothing of interest at the IP address you sent the datagram to.
Using UDP DHCP clients go through a set of steps to:
- Discover the DHCP server
- Which then sends the client an offer to lease an IP address
- And then the client sends a request to use the IP address sent to it (or another one)
- And the DHCP server sends an acknowledge to confirm the lease
The four steps are: discover, offer, request, and acknowledge. A bit like the TCP three-way handshake, except used to negotiate an IP address lease instead of just setting up the connection.
Once a system has been leased an IP address it tends to keep that address for a long time. This isn't guaranteed though, so you should not assume it will stay the same. Instead, assume it will change further down the line. If that's a concern for you then you have a few options:
- Configure the DHCP server to always give a specific system and specific IP
- Ignore DHCP on the system and give it a static IP
Lots of information can be sent from the DHCP server to clients. The most common you'll be concerned with is:
- The default gateway for communicating with other networks outside of the IP address subnet
- DNS server IPs used to resolve DNS names
- A hostname for the IP address
There is a lot more information that can offered up, but at this point in time you'll only be concerned with the above. And frankly you'll probably never configure a DHCP server in AWS as a VPC (Virtual Private Cloud - a big network, essentially) handles DHCP for you. It can even be configured to your liking.