Inter-VLAN routing is the ability to route, or send, traffic between VLANs that are normally blocked by default. Switches and VLANs work at the MAC address Layer (Layer 2). Traffic can’t be routed between VLANs at Layer 2 based on MAC addresses. Therefore, routers (or Layer 3 switches also called multilayer switch) that use IP addresses (Layer 3) are required for inter-VLAN routing.
Switched Virtual Interface
A Switched Virtual Interface (SVI) is a virtual LAN (VLAN) of switch ports represented by one interface to a routing or bridging system. There is no physical interface for the VLAN and the SVI provides the Layer 3 processing for packets from all switch ports associated with the VLAN. Switch has supervisor engine which has a pool of MAC address and a MAC is given to Logical interface from the same pool.
Switch#int fa0/1
Switch#switchport mode access
Switch#switchport access vlan 10
^z
Switch#int fa0/2
Switch#switchport mode access
Switch#switchport access vlan 20
Once you inserted interface into Vlans you have to create SVI for both vlan and run routing command to perform routing.Switch# int vlan10
Switch# ip add 10.0.0.10 255.0.0.0
^z
Switch#int vlan20
Switch#ip add 20.0.0.10 255.0.0.0
Switch#ip routing [Run routing command]
Note: Give IP address to Pc and Default gateway according to your SVIs IP and check the communication.
Routing-On-a-Stick
The only way to get off a layer two network segment is through a layer three device; commonly referred to as a Default Gateway for host machines, also called Routing-On-a-Stick method. A single Router can utilize an 802.1q trunk link to place a sub-interface in each VLAN using a single physical link and technically have interfaces in all VLAN’s. A Sub-Interface is a logical interface partitioned off from a physical interface. A sub-interface allows you to have multiple interface configurations on a single physical interface. In this lab you’ll use sub-interfaces to match the VLAN’s in the trunk to allow for interfaces in each VLAN and accomplish inter-vlan routing for the hosts as the router has an interface in each layer three network.
To create a new sub-interface you’ll use the interface fa0/0.# command in global configuration mode. To enable the sub-interface to use 802.1q you’ll use the encapsulation dot1q # command whereas # is the dot1q VLAN tag.
R1>enable
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface fa0/0
R1(config-if)#no shut
R1(config-if)#interface fa0/0.20
R1(config-subif)#encapsulation dot1q 20
R1(config-subif)#ip add 10.1.20.1 255.255.255.0
R1(config-subif)#exit
R1(config)#
Note: The above command is to create sub interface for single Vlan 20 with encapsulation dot1q. You have to configure another sub interface in order to communicate VLANs. If you have connected PCs directly then try ping after creating Sub interface with Default gateway as sub interface Ip. If you are using Router as PC then follow below command:
R2>enable
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#no ip routing
R2(config)#ip default-gateway 10.1.20.1
R2(config)#end