5.1 Dynamic Host Configuration Protocol (DHCP)
In this section you will see how networks can be configured so that new devices can join automatically and not have to be configured manually.
Mobile devices such as laptops and smartphones may leave and join different networks frequently: for example, you may use the same device at home and work, and also on the bus or in a café. A mobile device needs a different configuration for each network; it would be annoying and error-prone if the user had to do this manually. Other networked devices, such as security cameras or central heating thermostats, have no keyboard or screen, so they must connect automatically.
Dynamic Host Configuration Protocol (DHCP) is used to configure network devices automatically. DHCP is specifically designed for networks where the connected devices (hosts) change frequently, using a protocol to achieve a correct configuration.
Now watch the video below, which is about 5 minutes long. It shows how new devices are configured as they join a network.
Box _unit4.1.1 DHCP in action

Transcript
So let’s see how it works. Here’s my ‘Home’ network over here on the left. I’ve also got ‘Work’ network on screen as well, but I’ll talk about that in a minute. Let’s focus our attention on the ‘Home’ network here on the left, where I have a typical small domestic router. It happens to be a Wi-Fi access point as well, but I’m going to start just using wired connections, but actually everything will work just the same because DHCP will work across different transport layers.
So let’s see what happens if I bring my laptop into the network; let’s say I’ve just bought myself a new laptop, which will need configuring. So I’m going to click on it to configure it. But instead of typing in an IP address as we’ve done previously, I’m just going to click ‘DHCP’ and allow it to get configuration automatically. Nothing is going to happen until I actually connect it though, so let’s get a cable and connect from the laptop Ethernet port to the router – pick a free Ethernet port – and then I need to sit back and wait for the configuration to take place. So DHCP is a protocol that means a conversation, an exchange of messages between the devices – the laptop and the router – until they’ve between them sorted out what the correct configuration is. So I need to be patient while those messages are exchanged. And this is Packet Tracer and that is simulating all that exchange of messages, so I need to wait for that to happen. The lights have now gone green, so hopefully I can just check that the configuration is what I expect and I now have some values in here. And if I open a command prompt I can type in ipconfig and check to see what my configuration is. So this laptop has been given a configuration. It’s been given an IPv6 address, which we’re not going to talk any more about. It has an IPv4 address, which is 192.168.0.100 and it’s been given a subnet mask as well, 255.255.255.0, and a default gateway, 192.168.0.1. Now, the default gateway is the gateway to the internet – in this case it is the router that we’ve just connected to. So I can just check to see that that is working by doing a ping to the router, 192.168.0.1, and just check that we do get an exchange. And there we have some pings going backwards and received so that has a good connection. So that’s looking very good.
Let’s go wild and have a second laptop in the network. I’m going to do the same configuration again, just turning DHCP on and that’s all. I’m going to get another cable and I’m going to connect from that laptop Ethernet port to another free Ethernet port on the router. And again, I’ll need to be patient while that configuration takes place. Hopefully, I’m going to get an IP address; hopefully, I’m going to get a different IP address from the first laptop. So two different devices are going to need two different IP addresses to work on the same network, otherwise confusion will reign. Lights are still amber … there we are, gone green now. So I’m now going to open the command prompt on this laptop, do ipconfig on the second laptop, and we can see that we have an IP address. The IP address is different: it’s 192.168.0.101, so it’s different from the first one. The same subnet mask, because it is on the same subnet; the same default gateway because it is going to use the same router as a gateway to the internet, if the internet was connected. And I can check now that I can ping from the second laptop, which is where I’m sitting at the moment, to the first laptop: I can do ping 192.168.0.100 was the address of the first one. And there we are, we’ve got a reply from 0.100, some successful pings so I have got a path between the two laptops through the router acting as a switch.
So that’s all looking very good. And I could go on adding new devices, mobile devices using Wi-Fi – it would work in exactly the same way.
Now watch the video below, which is about 3 minutes long. It shows how one device receives a new configuration when it moves from one network to another.
Box _unit4.1.2 DHCP continued

