type
Post
status
Published
date
Apr 24, 2020
slug
Principles-Of-Computer-Networks-Experiment-3
summary
准备
在 CPT 中拖入 3560-24PS ,放入两个PC机,并在Connections中选择Copper Straight-Through连接Switch的GigabitEthernet 0/1、0/2和两台PC机的FastEthernet 0。
tags
学习
category
学习思考
icon
password
准备
在 CPT 中拖入 3560-24PS ,放入两个PC机,并在Connections中选择Copper Straight-Through连接Switch的GigabitEthernet 0/1、0/2和两台PC机的FastEthernet 0。
开始
划分vlan
给vlan配置地址
双击进入其中一台 Switch 中,为vlan10添加192.168.20.254地址
Switch#en Switch#conf Configuring from terminal, memory, or network [terminal]? Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#interface vlan 10 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan10, changed state to up Switch(config-if)#ip address 192.168.10.254 255.255.255.0 Switch(config-if)#no sh Switch(config-if)#
添加出错后,可为vlan10删除该地址
Switch(config-if)#int vlan 10 Switch(config-if)#no ip addre Switch(config-if)#no ip address 192.168.10.254 255.255.255.0 Switch(config-if)#
或者直接添加新的覆盖
Switch(config-if)#ip address 192.168.10.254 255.255.255.0
用同样的方法,给vlan20添加192.168.20.254 的ip
给接口配置vlan
进入gb0/1与gb0/2,分别给两个接口分配vlan10与vlan20
Switch(config)#interface gigabitEthernet 0/1 Switch(config-if)#switchport access vlan 10 Switch(config-if)# %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up Switch(config-if)#exit Switch(config)#inte Switch(config)#interface gi Switch(config)#interface gigabitEthernet 0/2 Switch(config-if)#switc Switch(config-if)#switchport acc Switch(config-if)#switchport access vlan 20 % Access VLAN does not exist. Creating vlan 20 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan20, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up Switch(config-if)
给PC配置IP
给划分在vlan10上的PC机进行IP配置,IP地址设为192.168.10.1,Gateway设为192.168.10.254,另一台同理。
此时使用一台PC机ping另一台PC机,发现不通,但是ping 192.168.20.254是通的,这是因为交换机目前还没有路由功能。在交换机上输入
Switch(config)#ip routing
这时候就有三层交换机的路由功能了。
这时候就可以ping通了
C:\>ping 192.168.20.1 Pinging 192.168.20.1 with 32 bytes of data: Reply from 192.168.20.1: bytes=32 time=1ms TTL=127 Reply from 192.168.20.1: bytes=32 time<1ms TTL=127 Reply from 192.168.20.1: bytes=32 time=6ms TTL=127 Reply from 192.168.20.1: bytes=32 time<1ms TTL=127 Ping statistics for 192.168.20.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 6ms, Average = 1ms
不划分vlan的交换机配置
给接口配置地址
不划分vlan的时候
Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int g0/1 Switch(config-if)#no swi Switch(config-if)#no switchport Switch(config-if)# %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up Switch(config-if)#ip add Switch(config-if)#ip address 192.168.10.254 255.255.255.0 Switch(config-if)#no sh Switch(config-if)#int g0/2 Switch(config-if)#no sw Switch(config-if)#no switchport Switch(config-if)# %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up Switch(config-if)#ip add Switch(config-if)#ip address 192.168.20.254 255.255.255.0 Switch(config-if)#
并给两台主机分别配置 192.168.10.1 和 192.168.20.1的ip,在 Switch 中输入
Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#ip routing Switch(config)#
在第一台PC机中输入 ping 192.168.20.1 即可ping通
C:\>ping 192.168.20.1 Pinging 192.168.20.1 with 32 bytes of data: Request timed out. Reply from 192.168.20.1: bytes=32 time<1ms TTL=127 Reply from 192.168.20.1: bytes=32 time<1ms TTL=127 Reply from 192.168.20.1: bytes=32 time<1ms TTL=127 Ping statistics for 192.168.20.1: Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms C:\>
问题探究
其他
默认模式下,交换机工作在二层模式下,需要运行 no switchport 将其修改为三层模式。
交换机需要手动配置网络而路由器不用
Preparation
Put the router model 3560-24PS and 2 PCs into Cisco Packet Tracer. Connect the FastEthernet 0 of two PCs with the GigabitEthernet 0/1 and GigabitEthernet 0/2 of the switch by Copper Straight-Through Line.
Start
Divide VLAN
Configure IP Address for VLAN
To enter one of the switches, you should double click it. Then add an IP address 192.168.20.254 for VLAN 10.
Switch#en Switch#conf Configuring from terminal, memory, or network [terminal]? Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#interface vlan 10 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan10, changed state to up Switch(config-if)#ip address 192.168.10.254 255.255.255.0 Switch(config-if)#no sh Switch(config-if)#
If you add a wrong IP, you can delete the IP of VLAN 10, or you can simply add a new IP to overwrite the old IP.
Switch(config-if)#int vlan 10 Switch(config-if)#no ip addre Switch(config-if)#no ip address 192.168.10.254 255.255.255.0 Switch(config-if)#
Switch(config-if)#ip address 192.168.10.254 255.255.255.0
Then use the same way to add the IP 192.168.20.254 for VLAN 20.
VLAN configuration of interface
IP configuration of PC
Configurate IP for the PC which is divided on VLAN 10. Set IP to 192.168.10.1, and set the gateway to 192.168.10.254. Do the same thing on another PC.
Try to use one PC to ping another PC, then you will find that the ICMP packet can't reach. But it is reachable to ping 192.168.20.254. It's because the switch hasn't routing feature yet. Type "ip routing" to enable it.
Then the layer 3 switch feature will be enabled, and the ICMP packet will be reachable.
Switch configuration without VLAN division
IP configuration for the Interface
Without VLAN division
Configurate IP 192.168.10.1 and 192.168.20.1 for two PCs. Type the command.
Type command "ping 192.168.20.1" on PC1. PC1 and PC2 are able to communicate.
Questions to explore
Why Command Prompt report timeout when I tried to ping for the first time?
Others
By the default, the switch works at Layer 2 mode. You should type "no switchport" to turn it to Layer 3 mode.
Also, Switch needs to configurate the network manually but Router doesn't.