DHCP
or the Dynamic Host Configuration Protocol.
Initially, we used to have to manually provide an IP address
to every machine on our network,
which is not really a big deal in your house
where you might have three or four machines.
But in the large networks I've worked on,
we have hundreds or thousands
or hundreds of thousands of computers and servers on them.
That is a ton of labor hours that we spent
just for configuring all of these devices.
So, someone was really smart
and created an automated way of doing this, known as DHCP.
DHCP was invented to help us with this monumentous task
of configuring all of these servers and workstations.
Now, DHCP also can help eliminate configuration errors
because when a person is entering an IP address
into an end user's device,
there is an opportunity for human error
where they fat finger it and type in the wrong one.
Also, it can be really hard to maintain
a good list of every IP
that every computer is using inside of your network.
So often you can get IP conflicts by assigning the same IP
to multiple machines inside the same network by accident.
With DHCP, none of this will happen
because each device
is automatically going to get assigned an IP from a scope.
Now, a scope is simply a list of valid IP addresses
that are available for assignment or lease to a computer
or an endpoint on a given subnet.
Now, for example, in my home network,
I have 254 IPs available for devices in my scope.
So when the computer joins my home network,
the DHCP server automatically picks
one of these unused IPs from the scope 192.168.1.2
all the way up to 192.168.1.254,
and then it gives that IP to that device to use.
This is known as a lease.
As a network administrator,
you can tell your DHCP server
what IP addresses should be used in your scope,
and you can even reserve some of those IPs
that you don't want to be handed out
as part of what's known as an excluded range
within your scope.
For example, in my home network,
I have a couple of IP addresses
that have been excluded from my DHCP scope.
These are IP addresses in the range of 192.168.1.2
up to 192.168.1.10.
These IP addresses have already been assigned
to some of those things in my network manually by me.
Things like my printer, my network file server,
and other things like that
that I always want to have the same IP address for.
Now, another way you could do this
instead of statically assigning these IPs
is to use something known as a DHCP reservation.
This is very commonly used in large networks.
Now, a DHCP reservation
lets you exclude some of these IP addresses
from being handed out to devices
unless they meet certain conditions.
For example, I could set up a DHCP reservation
from my printer based on its MAC address.
That way, whenever my printer joins the network,
the DHCP server sees that it joins, checks its MAC address,
and then assigns the exact same IP
every single time to that printer
because it's been listed as a reserved address
inside the DHCP scope.
This is a great way to do things
when you have a large network,
instead of having to manually configure each endpoint device
with a specific IP address.
This lets your DHCP server do it for you,
essentially giving it a static address every single time,
but using this automatic configuration.
So with DHCP, we can automate the process
of configuring all of our devices whenever they come online.
When the device joins our network,
it's going to reach out to our DHP server,
and it's going to do what's known as a discovery.
It's going to say, "Hey, DHCP server,
I need to discover an IP address."
This means I need one to be assigned to me.
The DHCP server then says,
"Okay, does this address look okay to you?"
And it offers up an address from the scope.
This is known as the offer phase.
Then the computer is going to say,
"Yeah, I like that address.
I request to take it."
And that's the DHCP request phase,
which is going to be our third step in this process.
Finally, our DHCP server is going to acknowledge
that the IP is now being used by this client
by sending what's known as an acknowledgement and saying,
"Okay, that's your address,
and you can borrow it for this amount of time."
This is known as a DHCP lease.
Now, when we look at this in our home networks,
the default lease time is going to be about 24 hours usually.
For a corporate network, though,
you may choose to use a longer lease time,
something like seven days or 30 days,
depending on your use case.
In the world of cybersecurity,
having devices that are constantly changing their IPs
makes it harder for us to track down when bad things happen.
So in larger networks, we tend to use a longer lease time.
Now, how are you going to remember these four steps at DHCP?
Well, I have a little memory aid or mnemonic for this.
I like to think of "Dora the Explorer."
Dora is D-O-R-A,
and it's discover, offer, request, and acknowledge.
That is our four steps
of configuring a device on a network using DHCP.
Now, when the device gets a configuration
from our DHCP server,
it isn't just getting that IP address though.
Instead, it's going to get four key pieces of information.
This is the IP address, the subnet mask,
the default gateway, which is the IP address of our router,
and the IP address of the DNS server,
so your client knows how to do a DNS name lookup.
Once your client has these four pieces
of information configured,
that client can now get online,
get out of your network,
and get onto the internet because it now knows
where it is on the network with its IP address,
where the router is with that gateway address,
and how to convert the domain names to IP addresses
using that DNS server's IP.
Now, I mentioned the fact that we use DHCP
to dynamically assign our configuration needed
for our devices to get online,
but we can also do this manually,
which is known as a static assignment.
You see, when we do it dynamically,
we let DHCP servers do the configuration for us,
but you can also statically assign the configuration
if you provide all four pieces of information
to your client device.
Now, again, in most large networks,
you wouldn't want to statically assign the information,
but instead you're going to want to use
a DHCP reservation to do it.
But in your home network or a small network,
you may want to statically configure things.
Now, if you need a statically configured device,
be sure you double check everything you've entered
for all four pieces of information.
The IP address, the subnet mask,
the default gateway, and the DNS server's IP.
If you're troubleshooting a device
that's having connectivity problems,
you should check if it was statically configured.
And if it was, you need to verify the IP address
and the subnet mask are configured correctly
because this is often the source of your problems.
So at this point,
we've talked about dynamic assignment and static assignment.
Now, when we use a dynamic assignment,
what happens if a device can't reach the DHCP server
or it fails to receive a proper configuration?
What should that device do?
Should it just keep asking?
Well, no, because then it's just going to sit there
forever getting hung up.
So instead, we need to have an alternate configuration.
Whenever you're configuring DHCP,
if DHCP is not successful
and it's not able to negotiate its way
through the DORA process for whatever reason,
it's going to default to its alternate configuration
that's set by the system administrator
inside the operating system.
By default, this is going to be set to use what's known
as an APIPA address, APIPA,
which is Automatic Private IP Address.
Now, as a network administrator or a system administrator,
you can also configure your device
to fall back to a known good static IP address
as your alternate configuration instead if you prefer.
Now, when you're configuring your DHCP server,
one of the things you can configure is your scope options.
This allows you to configure a bunch of different things,
but the most common are the subnet mask
that is going to be applied to all the devices
requesting that configuration,
the default router or gateway that these devices should use,
and the DNS server
to include the IP address configuration for those devices,
as well as the lease time for the IP address.
Now, as you can see,
we've already discussed all of these things in this lesson,
but I wanted to bring this up so you're aware
that you can change and configure them
as part of your scope options inside your DHCP server too.
Another unique configuration
you need to make for DHCP in your network
is the use of a DHCP relay.
Now, a DHCP relay is any host that forwards DHCP packets
between clients and servers.
Now, really, the only time you're going to need a DHCP relay
is when the client device and the DHCP server
are not located on the same subnet or network.
In this case,
instead of installing a DHCP server on every subnet
or mini network inside of your network,
you can configure one device to act as the DHCP relay,
and that way you can save yourself a lot of effort.
This device will listen for discovery requests,
and then forward that request to the DHCP server
on the other network on behalf of your client,
acting essentially as a middleman.
Another unique thing about DHCP
is that it operates using the User Datagram Protocol or UDP.
For this reason,
it is a fire and forget method of sending data.
To help the data get to where it needs to go,
you may need to configure
what's known as an IP helper address on your router.
The IP helper address
is used to forward several different kinds
of UDP broadcasts across the router
and can be used in conjunction with the DHCP relay
that we just talked about.
Remember, if the DHCP client and server
are on different network segments,
the router on the client's network segment
has to be configured with an IP helper address
for DHCP to work properly
and forward those requests over to the DHCP server.