Networking for Security, lesson 8 of 12
VLANs: separate networks on shared cable
Cameras and door controllers should not sit on the same network as the office's laptops and printers. Buying a second set of switches and cable is one way to keep them apart. A VLAN is the other way: one set of switches that behaves like several. This lesson shows how that works and how to ask for it correctly.
Who hears a broadcast?
Two switches in two rooms, joined by one cable. Choose how they are set up, then choose a device to shout to everyone it can reach.
The everyday picture
Picture an office building shared by two companies. They use the same front door, the same elevator and the same corridors. Yet each company has its own locked suite, and staff from one cannot wander into the other.
Mail for both companies rides up in the same elevator. That only works because every envelope is marked with a company name. At each floor, the mail is sorted by that mark and delivered to the right suite. Mail with one company's mark is never dropped at the other's door.
A VLAN works the same way. The switches and the cable between them are the shared corridors and elevator. Each VLAN is a locked suite. A small mark on each message, added while it travels between switches, keeps every message in its own suite.
The words
- A broadcast is a message addressed to everybody. Lesson 5 showed a device shouting one to find a DHCP server. On an ordinary switch, a broadcast goes out of every port.
- A VLAN, short for virtual local area network, is a group of switch ports that behave as if they were a separate switch. A message that enters on a port in one VLAN can only leave on a port in the same VLAN. That includes broadcasts.
- Each VLAN has a number, its VLAN ID, from 1 to 4094. People give them names too, such as "Video", but the switches only care about the number.
- A managed switch is one you can sign in to and configure. VLANs need managed switches. A cheap unmanaged switch has no settings at all and treats every port alike.
Try it in the diagram at the top. On the flat network, a broadcast from the office PC lands on both cameras and the recorder. With two VLANs it reaches only the other office devices, even though nothing was unplugged.
Why keep security devices apart
- Fewer ways in. An office laptop that picks up malicious software cannot even see the cameras, so it cannot probe them.
- Less noise. Devices stop receiving each other's broadcasts. On a large network this is a real saving.
- Clear ownership. The security subnet has its own address range, its own rules and its own records. A change to the office network is less likely to break the doors.
One caution. A VLAN separates traffic. It does not scramble it. Anyone with control of a switch, or of the cable between switches, is outside what a VLAN protects. The Cybersecurity course covers encryption.
Access ports and trunk ports
Every port on a managed switch is set to one of two jobs.
An access port belongs to a single VLAN. It is where an ordinary device plugs in. The camera on that port knows nothing about VLANs. It sends and receives plain messages, and the switch quietly keeps them inside the port's VLAN.
A trunk port carries several VLANs at once. It is used for the cable between two switches, or between a switch and a router. To keep the VLANs apart on that one cable, the sending switch adds a tag to each message: four extra bytes that hold the VLAN ID. The receiving switch reads the tag, removes it and delivers the message only to ports in that VLAN. The tagging method is a standard called IEEE 802.1Q, so switches from different makers can share a trunk.
| Access port | Trunk port | |
|---|---|---|
| Carries | One VLAN | Several VLANs |
| Messages on the cable | Plain, with no tag | Tagged with a VLAN ID |
| What plugs in | A camera, controller, recorder or PC | Another switch, a router, some wireless access points |
| What you set | The one VLAN ID | The list of VLANs allowed to cross |
Two more settings cause trouble if you have not met them. A new managed switch starts with every port in VLAN 1, the default VLAN, so out of the box it behaves like a flat network. A trunk also has a native VLAN: the one VLAN whose messages cross that trunk without a tag. Both ends of a trunk must agree on it.
Check yourself
A camera plugs into an access port in VLAN 20. What does the camera itself need to be told about VLANs?
Crossing between VLANs
Because a VLAN behaves like a separate network, each one is given its own subnet. Lesson 4 explained that traffic leaving a subnet must go through a gateway. The same is true here. For a PC in the office VLAN to watch video from a recorder in the security VLAN, the traffic must pass through a router, or through a switch with routing built in, which the trade calls a layer 3 switch.
That is the point of the whole exercise. The router is a single checkpoint, and rules can be set there. A typical plan and its rules look like this.
| VLAN ID | Name | Subnet | Who is in it |
|---|---|---|---|
| 10 | Office | 192.168.10.0/24 | Staff PCs and printers |
| 20 | Video | 192.168.20.0/24 | Cameras and recorders |
| 30 | Access control | 192.168.30.0/24 | Door controllers and their server |
| 99 | Management | 192.168.99.0/24 | The sign-in pages of the switches themselves |
- The security desk's PCs may reach the recorder, and nothing else in the video VLAN.
- Cameras may reach the recorder and the time server. They may not reach the office or the internet.
- Everything else between the VLANs is blocked.
The numbers are only a habit that makes life easy: VLAN 20 uses the subnet with 20 in it. Any plan works if it is written down.
Some recorders have two network ports and offer a simpler arrangement. One port sits in the camera VLAN and the other in the office VLAN. The recorder talks to both sides but does not pass traffic between them, so the cameras stay unreachable from the office. Check the recorder's manual to confirm it behaves this way.
Set up a port
Using the plan in the table above, pick what is about to be plugged in and see how the port should be set.
What plugs into this port?
How VLANs go wrong
VLAN faults are tidy. The cable tests perfectly and the link light is on, yet the device is unreachable. Four causes cover most of them.
- The port is in the wrong VLAN. The tell-tale is the device's address. A camera that has picked up an office address from DHCP is on an office port.
- The VLAN is missing from a trunk. Devices on one switch work, and devices in the same VLAN on the next switch are cut off. Choose the third setup in the diagram at the top to see it.
- No DHCP for the new VLAN. A broadcast asking for an address stays inside its VLAN. If no DHCP server serves that VLAN, devices give themselves a 169.254 address, as lesson 5 described.
- The change was never saved. Many managed switches hold new settings only in working memory until you save them. After the next power cut the switch returns to its old setup.
Three examples
Simple: one switch in a small office
A dental office has one 24-port managed PoE switch. Ports 1 to 8 feed cameras and port 9 feeds the recorder. The installer puts ports 1 to 9 in VLAN 20 as access ports and leaves the rest in the office VLAN. No trunk is needed, because there is only one switch. The cameras and recorder now form a private island. The receptionist views video on the recorder's own monitor.
Medium: the cameras that vanished after a repair
A school has a main building and a gym, each with a managed switch, joined by one trunk. Cameras in both buildings are in VLAN 20. The gym switch fails and is replaced with a new one over the weekend. On Monday the gym's computers work, but every gym camera is offline.
The new switch came out of its box with every port in VLAN 1. The computers happened to belong there. The cameras' ports were never put in VLAN 20, and VLAN 20 was never added to the trunk at the gym end. Nothing is broken. The switch's settings had been lost with the old switch. The fix takes ten minutes, and the lasting fix is to keep a saved copy of every switch's configuration.
Advanced: asking the IT department for a VLAN
On a large site the customer's IT department owns the switches, and you will not be allowed to sign in to them. Your job is to ask clearly. A good request lists:
- How many devices, and so how big a subnet you need, with room to grow.
- Whether addresses will be fixed or handed out by DHCP, and which range is yours.
- Every switch port you need, by room and port number, and the PoE power each one must deliver.
- Which trunks must carry the VLAN, which means every switch between your devices and your server.
- The rules at the router: who may reach the recorder and the access control server, and what the devices need to reach, such as a time server.
Then test before the day of the installation. Plug a laptop into one of your ports in each wiring closet, check that it receives an address in your subnet, and check that it can reach the server. Finding a missing trunk with a laptop is far cheaper than finding it with forty cameras on the wall.
From the field
- Label the ports. Colored patch cords or a printed label for security ports stop someone "borrowing" a camera port for a printer.
- Look at the address first. When a device misbehaves on a VLAN network, its IP address tells you which VLAN its port is really in.
- Keep a port map. A simple sheet listing each port, its VLAN and what is plugged in is worth more than any tool when a switch is replaced.
- Save, then back up. Save the configuration on the switch, and keep a copy off the switch as well.
- Do not change the VLAN of the port you are signed in through. You will lock yourself out and need a trip to the wiring closet.
Common mistakes
- Creating the VLAN on one switch and forgetting the trunks and the other switches.
- Hanging a small unmanaged switch off a trunk port and expecting it to sort the VLANs.
- Putting security devices in a VLAN, then allowing everything to cross at the router, which undoes the separation.
- Leaving unused ports live in a working VLAN, where anyone can plug in.
- Believing a VLAN makes traffic secret. It separates. It does not encrypt.
Summary
- A VLAN makes a group of switch ports behave like a separate switch. Broadcasts stay inside it.
- An access port serves one VLAN and one ordinary device. A trunk port carries several VLANs, each message tagged with its VLAN ID.
- Each VLAN has its own subnet. Traffic between VLANs must pass through a router, where rules decide what may cross.
- VLANs need managed switches, and the VLAN must exist on every switch and trunk along the path.
- When a device on a VLAN network cannot be reached, check its address, its port's VLAN and the trunks, in that order.
Exercises
Answer each one yourself first, then open the answer.
Exercise 1. On which kind of port do messages carry a VLAN tag?
Show answer
Exercise 2. Using the plan in this lesson, a new camera shows the address 192.168.10.57. What has happened?
Show answer
Exercise 3. Two switches both have VLAN 20 set up, with cameras on access ports. Cameras on the first switch record. Cameras on the second do not. Name the most likely cause.
Show answer
Exercise 4 (think, don't memorize). A customer says, "We put the cameras on their own VLAN, so they are safe." The router between the VLANs allows all traffic in both directions. What has the VLAN achieved, and what would you change?