Octet

Route between two VLANs with one router interface

Cisco IOSCore

Tasks

  1. Create VLANs 10 and 20 on SW1 and put PC1 and PC2 in them.
  2. Make Gi1/0/48 a trunk that carries only VLANs 10 and 20.
  3. Create one subinterface per VLAN on R1 with the gateway address.

Solution

  1. 1VLANs and access portsSW1
    SW1 on Cisco IOS
    vlan 10
     name USERS
    vlan 20
     name SALES
    interface GigabitEthernet1/0/1
     switchport mode access
     switchport access vlan 10
    interface GigabitEthernet1/0/2
     switchport mode access
     switchport access vlan 20
  2. 2Trunk to the routerSW1
    SW1 on Cisco IOS
    interface GigabitEthernet1/0/48
     switchport mode trunk
     switchport trunk allowed vlan 10,20
     switchport nonegotiate

    Some platforms need switchport trunk encapsulation dot1q before switchport mode trunk.

  3. 3Subinterfaces on R1R1
    R1 on Cisco IOS
    interface GigabitEthernet0/0/0
     no shutdown
    interface GigabitEthernet0/0/0.10
     encapsulation dot1Q 10
     ip address 10.10.0.1 255.255.255.0
    interface GigabitEthernet0/0/0.20
     encapsulation dot1Q 20
     ip address 10.20.0.1 255.255.255.0

    The physical interface needs no shutdown; the subinterfaces follow its state.

Verify

R1 output
R1# show ip interface brief | include 0/0/0
GigabitEthernet0/0/0     unassigned      YES unset  up                    up
GigabitEthernet0/0/0.10  10.10.0.1       YES manual up                    up
GigabitEthernet0/0/0.20  10.20.0.1       YES manual up                    up

All three lines up/up.

PC1 output
PC1# ping 10.20.0.10
Reply from 10.20.0.10: bytes=32 time=1ms TTL=127

TTL 127 (one less than the Windows default of 128) shows the packet was routed once, by R1.

Mistakes people make

  • Forgetting no shutdown on the physical interface.
  • The VLAN number in encapsulation dot1Q must match the switch VLAN. The subinterface number does not have to, but keep them equal.
  • Leaving the trunk in auto negotiation against a router, which does not speak DTP.

On other platforms

The same idea on a Linux router with VLAN interfaces.

Linux
ip link add link eth0 name eth0.10 type vlan id 10
ip link add link eth0 name eth0.20 type vlan id 20
ip addr add 10.10.0.1/24 dev eth0.10
ip addr add 10.20.0.1/24 dev eth0.20
ip link set eth0 up; ip link set eth0.10 up; ip link set eth0.20 up
sysctl -w net.ipv4.ip_forward=1

Say it in the interview

"One trunk, one subinterface per VLAN, encapsulation dot1Q with the VLAN ID and the gateway IP. It is cheap and simple, but all inter-VLAN traffic hairpins over one link, so in a real campus I would use SVIs on a layer 3 switch."