Cisco Command Christmas Calendar #16: switchport mode access / switchport access vlan x

The purpose of VLANs is to logically separate and isolate devices in the same physical network. At the interface level, this is done with the switchport mode access and switchport access vlan x commands. The default interface mode is dependent on the platform (usually dynamic auto or dynamic desirable), but the switchport mode access command sets the interface as a non-trunking, untagged single VLAN interface. The switchport access vlan command sets the VLAN when the interface is in access mode (the default VLAN is 1). Say you wanted to configure interface Fa0/2 in access mode and put it VLAN 200, here's what you would do:

interface FastEthernet0/2
 switchport access vlan 200
 switchport mode access 

Note: If you assign an interface to a VLAN that does not exist, the interface is not operational until you create the VLAN in the VLAN database. However, in many cases, the IOS device will create the VLAN for you if it doesn't already exist and present a notification message, such as % Access VLAN does not exist. Creating vlan 200.

Here's what the (relevant) output of the show interface switchport (from Cisco Command Christmas Calendar #13) would look like:

Switch# show interface Fa0/2 switchport
 Administrative Mode:static access
 Operational Mode:static access
 Administrative Trunking Encapsulation:negotiate
 Operational Trunking Encapsulation:native
 Negotiation of Trunking:On
 Access Mode VLAN:200
 Trunking Native Mode VLAN:1 (default)
 Trunking VLANs Enabled:ALL
 Pruning VLANs Enabled:2-1001

Cisco documentation: switchport mode access, switchport access vlan, and Configuring Layer 2 Ethernet Interfaces