PanelSimulator Academy

Networking for Security, lesson 5 of 12

DHCP and DNS

Lessons 3 and 4 set an address, a mask and a gateway on each device. Typing those into every device by hand is slow and easy to get wrong. Two services do the housekeeping instead: DHCP hands out addresses, and DNS lets people use names in place of numbers. This lesson shows how each one works, and why security devices need more care with them than a laptop does.

About 14 minutes. Read lessons 3 and 4 first.

Ask for an address

Pick a situation, then play or step through it. Watch the device's settings fill in.

message on the wire IP Mask Gate DNS DHCP server pool of addresses to lend DNS server 192.168.1.5 recorder1 192.168.1.20 access1 192.168.1.6 gate-cam 192.168.1.61

The everyday picture

When you check in at a hotel, you do not choose your own room. The front desk looks at which rooms are free, gives you one for the length of your stay, and tells you where breakfast is and which number to dial for an outside line. When you leave, the room goes back on the list for the next guest. If you stay longer, you ask the desk to extend.

That is DHCP. A device arrives on the network and asks. A server lends it a free address for a set time and tells it the other settings it needs.

Now think of the contacts list in your phone. You tap a name, and the phone looks up the number and dials it. If a friend changes their number, you update one entry and keep tapping the same name. That is DNS: a list that turns names into numbers.

DHCP: addresses on loan

DHCP stands for dynamic host configuration protocol. One device on the subnet acts as the DHCP server. On a small site it is usually the router. On a large site it is a server run by the information technology staff. The server holds a range of addresses it is allowed to hand out, called the pool or scope.

A device set to "obtain an address automatically" goes through four short messages when it starts. The first situation in the drawing shows them.

  1. Discover. The device has no address yet, so it broadcasts to everyone: is there a DHCP server here?
  2. Offer. The server picks a free address from its pool and offers it.
  3. Request. The device asks formally for the address it was offered.
  4. Acknowledge. The server confirms, and includes the rest of the settings.

The answer carries the four things from lesson 4 and this lesson together: the IP address, the subnet mask, the default gateway and the address of a DNS server. The loan is called a lease and it has a length, commonly somewhere between a few hours and several days. Halfway through, the device asks to renew, and the server normally agrees. If the device is away for longer than its lease, the address returns to the pool and may go to something else.

Two facts explain most DHCP trouble on security jobs.

  • The request is a broadcast, and broadcasts stop at routers. A DHCP server must be on the same subnet as the device, or the router must be set to pass the requests along, a feature called a DHCP relay.
  • If nobody answers, many devices give themselves an address beginning 169.254. Lesson 3 listed this range. It is a sign that the device asked and heard nothing. Some cameras fall back to a fixed factory address instead. The data sheet says which.

Check yourself

You plug in a laptop and it shows the address 169.254.37.200. What does that tell you?

Three ways to set an address

A laptop does not care which address it gets today. A camera is different. The recorder has been told to fetch video from a particular address, and if the camera turns up somewhere else tomorrow, the recording stops. Security devices need addresses that stay put. There are two good ways to achieve that, and one way that suits visitors only.

StaticReservedDynamic
How it is setTyped into the device by handThe device asks by DHCP. The server is told to always give this MAC address the same IP addressThe device asks by DHCP and takes whatever is free
Can the address change?NoNoYes
If the DHCP server is downNo effectThe device keeps its address until the lease runs out, then loses itThe same
Where the record livesIn each device, and in your site listIn one place, on the serverNowhere permanent
Replacing a failed unitType the settings into the new oneUpdate the MAC address on the serverNothing to do
FitsRecorders, servers, switches, and devices on a network with no DHCP serverCameras and controllers on a network whose owner runs DHCP wellLaptops, phones, visitors

A static address depends on nothing else, which is why the most important boxes get one. Its weakness is human: the mask or gateway is mistyped, or the address is one the DHCP server is also handing out. A reservation keeps every setting in one place and makes a wrong mask impossible, but it needs someone with access to the server. Either is sound. Mixing them without a plan is not.

An address plan

The way to stop static addresses and the DHCP pool from colliding is to divide the subnet on paper before anything is plugged in. Here is a common pattern for a /24. The numbers are an example, not a rule.

Last number of the addressUsed forHow it is set
1GatewayStatic
2 to 9Switches and other network equipmentStatic
10 to 29Recorders, servers, workstationsStatic
30 to 59Door controllers and intercomsStatic or reserved
60 to 199CamerasStatic or reserved
200 to 250DHCP pool for laptops and new devicesDynamic

The pool at the top has a practical use. A new camera set to automatic takes a pool address when first plugged in, which lets you find it and move it to its planned address. Only one DHCP server should be answering on a subnet. A second one, such as a home router plugged in by someone wanting wireless, hands out wrong settings to whichever devices hear it first.

DNS: names for numbers

DNS is the domain name system. A device that wants to reach a name sends a question to the DNS server it was told about: what is the address for this name? The server answers with an IP address, and the conversation then carries on by number as usual. The device remembers the answer for a while so that it does not ask every time. The third situation in the drawing shows a lookup.

Inside a security system, cameras and recorders mostly find each other by IP address, so DNS is not involved. It matters where the system reaches outward:

  • Time. Devices set their clocks from a time server, which is usually entered as a name. Without DNS the clocks drift, and video evidence with the wrong time is hard to use.
  • Cloud services. A cloud-managed camera or a recorder with a phone app connects out to a name on the internet.
  • Email and alerts. The mail server for alarm messages is given as a name.
  • Operators. A name such as recorder1 is easier to type than a number, and it stays the same when the recorder behind it is replaced.

