Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#vla 2 Switch(config-vlan)#int f0/1 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 1 Switch(config-if)#int f0/2 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 2 Switch(config-if)#exit Switch(config)#ip routing '开启路由功能 Switch(config)#int vlan 1 Switch(config-if)#no shutdown %LINK-5-CHANGED: Interface Vlan1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up Switch(config-if)#ip address 192.168.1.254 255.255.255.0 Switch(config-if)#int vlan 2 %LINK-5-CHANGED: Interface Vlan2, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan2, changed state to upSwitch(config-if)#no shut Switch(config-if)#no shutdown Switch(config-if)#ip address 192.168.2.254 255.255.255.0 Switch(config-if)#end %SYS-5-CONFIG_I: Configured from console by console Switch#sh ip rou 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, Vlan1 C 192.168.2.0/24 is directly connected, Vlan2 Switch# Packet Tracer PC Command Line 1.0 PC>ipconfig /all Physical Address……: 0030.A399.6C5B IP Address……: 192.168.1.1 Subnet Mask……: 255.255.255.0 Default Gateway……: 192.168.1.254 DNS Servers……: 0.0.0.0 PC>ping 192.168.2.1 Pinging 192.168.2.1 with 32 bytes of data: Reply from 192.168.2.1: bytes=32 time=63ms TTL=127 Reply from 192.168.2.1: bytes=32 time=63ms TTL=127 Reply from 192.168.2.1: bytes=32 time=62ms TTL=127 Reply from 192.168.2.1: bytes=32 time=63ms TTL=127 Ping statistics for 192.168.2.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 62ms, Maximum = 63ms, Average = 62ms PC> 不同VLAN通讯需要第三层的路由器,没有三层交换机时,可以用一个路由器加一个交换机做单臂路由: 路由器的设置: Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int f0/0 Router(config-if)#no shut %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up Router(config-if)#int f0/0.1 %LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to upRouter(config-subif)#en Router(config-subif)#encapsulation dot1Q 1 native Router(config-subif)#ip address 192.168.1.254 255.255.255.0 Router(config-subif)#int f0/0.2 %LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to upRouter(config-subif)#en Router(config-subif)#encapsulation dot1Q 2 Router(config-subif)#ip address 192.168.2.254 255.255.255.0 Router(config-subif)#end %SYS-5-CONFIG_I: Configured from console by console Router# 交换机的配置: Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#vla 2 Switch(config-vlan)#int f0/2 Switch(config-if)#switchport access vlan 2 Switch(config-if)#switchport mode access Switch(config-if)#exit Switch(config)#int f0/1 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 1 Switch(config-if)#end %SYS-5-CONFIG_I: Configured from console by console Switch#sh vlan br VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/3, Fa0/4, Fa0/5 Fa0/6, Fa0/7, Fa0/8, Fa0/9 Fa0/10, Fa0/11, Fa0/12, Fa0/13 Fa0/14, Fa0/15, Fa0/16, Fa0/17 Fa0/18, Fa0/19, Fa0/20, Fa0/21 Fa0/22, Fa0/23, Fa0/24 2 VLAN0002 active Fa0/2 1002 fddi-default active 1003 token-ring-default active 1004 fddinet-default active 1005 trnet-default active Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int f0/24 Switch(config-if)#switchport mode trunk Switch(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/24, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up PC>ipconfig /all Physical Address……: 00E0.8FE0.8D94 IP Address……: 192.168.1.1 Subnet Mask……: 255.255.255.0 Default Gateway……: 192.168.1.254 DNS Servers……: 0.0.0.0 PC>ping 192.168.2.1 Pinging 192.168.2.1 with 32 bytes of data: Reply from 192.168.2.1: bytes=32 time=125ms TTL=127 Reply from 192.168.2.1: bytes=32 time=125ms TTL=127 Reply from 192.168.2.1: bytes=32 time=125ms TTL=127 Reply from 192.168.2.1: bytes=32 time=125ms TTL=127 Ping statistics for 192.168.2.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 125ms, Maximum = 125ms, Average = 125ms PC> |