实验拓扑
交换机配置
Switch>
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#int f 0/2
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#int f 0/3
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#int f 0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#write
Building configuration...
[OK]
Switch#
路由器配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f 0/0
Router(config-if)#en
Router(config-if)#exit
Router(config)#int f 0/0.10
Router(config-subif)#encapsulation dot1q 10
Router(config-subif)#ip add 192.168.1.254 255.255.255.0
Router(config-subif)#exit
Router(config)#int f 0/0.20
Router(config-subif)#en
Router(config-subif)#encapsulation dot1q
% Incomplete command.
Router(config-subif)#encapsulation dot1q 20
Router(config-subif)#ip add 192.168.2.254 255.255.255.0
Router(config-subif)#exit
Router(config)#int f 0/0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
%LINK-5-CHANGED: Interface FastEthernet0/0.10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.10, changed state to up
%LINK-5-CHANGED: Interface FastEthernet0/0.20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.20, changed state to up
Router(config-if)#exit
Router(config)#exit
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#write
Building configuration...
[OK]
测试,两台PC IP地址设定,再PING
题外话,查看路由器的路由表:
Router#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.1.0/24 is directly connected, FastEthernet0/0.10
C 192.168.2.0/24 is directly connected, FastEthernet0/0.20
Router#
本文出自 “Simon.Xu” 博客,请务必保留此出处http://simonxu.blog.51cto.com/8010209/1386389
原文:http://simonxu.blog.51cto.com/8010209/1386389