Introduction
Earlier, I wrote an article about VLAN configuration on a Cisco switch. You can read it here: VLAN Configuration on a Cisco Switch
In that article, we learned how to create VLANs and assign ports to them.
In this article, we will go a step further and assign IP addresses to each VLAN. Assigning IP addresses is important because devices in each VLAN can then communicate with other devices in the same VLAN or even in other VLANs (if routing is configured).
We will configure these VLANs on switch S1:
IT - VLAN 10 - 172.16.10.0/24
HR - VLAN 20 - 172.16.20.0/24
SALES - VLAN 30 - 172.16.30.0/24
GUEST - VLAN 40 - 172.16.40.0/24
Step 1. Create VLANs on S1
First, make sure the VLANs exist on the switch. If you followed the previous article, the VLANs should already be there. If not, create them using these commands:
S1> enable
S1# configure terminal
S1(config)# vlan 10
S1(config-vlan)# name IT
S1(config-vlan)# exit
S1(config)# vlan 20
S1(config-vlan)# name HR
S1(config-vlan)# exit
S1(config)# vlan 30
S1(config-vlan)# name SALES
S1(config-vlan)# exit
S1(config)# vlan 40
S1(config-vlan)# name GUEST
S1(config-vlan)# exit
Step 2. Assign Ports to VLANs
We also need to assign switch ports to the correct VLANs. For example:
IT - Fa0/1 to Fa0/5
HR - Fa0/6 to Fa0/10
SALES - Fa0/11 to Fa0/15
GUEST - Fa0/16 to Fa0/20
S1(config)# interface range fa0/1 - 5
S1(config-if-range)# switchport mode access
S1(config-if-range)# switchport access vlan 10
S1(config-if-range)# exit
S1(config)# interface range fa0/6 - 10
S1(config-if-range)# switchport mode access
S1(config-if-range)# switchport access vlan 20
S1(config-if-range)# exit
S1(config)# interface range fa0/11 - 15
S1(config-if-range)# switchport mode access
S1(config-if-range)# switchport access vlan 30
S1(config-if-range)# exit
S1(config)# interface range fa0/16 - 20
S1(config-if-range)# switchport mode access
S1(config-if-range)# switchport access vlan 40
S1(config-if-range)# exit
Step 3. Assign IP Addresses to VLANs
Next, we will give each VLAN an IP address. This IP will act as a default gateway for devices in that VLAN.
S1(config)# interface vlan 10
S1(config-if)# ip address 172.16.10.1 255.255.255.0
S1(config-if)# no shutdown
S1(config-if)# exit
S1(config)# interface vlan 20
S1(config-if)# ip address 172.16.20.1 255.255.255.0
S1(config-if)# no shutdown
S1(config-if)# exit
S1(config)# interface vlan 30
S1(config-if)# ip address 172.16.30.1 255.255.255.0
S1(config-if)# no shutdown
S1(config-if)# exit
S1(config)# interface vlan 40
S1(config-if)# ip address 172.16.40.1 255.255.255.0
S1(config-if)# no shutdown
S1(config-if)# exit
Step 4. Save the Configuration
To save your work and make sure it stays after the switch restarts:
S1# copy running-config startup-config
Step 5. Verify VLANs and IPs
S1# show vlan brief
Check the IP addresses of VLAN interfaces
S1# show ip interface brief