In our last two tutorials we looked at VLANs and Trunking, where we created two VLANs on two switches and linked them with a trunk port. At the end of that tutorial, the VLANs of same ID were able to communicate across the two switches. In this tutorial, we shall look at how the different VLANs can communicate, known as Inter-VLAN routing, by configuring Router on a stick.


In this tutorial, we shall add a router to the previous topology, as seen below:

undefined

 

1. Setup the initial router configuration (This was covered in the previous tutorial).

2. Now on the router, we have to create sub-interfaces on port fa0/0 in order to route between the two VLANs. This sub-interface could be any number, but for the sake of manageability we shall assign 10 for VLAN 10, and 20 for VLAN 20. To achieve this, we have to enter the sub-interface, specify which VLANs this interface will be part of via encapsulation, and assign IP address to the sub-interfaces.

 

router1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router1(config)#int fa0/0.10
router1(config-subif)#encapsulation dot1q 10
router1(config-subif)#ip address 192.168.1.254 255.255.255.0
router1(config-subif)#exit
router1(config)#int fa0/0.20
router1(config-subif)#encapsulation dot1q 20
router1(config-subif)#ip address 192.168.2.254 255.255.255.0
router1(config-subif)#exit
router1(config)#

In the above commands, we assigned the IP address 192.168.1.254/24 to the sub-interface 10, and 192.168.2.254/24 to the sub-interface 20 in order to put then on the same network as hosts on VLAN 10 and VLAN 20 respectively.

 

3. Now we need to force the port fa0/0 up

outer1(config)#int fa0/0
router1(config-if)#no shutdown
router1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINK-5-CHANGED: Line protocol on Interface FastEthernet0/0, changed state to up

 

4. Since the router is directly connected to switch1 via fa0/3, we need to configure that port as a trunk on switch1

switch1(config)#int fa0/3
switch1(config-if)#switchport mode trunk
switch1(config-if)#

 

5. Assign default gateways to the hosts. 192.168.1.254 for hosts on VLAN 10, and 192.168.2.254 for hosts on VLAN 20.

undefined

 

undefined

 

6. Now let’s test connectivity by pinging Host2 on VLAN 20 from Host1 on VLAN 10 and vice versa.

undefined

 

Alternatively, this Inter-VLAN routing can also be achieved on a layer 3 switch. In this example, we shall remove the Router from the topology and make Switch1 a layer 3 switch.


a. Convert switch1 into a layer 3 switch with the command ip routing in global configuration mode. Note the change of the look of switch1 as in the image below:

switch1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
switch1(config)#ip routing

switch1(config)#

undefined

b. Assign the IP address 192.168.1.254/24 to interface vlan 10, and 192.168.2.254/24 to interface vlan 20 on switch 1

switch1(config)#int vlan 10
switch1(config-if)#ip address 192.168.1.254 255.255.255.0
switch1(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan 10, changed state to up
%LINK-5-CHANGED: Line protocol on Interface FastEthernet0/0, changed state to up

switch1(config)#int vlan 20
switch1(config-if)#ip address 192.168.2.254 255.255.255.0
switch1(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan 20, changed state to up
%LINK-5-CHANGED: Line protocol on Interface FastEthernet0/0, changed state to up

 

c. Ping a host across the VLANs and see the successful reply.

 

 

Note: Don’t forget to run the copy running-config startup-config command on the switches and the router to save all configurations.