Create a VLAN and assign ports on a Cisco switch

This example is for Cisco switches running IOS or IOS XE. It creates VLAN 10, names it SALES, and assigns GigabitEthernet1/0/1 through 1/0/4 to it. Replace the VLAN number, name, and port names as needed for your switch.

Create the VLAN and assign ports

enable
configure terminal
vlan 10
name SALES
exit
interface range GigabitEthernet1/0/1 - 4
switchport mode access
switchport access vlan 10
no shutdown
end
copy running-config startup-config
CommandWhat it does
enableEnters privileged mode, allowing administration commands.
configure terminalEnters global configuration mode.
vlan 10Creates VLAN 10, or opens its settings if it already exists.
name SALESGives the VLAN the descriptive name SALES.
exitReturns from VLAN settings to global configuration mode.
interface range GigabitEthernet1/0/1 - 4Selects ports 1 through 4 so the following commands affect all four.
switchport mode accessMakes the selected ports access ports, typically used for computers or printers.
switchport access vlan 10Assigns the selected ports to VLAN 10.
no shutdownEnables the ports if they were administratively disabled.
endLeaves configuration mode and returns to privileged mode.
copy running-config startup-configSaves the configuration so it survives a restart. Press Enter to accept the destination filename if prompted.

Add one more port later

This example adds GigabitEthernet1/0/5 to VLAN 10:

configure terminal
interface GigabitEthernet1/0/5
switchport mode access
switchport access vlan 10
no shutdown
end
copy running-config startup-config

interface GigabitEthernet1/0/5 selects only port 5. The remaining commands have the same meanings as above. Run these commands from privileged mode (the prompt ends in #); use enable first if your prompt ends in >.

Verify the configuration

Run these commands from privileged mode:

show vlan brief
show interfaces GigabitEthernet1/0/1 switchport
CommandWhat it does
show vlan briefLists VLANs and their assigned access ports. Look for VLAN 10, SALES, and the selected ports.
show interfaces GigabitEthernet1/0/1 switchportShows port 1’s switching mode and access VLAN. Look for access mode and VLAN 10.

Notes

  • Port names vary by model, for example FastEthernet0/1, GigabitEthernet0/1, or GigabitEthernet1/0/1.
  • Assigning a port to VLAN 10 changes its existing access VLAN membership.
  • Use these access-port commands for end-device ports. A link carrying multiple VLANs between switches needs trunk configuration.
  • Devices in different VLANs need a router or Layer 3 switch to communicate.
  • Creating a VLAN does not configure device IP addresses, DHCP, or routing.

Cisco references