A static device needs its DNS server typed in along with the other three settings. It is the one most often left blank. The symptom is distinctive: everything on site works, and everything that depends on a name does not. The quick test is to try the same destination both ways. If the number answers and the name does not, the fault is DNS.

Choose for each device

How should this device get its address?

Check first

These are starting points. On a customer's network, the people who run it decide the method. Ask them, and follow their plan.

Three examples

Simple: two cameras swap places

After a long weekend power cut, a store's recorder shows the stockroom picture under "Front door" and the front door under "Stockroom". The cameras had been left on automatic. Their leases ran out while the power was off, and when everything restarted they asked afresh and received each other's old addresses. The recorder still fetched by address. The fix was to give every camera a fixed address outside the pool and write it in the site list.

Medium: the helpful wireless router

Cameras on one floor go offline one at a time over a week, each after a restart. A technician finds that a dead camera has an address beginning 192.168.0, a gateway nobody recognizes, and a lease from an unknown server. The site uses 10.10.20.x.

Someone had plugged a home wireless router into a spare port to get better signal at their desk. It was answering DHCP requests faster than the real server. Any device that restarted took its settings from the wrong box. Removing it and restarting the affected cameras cured the fault. The network owner then switched on a feature of the managed switches that accepts DHCP answers only from the port where the real server lives.

Advanced: works on site, dead from outside

A recorder plays live and recorded video perfectly at the security desk. The manager's phone app cannot connect, alarm emails have stopped, and the recorder's clock is eleven minutes slow. All three began after the customer replaced an old server.

The recorder has static settings. Its DNS entry still pointed at the old server, which had also been the site's DNS server. From the recorder's test page, a known internet address answered by number, but no name could be found. The app service, the mail server and the time server are all reached by name, so all three failed together while local video, which uses addresses, carried on. Entering the new DNS server's address fixed all three at once. Three faults with one starting date usually have one cause.

From the field

  • Ask for the pool range before you choose a static address. An address inside the pool will work for weeks, until the server lends it to a visitor's phone.
  • Enter all four settings on a static device: address, mask, gateway and DNS. Then test something that uses a name, such as the time server.
  • Use the maker's discovery tool to find a new device whose address you do not know. These tools search by broadcast, so your laptop must be on the same subnet.
  • Read the lease details on a misbehaving device. The address of the server that issued the lease tells you at once whether a stranger is answering.
  • Agree reservations by MAC address in advance. Send the network owner your list of MAC addresses and locations before installation day.
  • Set the clock source at the same time. Every camera and recorder should take its time from the same server.

Common mistakes

  • Leaving cameras on dynamic addresses because they worked on the day of installation.
  • Choosing a static address from inside the DHCP pool.
  • Leaving the DNS setting blank on a static device, then wondering why the clock and the emails fail.
  • Plugging in a second router or recorder with its own DHCP server switched on.
  • Replacing a reserved camera and forgetting that the reservation is tied to the old unit's MAC address.
  • Reading a 169.254 address as a real one and trying to reach the device with it from another subnet.

Summary

  • DHCP lends a device an address for a set time, and supplies the mask, gateway and DNS server with it.
  • The exchange is discover, offer, request, acknowledge. It starts with a broadcast, so it does not cross a router without help.
  • An address beginning 169.254 means the device asked and nobody answered.
  • Security devices need fixed addresses: static, or reserved by MAC address on the DHCP server.
  • Divide the subnet on paper so that fixed addresses and the pool never overlap. One DHCP server per subnet.
  • DNS turns names into addresses. If numbers work and names do not, check the DNS setting.

Exercises

Answer each one yourself first, then open the answer.

Exercise 1. Name the four settings a DHCP server normally hands to a device.

Show answer
The IP address, the subnet mask, the default gateway and the address of a DNS server. It also states how long the lease lasts.

Exercise 2. A site's DHCP pool is 192.168.1.200 to 192.168.1.250. You are asked to give a new camera a static address. Which of these is safe: 192.168.1.75, 192.168.1.210, 192.168.1.255?

Show answer
Only 192.168.1.75, and only after checking the site list to see that nothing else has it. The address .210 is inside the pool and will collide one day. The address .255 is the broadcast address of a /24 and cannot be given to a device.

Exercise 3. A lease lasts 8 days. Roughly when does the device first ask to renew it, and what happens if the device is switched off for 10 days?

Show answer
It asks to renew about halfway through, after 4 days. If it is off for 10 days the lease runs out, the address goes back into the pool, and the device may be given a different one when it returns, unless the address is reserved for it.

Exercise 4 (think, don't memorize). A recorder with static settings records every camera correctly, but its clock is wrong and it cannot send alarm emails. A laptop on the same switch, set to automatic, can do both. What is the most likely difference between the two, and how do you confirm it?

Show answer
The laptop received a working DNS server address from DHCP. The recorder's DNS setting was typed by hand and is probably blank, mistyped or pointing at a server that no longer exists. Cameras are reached by address, so recording is unaffected, while the time server and mail server are reached by name. Confirm by comparing the DNS setting on the two, and by testing from the recorder whether a name can be found when a number can.