Hone

Lessons · Network switches · access ports

Putting a port in a VLAN

An access port belongs to exactly one VLAN: `switchport mode access` says it carries one, and `switchport access vlan <n>` says which.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

This is the command that actually moves somebody's desk onto the right network, and it is the one you will type more than any other.

How to think about it

Both lines, every time. Setting the VLAN without setting the mode works today and breaks the day something negotiates the port into a trunk.

Worked example

enable
The # prompt.
configure terminal
Into configuration mode.
vlan 20
The VLAN has to exist first.
name ACCOUNTS
Named.
exit
Back to (config)#.
interface gi0/4
Into the port on the wall behind that desk.
switchport mode access
One VLAN, no tags. This is what a port with a PC on it should be.
switchport access vlan 20
And that VLAN is 20.
end
Out.
show vlan brief
Gi0/4 is now listed against VLAN 20, which is the proof the change landed where you meant it.

Your turn

Put this port into VLAN 20.

switchport access  20

The trap

Typing it in global configuration instead of inside an interface. switchport is not a global command; it only exists at (config-if)#.

Practise access ports on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.