Table of Contents for
Packet Tracer Network Simulator

InterVLAN routing with routers and layer 3 switches

Although VLAN is used to split the broadcast domain, it is necessary to enable communication between two or more VLANs at layer 3 using IP routing. This is called InterVLAN routing and can be configured using both routers and layer 3 switches. This requires allocating a different IP subnet for devices in each VLAN.

We will configure InterVLAN routing by connecting the router to a switch using a single link. All the traffic to other VLANs passes through this link, to the router and back again through this link. This method of configuration is also called router-on-a-stick, as a single link to the router handles all traffic.

InterVLAN on a router

We will use the following topology for this setup:

InterVLAN on a router

As stated earlier, each VLAN will have IP addresses from different network ranges and the router's interface will have three IP addresses—each belonging to a different network.

  1. After IP addresses have been assigned to all PCs, create the necessary VLANs on the switch and assign the ports to them.
    Sw1(config)#int range f0/2-3
    Sw1(config-if-range)#switchport access vlan 10
    Sw1(config-if-range)#int range f0/4-5
    Sw1(config-if-range)#switchport access vlan 20
    Sw1(config-if-range)#int range f0/6-7
    Sw1(config-if-range)#switchport access vlan 30
    
  2. Configure the switch port that connects to the router as a trunk link. More on this in the Switch-to-switch trunk links section.
    Sw1(config)#int f0/1
    Sw1(config-if)#switchport mode trunk
    
  3. Now, moving on to the router portion of the configuration, bring the interface up.
    R1(config)#int f0/0
    R1(config-if)#no shutdown
    
  4. We will now create the subinterfaces. Each will have its own IP address in a different network.
    R1(config-subif)#int f0/0.10
    R1(config-subif)#encapsulation dot1Q 10
    R1(config-subif)#ip address 10.10.0.1 255.255.255.0
    R1(config-subif)#int f0/0.20
    R1(config-subif)#encapsulation dot1Q 20
    R1(config-subif)#ip address 10.20.0.1 255.255.255.0
    R1(config-subif)#int f0/0.30
    R1(config-subif)#encapsulation dot1Q 30
    R1(config-subif)#ip address 10.30.0.1 255.255.255.0
    
  5. Notice the encapsulation command here. It specifies the VLAN ID the interface will handle.
  6. That's it, now test the connectivity between hosts on different VLANs using simple PDUs or a ping. The first packet will always time out as it takes some time for the ARP (Address Resolution Protocol) to complete.

Try using tracert to see the path the packet takes.

InterVLAN on a layer 3 switch

The only layer 3 switch present on Packet Tracer is 3560-24PS. We will use the same topology by replacing only the router with the layer 3 switch, as shown in the following screenshot:

InterVLAN on a layer 3 switch

Creation and configuration of VLANs is the same on the layer 2 switch, hence it won't be repeated here. So, we'll move to the layer 3 switch straightaway.

  1. Since the switch-switch link on the layer 2 switch was set to trunking mode with the switchport mode trunk command, the same port on the layer 3 switch will also be in trunking mode. This can be verified as follows:
    MSw1#sh interface trunk
    
    InterVLAN on a layer 3 switch

    The trunking status indicates this. More on how this port automatically moved to trunk will be discussed in the next section (Switch-to-switch trunk links).

  2. We will configure what is called SVI (Switch Virtual Interface), which will act as layer 3 interfaces for each VLAN.
    MSw1(config)#int vlan 10
    MSw1(config-if)#ip add 10.10.0.1 255.255.255.0
    MSw1(config-if)#int vlan 20
    MSw1(config-if)#ip add 10.20.0.1 255.255.255.0
    MSw1(config-if)#int vlan 30
    MSw1(config-if)#ip add 10.30.0.1 255.255.255.0
    
  3. These interfaces will stay down, as this layer 3 switch doesn't have VLANs 10, 20, and 30. So we'll create them as follows:
    MSw1(config)#vlan 10
    MSw1(config-vlan)#vlan 20
    MSw1(config-vlan)#vlan 30
    
  4. As each command is entered, the associated SVI will come up. IP Routing has to be enabled.
    MSw1(config)#ip routing
    
  5. Use the simple PDU tool to test the connectivity.

Here, too, the first packet will always time out as the ARP process takes some time.