On the switch
The switch port to the router is a trunk. Routers don't speak DTP, so set it to switchport mode trunk.
On the router
- Bring up the physical interface (
no shutdown); it has no address itself. - Create a subinterface per VLAN:
interface g0/0.10. The number after the dot can be anything, but matching the VLAN keeps you sane. encapsulation dot1Q 10: this subinterface handles frames tagged with VLAN 10. It must come before the IP address.ip address: the gateway address for that VLAN.
In NetLab
▶ SW1 SW1>enable SW1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#interface g0/1 SW1(config-if)#switchport mode trunk SW1(config-if)#end *Mar 1 00:00:05.000: %SYS-5-CONFIG_I: Configured from console by console ▶ R1 R1>enable R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface g0/0 R1(config-if)#no shutdown *Mar 1 00:00:09.000: %LINK-3-UPDOWN: Interface GigabitEthernet0/0, changed state to up *Mar 1 00:00:09.000: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up R1(config-if)#interface g0/0.10 *Mar 1 00:00:10.000: %LINK-3-UPDOWN: Interface GigabitEthernet0/0.10, changed state to up *Mar 1 00:00:10.000: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0.10, changed state to up R1(config-subif)#encapsulation dot1Q 10 R1(config-subif)#ip address 192.168.10.1 255.255.255.0 R1(config-subif)#interface g0/0.20 *Mar 1 00:00:13.000: %LINK-3-UPDOWN: Interface GigabitEthernet0/0.20, changed state to up *Mar 1 00:00:13.000: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0.20, changed state to up R1(config-subif)#encapsulation dot1Q 20 R1(config-subif)#ip address 192.168.20.1 255.255.255.0 R1(config-subif)#end *Mar 1 00:00:16.000: %SYS-5-CONFIG_I: Configured from console by console R1#show ip interface brief Interface IP-Address OK? Method Status Protocol GigabitEthernet0/0 unassigned YES unset up up GigabitEthernet0/0.10 192.168.10.1 YES manual up up GigabitEthernet0/0.20 192.168.20.1 YES manual up up GigabitEthernet0/1 unassigned YES unset administratively down down GigabitEthernet0/2 unassigned YES unset administratively down down R1#show ip route | begin Gateway Gateway of last resort is not set 192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.10.0/24 is directly connected, GigabitEthernet0/0.10 L 192.168.10.1/32 is directly connected, GigabitEthernet0/0.10 192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.20.0/24 is directly connected, GigabitEthernet0/0.20 L 192.168.20.1/32 is directly connected, GigabitEthernet0/0.20 ▶ PC2 student@PC2:~$ ping -c 3 192.168.10.10 PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data. 64 bytes from 192.168.10.10: icmp_seq=2 ttl=127 time=0.640 ms 64 bytes from 192.168.10.10: icmp_seq=3 ttl=127 time=0.580 ms --- 192.168.10.10 ping statistics --- 3 packets transmitted, 2 received, 33% packet loss, time 2002ms rtt min/avg/max/mdev = 0.580/0.610/0.640/0.030 ms
The native VLAN
Untagged frames on the trunk belong to the native VLAN. If that VLAN needs a gateway too, configure its subinterface with encapsulation dot1Q 99 native (or put the address on the physical interface). The router and the switch must agree on which VLAN is native.
Common mistake: Typing
ip addressbeforeencapsulation dot1Qon a subinterface fails: IOS refuses to configure IP on a subinterface that has no VLAN yet.