This lab is based on the topology of the labVLAN trunk. After finish that lab, we can just connect a router to the S3, and topology becomes the following:Inter-VLAN routing_lab

 

  1. Step one, configure switch port :
    S3(config)#int f0/1
    s3(config-if)#switchport mode trunk

    %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

     s3(config-if)#switchport native vlan 23
     s3(config-if)#switchport trunk allowed vlan 10,20,30   
     s3(config-if)#do show int trunk
    Port Mode Encapsulation Status Native vlan
    Fa0/1 on     802.1q    trunking    23
    Gig0/1 on     802.1q   trunking    23
    Gig0/2 on     802.1q   trunking    23
    Port Vlans allowed on trunk
    Fa0/1 10,20,23,30
    Gig0/1 10,20,30
    Gig0/2 10,20,30
    Port Vlans allowed and active in management domain
    Fa0/1 10,20,30
    Gig0/1 10,20,30
    Gig0/2 10,20,30
    Port Vlans in spanning tree forwarding state and not pruned
    Fa0/1 10,20,30
    Gig0/1 10,20,30
    Gig0/2 10,20,30
  2. Configure router subinterface.  r1(config)#int g0/1.10
    %LINK-5-CHANGED: Interface GigabitEthernet0/1.10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1.10, changed state to upr1(config-subif)#encapsulation dot1q 10
    r1(config-subif)#ip add 192.168.10.1 255.255.255.0
    r1(config-subif)#int g0/1.20
    r1(config-subif)#
    %LINK-5-CHANGED: Interface GigabitEthernet0/1.20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1.20, changed state to upr1(config-subif)#encapsulation dot1Q 20
    r1(config-subif)#ip add 192.168.20.1 255.255.255.0
    r1(config-subif)#int g0/1.30
    r1(config-subif)#
    %LINK-5-CHANGED: Interface GigabitEthernet0/1.30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1.30, changed state to up

    r1(config-subif)#encapsulation dot1Q 30
    r1(config-subif)#ip add 192.168.30.1 255.255.255.0
    r1(config-subif)#exit
    r1(config)#int g0/1
    r1(config-if)#no shutdown
    r1(config-if)#do show ip rout
    Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
    D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
    N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
    E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
    i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
    * - candidate default, U - per-user static route, o - ODR
    P - periodic downloaded static route

    Gateway of last resort is not set

    192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
    C 192.168.1.0/24 is directly connected, GigabitEthernet0/1
    L 192.168.1.1/32 is directly connected, GigabitEthernet0/1
    192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks
    C 192.168.10.0/24 is directly connected, GigabitEthernet0/1.10
    L 192.168.10.1/32 is directly connected, GigabitEthernet0/1.10
    192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks
    C 192.168.20.0/24 is directly connected, GigabitEthernet0/1.20
    L 192.168.20.1/32 is directly connected, GigabitEthernet0/1.20
    192.168.30.0/24 is variably subnetted, 2 subnets, 2 masks
    C 192.168.30.0/24 is directly connected, GigabitEthernet0/1.30
    L 192.168.30.1/32 is directly connected, GigabitEthernet0/1.30

  • Remember to configure the IP address of the sub_interface as the default gateway on the PC. Or else the pc won’t forward packet to the router.