Switch#conf tSwitch(config)#vlan 10Switch(config-vlan)#exitSwitch(config)#vlan 20Switch(config-vlan)#exitSwitch(config)#int f0/1Switch(config-if)#switchport mode accessSwitch(config-if)#switchport access vlan 10Switch(config-if)#exitSwitch(config)#int f0/2Switch(config-if)#switchport mode accessSwitch(config-if)#switchport access vlan 20Switch(config-if)#exitSwitch(config)#int g0/1Switch(config-if)#switchport mode accessSwitch(config-if)#switchport access vlan 10Switch(config-if)#int g0/2Switch(config-if)#switchport mode accessSwitch(config-if)#switchport access vlan 20Switch(config-if)#end---路由器配置Router>enRouter#conf tRouter(config)#int f0/0Router(config-if)#ip address 192.168.10.254 255.255.255.0Router(config-if)#no shutdownRouter(config-if)interface f0/1Router(config-if)#ip address 192.168.20.254 255.255.255.0Router(config-if)#no shutdown
Router(config-if)#no shut
Router(config-if)#int f0/0.10
Router(config-subif)#
Router(config-subif)#encapsulation dot1Q vlan 10
Router(config-subif)#ip address 192.168.10.254 255.255.255.0
Router(config-subif)#int f0/0.20
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip add 192.168.20.254 255.255.255.0
Router(config-subif)#do show ip int bri
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES manual up up
FastEthernet0/0.10 192.168.10.254 YES manual up up
FastEthernet0/0.20 192.168.20.254 YES manual up up
Switch>
Switch>en
Switch#conf t
Switch(config)#int g0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#
配置:Switch>en
Switch#conf t
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#int vlan 10
Switch(config-if)#ip add 192.168.10.254 255.255.255.0
Switch(config-if)#int vlan 20
Switch(config-if)#ip add 192.168.20.254 255.255.255.0
Switch(config-if)#exit
Switch(config)#int g0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int g0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#ip routing
Switch(config-if)#do show ip route
Codes: C - connected, S - static, I - IGRP, 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
C 192.168.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
Switch(config-if)#