Sub topic 4
Access ports: assigning end devices to a VLAN
This chapter assumes you know how a Layer 2 switch learns MAC addresses and forwards, floods and filters frames. It also assumes you can read IPv4 addresses and subnets and use a switch command line. You should already know what a VLAN is: a separate Layer 2 broadcast domain inside one physical switch.
What an access port is
An access port is a switch port that belongs to exactly one VLAN. End devices such as PCs, printers, servers and cameras plug into access ports. These devices do not know VLANs exist. They send and receive ordinary untagged Ethernet frames.
The switch adds the VLAN meaning inside itself. When a frame arrives on an access port, the switch associates it with the port's configured VLAN. It then forwards the frame only to other ports in that same VLAN, or to trunk ports that carry that VLAN. When a frame leaves an access port, the switch sends it untagged.
So the VLAN label is a property of the port, not of the device. Move the cable to a port in another VLAN and the device changes VLAN. Nothing on the device changes.
Configuring access ports
Two steps are needed. First the VLAN must exist in the switch's VLAN database. Then each port is set to access mode and assigned to the VLAN.
vlan 10
name USERS
vlan 20
name SERVERS
!
interface GigabitEthernet0/1
switchport mode access
switchport access vlan 10
!
interface GigabitEthernet0/2
switchport mode access
switchport access vlan 20Each line does one job:
vlan 10creates VLAN 10, andname USERSgives it a label. The name is only for humans. It does not affect forwarding.switchport mode accessmakes the port a permanent access port. Without it, a port on many Cisco switches defaults to a dynamic mode and may try to negotiate a trunk.switchport access vlan 10sets the port's VLAN.
Setting the mode explicitly matters. A port left in a dynamic mode can become a trunk if the device on the other end sends the right negotiation frames. That is a security concern covered in later chapters. For now, treat switchport mode access as part of every end-device port.
Configuring several ports at once
Use the range keyword to avoid repeating yourself:
interface range GigabitEthernet0/3 - 12
switchport mode access
switchport access vlan 10What happens when the VLAN does not exist
On many Cisco switches, assigning a port to a VLAN that is not in the database used to create the VLAN automatically. Behavior differs by platform and software version, so do not rely on it. Create VLANs explicitly.
If a VLAN is deleted while ports are still assigned to it, those ports do not move to VLAN 1. They stay assigned to the missing VLAN, show as inactive, and forward no traffic. This is a common cause of a device that has link but no connectivity. The fix is to recreate the VLAN or reassign the ports.
The default VLAN is VLAN 1. Every port starts in it until you change it. A port you never configured is therefore in VLAN 1, alongside any other unconfigured ports. A common hardening practice is to move unused ports into an unused VLAN and shut them down.
Inside the switch: how forwarding stays separate
A switch keeps MAC address learning per VLAN. The same MAC address can appear in the table once for each VLAN, and a lookup uses both the destination MAC and the VLAN. Because of that, a frame in VLAN 10 is never forwarded to a port in VLAN 20, even if the destination MAC would otherwise be known on that port.
The same rule applies to flooding. Broadcasts, multicasts and frames to unknown unicast addresses are flooded only to ports in the frame's VLAN. This is what makes a VLAN a broadcast domain.
| Event | What the switch does |
|---|---|
| Untagged frame arrives on an access port in VLAN 10 | Treats the frame as VLAN 10 |
| Broadcast in VLAN 10 | Floods to other VLAN 10 access ports and to trunks carrying VLAN 10 |
| Known unicast in VLAN 10 | Forwards only out the port learned for that MAC in VLAN 10 |
| Frame leaves an access port | Sent untagged |
| Frame to a MAC in another VLAN | Not forwarded at Layer 2. A router or Layer 3 switch is needed |
Verifying access port configuration
Use show vlan brief to see which ports belong to each VLAN, and show interfaces switchport for one port.
show vlan brief
show interfaces GigabitEthernet0/1 switchportIn the show vlan brief output, trunk ports are not listed under any VLAN. Only access ports appear. In the single-port output, check these fields:
Administrative Modeis what you configured, such asstatic access.Operational Modeis what the port is actually doing, such asstatic access.Access Mode VLANis the VLAN the port is assigned to.
If the administrative mode is dynamic auto or dynamic desirable, the port was never fixed to access mode.
Subnets and VLANs
A VLAN is a Layer 2 construct, and an IP subnet is a Layer 3 one. In practice each VLAN is given its own subnet, so VLAN 10 uses 192.168.10.0/24 and VLAN 20 uses 192.168.20.0/24. This one-to-one mapping is a design convention, not a protocol rule.
Putting two subnets in one VLAN does not make them communicate through the switch. Hosts only reach another subnet via a gateway. Putting one subnet across two VLANs breaks it. Hosts in the same subnet assume they can reach each other with ARP, but the ARP broadcast stays inside its own VLAN, so ARP fails.
Because the device is not VLAN-aware, it must be configured with an address and default gateway that fit the subnet of the VLAN its port is in. Moving a port to another VLAN without changing the host's address leaves it with a wrong subnet. DHCP helps because the VLAN's DHCP scope hands out the correct address, though the DHCP server must be reachable from that VLAN.
Common mistakes
- Forgetting to set the mode. The port stays dynamic and may negotiate.
- Assigning a port to a VLAN that is missing from the database. The port goes inactive or the VLAN is created unexpectedly, depending on the platform.
- Plugging an end device into a trunk port. Most PCs ignore tagged frames. The device either gets nothing or only receives the native VLAN.
- Using a trunk-configured port for an access device. If the port was previously a trunk,
switchport access vlanhas no effect until the mode is access. - Mismatched host addressing. The port is in VLAN 20 but the host has a 192.168.10.x address.
- Leaving unused ports in VLAN 1 and enabled. Anyone can plug in and join the default VLAN.
A note on hosts that send tags
A normal end device sends untagged frames. A server running a hypervisor, or a Linux host with a VLAN subinterface, can send tagged frames. Such a device needs a trunk port, not an access port, because an access port expects untagged frames. Some switches drop tagged frames that arrive on an access port, and others accept them in limited cases such as a voice VLAN. Check your platform and do not depend on this behavior.
Troubleshooting walkthrough
A user on Gi0/1 cannot reach a server on Gi0/2. Work from the port outward.
- Check link state with
show interfaces status. Anotconnectorerr-disabledport needs attention first. - Run
show vlan brief. Confirm that Gi0/1 appears under the expected VLAN and that the VLAN status isactive. - Run
show interfaces GigabitEthernet0/1 switchport. Confirmstatic accessand the right access VLAN. - Check the host address, mask and gateway against the VLAN's subnet.
- Remember the server is in a different VLAN here. Layer 2 will not connect them. The path needs inter-VLAN routing, covered in a later chapter.
The last step reveals that the configuration earlier in this chapter is correct for isolation, so the fault is expected behavior until a router is added.
Summary
An access port carries one VLAN and sends and receives untagged frames. The switch assigns incoming frames to the port's VLAN, keeps MAC learning and flooding inside that VLAN, and strips the VLAN when a frame leaves. Create the VLAN first, set the port to access mode explicitly, match host addressing to the VLAN's subnet, and verify with show vlan brief and show interfaces switchport.
Exercise
A PC on Gi0/5 has link, but it cannot reach its gateway. show vlan brief does not list Gi0/5 under any VLAN, and show interfaces GigabitEthernet0/5 switchport shows "Access Mode VLAN: 30 (Inactive)". What is the cause and what are two fixes?
Show answer
The port is assigned to VLAN 30, but VLAN 30 is not in the VLAN database, so the port is inactive and forwards nothing. Fix it by creating the VLAN with vlan 30 (and a name), or by reassigning the port with switchport access vlan <existing VLAN>.
Exercise
A host in VLAN 10 has address 192.168.20.15/24 and its port is configured with switchport access vlan 10. It cannot reach the VLAN 10 gateway 192.168.10.1. Why, and what should change?
Show answer
The host's address is in the VLAN 20 subnet, so it does not match the subnet of the VLAN its port is in. Either move the port to VLAN 20 with switchport access vlan 20 or give the host an address in 192.168.10.0/24 and the gateway 192.168.10.1, for example through DHCP.
Exercise
Why should you configure switchport mode access on a port that already has switchport access vlan 10?
Show answer
The VLAN assignment alone does not fix the port's mode. On many Cisco switches the default mode is dynamic, so the port could negotiate a trunk with a device on the other end. Setting access mode makes the port a permanent access port and removes that risk.