Transcript
What would be interesting now is to see what happens if I disconnect my laptop from my home and take it to work – bring it up here and take it to work. Look for another connection, so let’s get another cable and go from the Ethernet port to a spare port on the router. And then again I’m going to need to sit back and be quite patient while the DHCP on that router kicks in and gives me a configuration. While it’s doing that, I think I might just point out you might think there’s a bit of a problem here because the IP address is at the moment either not set or set incorrectly because it was on the wrong network. So how is communication happening at all? Well, the answer to that is that it’s working at the Ethernet level because it’s able to do that just within the local network because each device has got a unique MAC address, so Ethernet communication can work without IP addresses being correctly set. And it can be done as a broadcast: the laptop can just broadcast and say ‘is there a DHCP server out there?’ and then the DHCP server will reply and start the conversation that leads to configuration.
So let’s check to see that I have got configuration on the laptop now. I’m going to do ipconfig again, which was set at 192.168.0.100 at home. Let’s see what it is now. Ah, it’s changed. So we now have an IP address which is 172.16.0.100, so that fits with a different network; has a different subnet mask, and a different default gateway because I’m now talking to a different router, 172.16.0.1. And so that’s all looking good. So you can see that DHCP is able to take a dynamic host – take a host from one place to another – and sort out the configuration all automatically: there was nothing that I needed to do to type that in.
So there we are, DHCP (Dynamic Host Configuration Protocol).
In the video you saw that instead of manually setting up the IP address for every device on a LAN, you can use DHCP (Dynamic Host Configuration Protocol) to do it automatically. A new device joining the network – for example a PC plugged in to an Ethernet socket or a tablet connecting to Wi-Fi – will receive an IP address.
A DHCP server has a pool of IP addresses which it can issue to devices as they join the network. On a home network the router will act as the DHCP server, but a dedicated DHCP server may be used in a business network.
Besides the IP address, DHCP will configure other important network parameters such as the subnet mask and default gateway.
The IP address is granted only for a limited period of time (a lease) such as 24 hours. If the device stays connected or reconnects before this lease expires, it keeps the same IP address. If the lease expires, the server can reallocate the IP address to any new device that connects. If the original device reconnects, it will be given a different IP address.
Some host devices in a network may need a permanent static address rather than obtain an address from the DHCP pool which might change. For example, a home gateway is usually given a static address that never changes.
Activity _unit4.1.1 Activity 1 Think about
10 minutes
Could you set up a coffee shop Wi-Fi network?
Customers expect to have wireless access so they can use their tablets and laptops. What would you have to consider when you set up a Wi-Fi network?
Discussion
You will certainly want to set up DHCP on your network so customers don’t need to reconfigure their devices manually. Some specific issues to consider are:
The pool of addresses should be large enough for the number of customers you expect at any one time.
The lease time should be short, or you may run out of available addresses.
You may want to reserve some static addresses for the security cameras, tills or credit card terminals.
There are other considerations – for example making sure that your network is secure – which won’t be considered here.
Activity _unit4.1.2 Activity 2 Try it out
15 minutes
Open PT Anywhere [Tip: hold Ctrl and click a link to open it in a new tab. (Hide tip)] in a new tab or window so you can read these instructions.
In this scenario, there is a home gateway router and one PC already connected.
Add the laptop to the network.
Check the laptop configuration – is DHCP turned on?
Connect the laptop to the home gateway.
What IP address is it assigned?
What other configuration does it receive?
Can you ping the laptop from the PC?
Can you ping the PC from the laptop?
Disconnect the laptop from the home gateway.
Connect the second PC to the home gateway.
What IP address is the new device assigned?
-
Now reconnect the laptop to the home gateway.
What IP address is it assigned now?
Discussion
When you add a new device to a network running DHCP, it will receive an IP address and subnet mask. The IP address will be different from other devices already on the network. (The new device will normally also receive the address of the home gateway but this is not simulated here.)
If you disconnect a device, its IP address won’t immediately be allocated to a different device. As long as the lease has not yet expired, you can reconnect the device and it will retain the same IP address.
Activity _unit4.1.3 Activity 3 Sort it out
15 minutes
Open PT Anywhere in a new tab or window so you can read these instructions.
In this scenario, there is a home gateway router and one PC already connected.
Add the laptop to the network by connecting it to the gateway.
Can you ping the laptop from the PC?
Check the laptop and PC configuration – is DHCP turned on?
Check the gateway configuration – is DHCP turned on and configured sensibly?
If not, fix it and try again.
Discussion
In this network, DHCP wasn’t turned on and so a new device would not be configured correctly. Once DHCP is turned on at the gateway router, new devices will be granted a new IP address automatically.