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
enableThe # prompt.
configure terminalInto configuration mode.
vlan 20The VLAN has to exist first.
name ACCOUNTSNamed.
exitBack to (config)#.
interface gi0/4Into the port on the wall behind that desk.
switchport mode accessOne VLAN, no tags. This is what a port with a PC on it should be.
switchport access vlan 20And that VLAN is 20.
endOut.
show vlan briefGi0/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
Console into a switch
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.