一、实验题目
二、实验过程
1.建立拓扑结构
①添加各设备并添加路由器Router1的端口f1/0:
设备添加完成如图1。接下来进行路由器f1/0端口添加:单击路由器会弹出对话框;首先关闭电源;关闭路由器电源后,在物理模块中选择NM-2FE2W,拖到物理设备视图界面的左上角黑框区域,效果如图2;随后开启电源,进入配置模块,弹出对话框,点击ok即可;在左侧即可以看到完成FastEthernet0/0、FastEthernet0/1、FastEthernet1/0、FastEthernet1/1接口的添加,效果如图3。
图1
图2
图3
②各设备按照以下方式连接直通线:
PC1的f0端口连接Switch1的f0/1端口,PC2的f0端口连接Switch2的f0/1端口,PC3的f0端口连接Switch3的f0/1端口,Switch1、Switch2、Switch3的f0/2端口分别和Router1的f0/0、f0/1、f1/0相连接。
图4
③为各设备配置ip地址、子网掩码、网关:
PC1的ip地址是192.168.1.5,子网掩码255.255.255.0,网关为192.168.1.254(如图5);PC2的ip地址是192.168.2.5,子网掩码255.255.255.0,网关为192.168.2.254(如图6);PC3的ip地址是192.168.3.5,子网掩码255.255.255.0,网关为192.168.3.254(如图7);路由器f0/0、f0/1、f1/0的ip地址分别为192.168.1.254、192.168.2.254、192.168.3.254,子网掩码都是255.255.255.0(图8、图9),路由器配置完成后,所有接口已经变为绿色(图10),说明理论上已经完成了物理通路。
对路由器ip配置的源码如下:
进入到全局配置模式
Router>enable
Router#configure terminal
Router(config)#
//进入Fa0/0端口进行IP配置
Router(config)#interface fastEthernet 0/0
Router(config-if)#ip address 192.168.1.254 255.255.255.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
//进入到Fa0/1端口进行IP配置。
Router(config-if)#interface fastEthernet 0/1
Router(config-if)#ip address 192.168.2.254 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
//进入到Fa1/0端口进行IP配置。
Router(config-if)#interface fastEthernet 1/0
Router(config-if)#ip address 192.168.3.254 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
图5
图56
图7
图8
图9
图10
2.测试三台主机之间的连通性
PC1分别ping命令PC2和PC3(图11);PC2分别ping命令PC1和PC3(图12);PC3分别ping命令PC1和PC2(图13);
图11
图12
图13
由此可以发现,3台主机之间可以两两相互ping通;
3.创建vlan实现网段隔离
将PC1和PC3划分在vlan1内,PC2划分在vlan2的网内,实现PC1和PC2的通信,PC2和PC3的隔离。
Switch1的f0/1端口划分vlan 1,Switch2的f0/1端口划分vlan 2,
Switch3的f0/1端口划分vlan 1,各个端口链路设置为access模式,
3个交换机Switch和路由器Router1的连接端口设置为trunk模式。
Switch1划分vlan的源码:
Switch>enable
Switch#configure terminal
Switch(config)#vlan 1
Switch(config-if)#interface fa0/1
## 设置端口的链路为接入链路模式
Switch(config-if)#switch mode access
## 接入链路允许VLAN1的帧通过
Switch(config-if)#switch access vlan 1
Switch(config-if)#exit
Switch2划分vlan的源码:
Switch>enable
Switch#configure terminal
Switch(config)#vlan 2
Switch(config-if)#interface fa0/1
## 设置端口的链路为接入链路模式
Switch(config-if)#switch mode access
## 接入链路允许VLAN1的帧通过
Switch(config-if)#switch access vlan 2
Switch(config-if)#exit
Switch3划分vlan的源码:
Switch>enable
Switch#configure terminal
Switch(config)#vlan 1
Switch(config-if)#interface fa0/1
## 设置端口的链路为接入链路模式
Switch(config-if)#switch mode access
## 接入链路允许VLAN1的帧通过
Switch(config-if)#switch access vlan 1
Switch(config-if)#exit
Switch1、Switch2、Switch3设置trunk接口:
Switch>enable
Switch#configure terminal
Switch(config)#interface fa0/2
Switch(config-if)#switch mode trunk
图14
图15
图16
图17
图18
图19
4.测试网络隔离效果
PC1分别ping命令PC2和PC3(图20);PC2分别ping命令PC1和PC3(图21);PC3分别ping命令PC1和PC2(图22);
图20
图21
图22
由此可以看出,PC1和PC3可以相互通信,PC2无法和PC2和PC3实现通信,最终完成不同vlan之间相互隔离的目的。
三、实验总结
交换机连接的主机都在一个网段内,路由器连接的交换机/主机都在异构网络中,即不在同一个网段,各个端口的网段不同,但每个端口下的主机都对应端口的网段下,并且主机的网关对应各个端口的ip地址,因此通过路由器的分组转发功能能够实现不同网段设备之间的通信。要使PC1网段能够与PC3通信,将这两个网段划分在同一个vlan内,PC2在另一个vlan中,实现vlan之间的隔离就可以完成题目要求。