本实验需使用 Cisco Packet Tracer 软件完成。 请大家先了解
VLSM、CIDR、RIP、OSPF、VLAN、STP、NAT 及 DHCP 等概念,以能够进行网络规划和配置。
参考:
1.https://www.bilibili.com/video/av33482059/
2.https://blog.csdn.net/Al_assad/article/details/70255987
直接连接两台 PC 构建 LAN
-
将两台 PC 直接连接构成一个网络。注意:直接连接需使用交叉线。
-
进行两台 PC 的基本网络配置,只需要配置 IP 地址即可,然后相互 ping 通即成功
用交换机构建 LAN
PC机的基本网络配置
机器名—IP------------------子网掩码PC0 -----192.168.1.1------255.255.255.0
PC1 -----192.168.1.2------255.255.255.0
PC2 -----192.168.2.1------255.255.255.0
PC3 -----192.168.2.2------255.255.255.0
拓扑图:
✎ 问题
- PC0 能否 ping 通 PC1、PC2、PC3 ?
- PC3 能否 ping 通 PC0、PC1、PC2 ?为什么?
如图,PC0只能ping通PC1,ping不通pc2和pc3
同理,pc5只能ping同pc4,ping不通pc2和pc3,因为pc2,pc3处于一个子网内,pc4,pc5处于同一个子网内,pc只设置了ip和掩码,所以只能子网内通信
- 将 4 台 PC 的掩码都改为 255.255.0.0 ,它们相互能 ping 通吗?为什么?
它们之间可以相互ping通,由于它们与子网掩码相与得到的结果都是192.168.2.1,表示它们都处于192.168.2.1这个子网下面,所以能ping通。
- 使用二层交换机连接的网络需要配置网关吗?为什么?
不需要,由于二层交换机它是子网内部进行数据传输,不需经过到网关对外进行通信,所以,不需要设置网关。
- 集线器 Hub 是工作在物理层的多接口设备,它与交换机的区别是什么?请在 CPT 软件中用 Hub 构建网络进行实际验证。
一、本质区别:
交换机可以分割冲突域, HUB不可以分割冲突域 这是他们最本质的区别 hub连N台电脑,他们共享在一个区域里,如果这个区域里有冲突,所有电脑都受影响。 交换机连n台电脑,每个交换机端口是一个独立的区域,即使有冲突,冲突也局限在相对应的交换机端口,不影响其他电脑。
二、资源占用区别:
比如一个100M的交换机,对每一个连接在交换机的计算机都是100M的速度,而Hub是瓜分100M的资源。而且Hub是通过广播来通信,很占网络资源。
三、类型上的区别:
HUB是广播数据包,交换机是隔离数据包,HUB比交换机卡,是因为几台电脑接HUB上网就像是排队上网一样,一个先上接着轮下一个 交换机则是自由的上网,不用排队。
交换机接口地址列表
二层交换机是一种即插即用的多接口设备,它对于收到的帧有 3 种处理方式:广播、转发和丢弃(请弄清楚何时进行何种操作)。那么,要转发成功,则交换机中必须要有接口地址列表即 MAC 表,该表是交换机通过学习自动得到的!
仍然构建上图的拓扑结构,并配置各计算机的 IP 在同一个一个子网,使用工具栏中的放大镜点击某交换机如左边的 Switch3,选择 MAC Table,可以看到最初交换机的 MAC 表是空的,也即它不知道该怎样转发帧(那么它将如何处理?),用 PC0 访问(ping)PC1 后,再查看该交换机的 MAC 表,现在有相应的记录,请思考如何得来。随着网络通信的增加,各交换机都将生成自己完整的 MAC 表,此时交换机的交换速度就是最快的!
未进行ping的操作的MAC表:
进行ping后的MAC表
此时可见,交换机的mac地址表内多了三个mac地址,原理是pc4发送一个icmp包,交换机收到,此时交换机的mac地址表为空,不知道收到的来自pc4的包的目的地是哪,所以向所有连接的设备广播这个icmp包,然后所有收到广播的设备返回信息,就收集到所有与交换机直接连接的设备的mac地址
生成树协议(Spanning Tree Protocol)
交换机在目的地址未知或接收到广播帧时是要进行广播的。如果交换机之间存在回路/环路,那么就会产生广播循环风暴,从而严重影响网络性能。
而交换机中运行的 STP 协议能避免交换机之间发生广播循环风暴。
拓扑图:
当switch3和switch2之间的线路出现问题后,会重新根据STP协议生成一个新的生成树
虚拟局域网 VLAN
VLAN(Virtual Local Area Network)即虚拟局域网。通过划分 VLAN,我们可以把一个物理网络划分为多个逻辑网段即多个子网。
拓扑图:
交换机 VLAN 配置
Switch>en
Switch#conf t
Switch(config)#vlan 10 // 创建 id 为 10 的 VLAN(缺省的,交换机所有接口都属于VLAN 1,不能使用)
Switch(config-vlan)#name computer // 设置 VLAN 的别名
Switch(config-vlan)#exit
Switch(config)#int vlan 10 // 该 VLAN 为一个子网,设置其 IP,作为该子网网关
Switch(config-if)#ip address 192.168.0.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#vlan 20 // 创建 id 为 20 的 VLAN
Switch(config-vlan)#name communication //设置别名
Switch(config-vlan)#exit
Switch(config)#int vlan 20
Switch(config-if)#ip addr 192.168.1.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#vlan 30 // 创建 id 为 20 的 VLAN
Switch(config-vlan)#name electronic // 设置别名
Switch(config-vlan)#exit
Switch(config)#int vlan 30
Switch(config-if)#ip add 192.168.2.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#int range f0/1-8 // 成组配置接口(1-8)
Switch(config-if-range)#switchport mode access // 设置为存取模式
Switch(config-if-range)#switchport access vlan 10 // 划归到 VLAN 10 中
Switch(config-if-range)#exit
Switch(config)#int range f0/9-16
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 20
Switch(config-if-range)#exit
Switch(config)#int range f0/17-24
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 30
Switch(config-if-range)#^Z
Switch#show vlan // 查看 VLAN 的划分情况
PC机配置
机器名 连接的接口 所属VLAN IP 子网掩码 网关
PC0 F0/1 VLAN 10 192.168.0.2 255.255.255.0 192.168.0.1
PC1 F0/2 VLAN 10 192.168.0.3 255.255.255.0 192.168.0.1
PC2 F0/17 VLAN 30 192.168.2.2 255.255.255.0 192.168.2.1
PC3 F0/9 VLAN 20 192.168.1.2 255.255.255.0 192.168.1.1
PC4 F0/10 VLAN 20 192.168.1.3 255.255.255.0 192.168.1.1
PC5 F0/18 VLAN 30 192.168.2.3 255.255.255.0 192.168.2.1
PC6 F0/19 VLAN 30 192.168.2.4 255.255.255.0 192.168.2.1
✎ 思考
分析一下当前为何不同 VLAN 中的 PC 不能通信?网关在此起什么作用?我们的网关又在何处?如何发起广播测试?
此时不同vlan中的pc不能通信时由于他们处于不同的子网,网关起到了信息拦截的作用,此时网关应为相同子网下与交换机连接的端口,广播测试:ping一个不同子网下ip
DHCP、DNS及Web服务器简单配置
拓扑图:
该拓扑中,服务器及客户机都连在同一交换机上。为简单起见,服务器 Server-PT 同时作为 DHCP、DNS 以及 Web 服务器,各客户机无需配置,将自动获取网络配置。
点击 CPT 拓扑图中的 Server 图标,设置其静态 IP 地址为 19.89.6.4/24,然后选择 Service 进行如下相关配置:
机器名 配置项目 说明
Server HTTP 开启即可
Server DNS 19.89.6.4:www.google.com、www.baidu.com
Server DHCP 地址池开始地址:19.89.6.10/24,并返回DNS地址
PC 网络配置 自动获取
小结
通过应用Cisco Packet Tracer来构建一些简单的拓扑图,来理解交换机和路由器是怎么工作,来实现通信的。现在可以比较熟练的使用该工具,对一些IP,交换机,路由器的一些配置,也有了一定的了解。独立的构建一个网络还是存在一定的困难。
此部分的难度较大,很多东西都没没有很好的完成
参考:https://qige.io/network/netlab/index.html#3