-: DHCP or the Dynamic Host Configuration Protocol. 2 2
Initially, we used to have to manually provide an IP address 3 3
to every machine on our network, 4 4
which is not really a big deal in your house 5 5
where you might have three or four machines, 6 6
but in the large networks I've worked on, 7 7
we have hundreds or thousands, 8 8
or hundreds of thousands of computers and servers on them. 9 9
That is a ton of labor hours that we spent 10 10
just for configuring all of these devices. 11 11
So, someone was really smart 12 12
and create an automated way of doing it, known as DHCP. 13 13
DHCP was invented to help us with this monumentous task 14 14
of configuring all of these servers and workstations. 15 15
Now, DHCP also can help eliminate configuration errors 16 16
because when a person is entering an IP address 17 17
into an end user's device, 18 18
there is an opportunity for human error, 19 19
where they fat finger it and type in the wrong one. 20 20
Also, it can be really hard to maintain a good list 21 21
of every IP that every computer is using 22 22
inside of your network. 23 23
So often, you can get IP conflicts by assigning the same IP 24 24
to multiple machines inside the same network by accident. 25 25
With DHCP, none of this will happen, 26 26
because each device is automatically going to get assigned 27 27
an IP from a scope. 28 28
Now, a scope is simply a list of valid IP addresses 29 29
that are available for assignment or lease 30 30
to a computer or an endpoint on a given subnet. 31 31
Now, for example, in my home network, 32 32
I have 254 IPs available for devices in my scope. 33 33
So, when the computer joins my home network, 34 34
the DHCP server automatically picks one of these unused IPs 35 35
from the scope, 192.168.1.2 36 36
all the way up to 192.168.1.254 37 37
And then it gives that IP to that device to use. 38 38
This is known as a lease. 39 39
As a network administrator, you can tell your DHCP server 40 40
what IP addresses should be used in your scope 41 41
and you can even reserve some of those IPs 42 42
that you don't want to be handed out 43 43
as part of what's known as an excluded range 44 44
within your scope. 45 45
For example, in my home network, 46 46
I have a couple of IP addresses 47 47
that have been excluded from my DHCP scope. 48 48
These are IP addresses in the range of 192.168.1.2 49 49
up to 192.168.1.10. 50 50
These IP addresses have already been assigned 51 51
to some of those things in my network manually by me. 52 52
Things like my printer, 53 53
my network file server, and other things like that, 54 54
that I always want to have the same IP address for. 55 55
Now, another way you could do this 56 56
instead of statically assigning these IPs 57 57
is to use something known as a DHCP reservation. 58 58
This is very commonly used in large networks. 59 59
Now, a DHCP reservation lets you exclude 60 60
some of these IP addresses 61 61
from being handed out to devices 62 62
unless they meet certain conditions. 63 63
For example, I could set up a DHCP reservation 64 64
for my printer based on its MAC address. 65 65
That way, whenever my printer joins the network, 66 66
the DHCP server sees that it joins, checks its MAC address, 67 67
and then assign the exact same IP 68 68
every single time to that printer, 69 69
because it's been listed as a reserved address 70 70
inside the DHCP scope. 71 71
This is a great way to do things 72 72
when you have a large network, 73 73
instead of having to manually configure 74 74
each endpoint device with a specific IP address. 75 75
This lets your DHCP server do it for you. 76 76
Essentially, giving it a static address every single time, 77 77
but using this automatic configuration. 78 78
So, with DHCP, we can automate the process 79 79
of configuring all of our devices whenever they come online. 80 80
When the device joins our network, 81 81
it's going to reach out to our DHCP server 82 82
and it's going to do what's known as a discovery. 83 83
It's going to say, hey, DHCP server, 84 84
I need to discover an IP address. 85 85
This means I need one to be assigned to me. 86 86
The DHCP server then says, okay, 87 87
does this address look okay to you? 88 88
And it offers up an address from the scope. 89 89
This is known as the offer phase. 90 90
Then the computer's going to say, yeah, I like that address. 91 91
I request to take it. 92 92
And that's the DHCP request phase, 93 93
which is going to be our third step in this process. 94 94
Finally, our DHCP server is going to acknowledge 95 95
that the IP is now being used by this client, 96 96
by sending what's known as an acknowledgment 97 97
and saying, okay, that's your address 98 98
and you can borrow it for this amount of time. 99 99
This is known as a DHCP lease. 100 100
Now, when we look at this in our home networks, 101 101
the default lease time is going to be about 24 hours usually. 102 102
For a corporate network though, 103 103
you may choose to use a longer lease time. 104 104
Something like seven days or 30 days, 105 105
depending on your use case. 106 106
In the world of cybersecurity, 107 107
having devices that are constantly changing their IPs, 108 108
makes it harder for us to track down when bad things happen. 109 109
So, in larger networks, we tend to use a longer lease time. 110 110
Now, how are you going to remember these four steps of DHCP? 111 111
Well, I have a little memory aid or mnemonic for this. 112 112
I like to think of "Dora The Explorer". 113 113
Dora is D-O-R-A, 114 114
and it's discover, offer, request, and acknowledge. 115 115
That is our four steps of configuring a device 116 116
on a network using DHCP. 117 117
Now, when the device gets a configuration 118 118
from our DHCP server, 119 119
it isn't just getting that IP address though. 120 120
Instead, it's going to get four key pieces of information. 121 121
This is the IP address, the subnet mask, 122 122
the default gateway, 123 123
which is the IP address of our router, 124 124
and the IP address of the DNS server 125 125
so your client knows how to do a DNS name lookup. 126 126
Once your client has these four pieces 127 127
of information configured, that client can now get online, 128 128
get out of your network, and get onto the internet 129 129
because it nows knows where it is on the network 130 130
with its IP address, 131 131
where the router is with that gateway address 132 132
and how to convert the domain names to IP addresses 133 133
using that DNS servers IP. 134 134
Now, I mentioned the fact that we use DHCP 135 135
to dynamically assign our configuration needed 136 136
for our devices to get online. 137 137
But we can also do this manually, 138 138
which is known as a static assignment. 139 139
You see, when we do it dynamically, 140 140
we let DHCP servers do the configuration for us, 141 141
but you can also statically assign the configuration 142 142
if you provide all four pieces of information 143 143
to your client device. 144 144
Now again, in most large networks, 145 145
you wouldn't want to statically assign the information, 146 146
but instead you're going to want to use 147 147
a DHCP reservation to do it. 148 148
But in your home network or a small network, 149 149
you may want to statically configure things. 150 150
Now, if you need a statically configure a device, 151 151
be sure you double check everything you've entered 152 152
for all four pieces of information. 153 153
The IP address, the subnet mask, 154 154
the default gateway, and the DNS servers IP. 155 155
If you're troubleshooting a device 156 156
that's having connectivity problems, 157 157
you should check if it was statically configured. 158 158
And if it was, you need to verify the IP address 159 159
and the subnet mask are configured correctly, 160 160
because this is often the source of your problems. 161 161
So, at this point, 162 162
we've talked about dynamic assignment and static assignment. 163 163
Now, when we use a dynamic assignment, 164 164
what happens if a device can't reach the DHCP server 165 165
or it fails to receive a proper configuration? 166 166
What should that device do? 167 167
Should it just keep asking? 168 168
Well, no, because then it's just going to sit there forever 169 169
getting hung up. 170 170
So, instead, we need to have an alternate configuration. 171 171
Whenever you're configuring DHCP, 172 172
if DHCP is not successful and it's not able to negotiate 173 173
its way through the door or process for whatever reason, 174 174
it's going to default to it's alternate configuration 175 175
that's set by the system administrator 176 176
inside the operating system. 177 177
By default, this is going to be set to use 178 178
what's known as an APIPA address, A-P-I-P-A, 179 179
which is Automatic Private IP Address. 180 180
Now, as a network administrator or a system administrator, 181 181
you can also configure your device to fall back 182 182
to a known good static IP address 183 183
as your alternate configuration instead if you prefer. 184 184
Now, when you're configuring your DHCP server, 185 185
one of the things you can configure is your scope options. 186 186
This allows you to configure a bunch of different things, 187 187
but the most common are the subnet mask 188 188
that is going to be applied to all the devices 189 189
requesting that configuration, 190 190
the default router or gateway that these devices should use, 191 191
and the DNS server to include the IP address configuration 192 192
for those devices, 193 193
as well as the least time for the IP address. 194 194
Now, as you can see, we've already discussed 195 195
all of these things in this lesson. 196 196
But I wanted to bring this up 197 197
so you're aware that you can change and configure them 198 198
as part of your scope options inside your DHCP server too. 199 199
Another unique configuration you need to make 200 200
for DHCP or network is the use of a DHCP relay. 201 201
Now, a DHCP relay is any host that forwards DHCP packets 202 202
between clients and servers. 203 203
Now, really the only time you're going to need a DHCP relay 204 204
is when the client device and the DHCP server 205 205
are not located on the same subnet or network. 206 206
In this case, instead of installing a DHCP server 207 207
on every subnet or mini network inside of your network, 208 208
you can configure one device to act as the DHCP relay, 209 209
and that way you can save yourself a lot of effort. 210 210
This device will listen for discovery requests 211 211
and then forward that request to the DHCP server 212 212
on the other network on behalf of your client, 213 213
acting essentially as a middleman. 214 214
Another unique thing about DHCP 215 215
is that it operates using the User Datagram Protocol or UDP. 216 216
For this reason, it is fire and forget method 217 217
of sending data. 218 218
To help the data get to where it needs to go, 219 219
you may need to configure 220 220
what's known as an IP helper address on your router. 221 221
The IP helper address is used to forward 222 222
several different kinds of UDP broadcasts 223 223
across the router and can be used in conjunction 224 224
with the DHCP relay that we just talked about. 225 225
Remember, if the DHCP client and server 226 226
are on different network segments, 227 227
the router and the client's network segment 228 228
has to be configured with an IP helper address 229 229
for DHCP to work properly and forward those requests over 230 230
to the DHCP server.