在交换机上配置VLAN,并在路由器上配置动态路由,使得属于不同VLAN的交换机端口连接的主机可以互相通信,拓扑图如下:
PC1: IP地址为10.1.2.10 子网掩码为255.255.255.0
PC2: IP地址为10.1.3.20 子网掩码为255.255.255.0
PC3: IP地址为10.1.2.30 子网掩码为255.255.255.0
PC4: IP地址为10.1.3.40 子网掩码为255.255.255.0
VLAN2中的所有主机的缺省网关为:10.1.2.1
VLAN3中的所有主机的缺省网关为:10.1.3.1
1.在配置VLAN之前,测试与交换机不同端口相连PC1、PC2、PC3、PC4间的连通性。
分别查看PC的IP地址;
用Ping尝试其连通性,验证PC1、PC2、PC3、PC4间 能互相通信;
2.在交换机上配置VLAN1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23Switch> enable \\从用户模式进入特权模式
Switch# config terminal
Switch(config)# \\进入到全局配置模式
Switch(config)#vlan 2
Switch(config-vlan)#name test2
注:创建vlan 2,并将Vlan 2 命名为test2
Switch(config-vlan)# vlan 3
Switch(config-vlan)#name test3
注:创建vlan 3,并将Vlan 3 命名为test3
Switch(config)#int f0/7 //进入快速以太网端口7的配置模式
Switch(config-if)#switchport mode access //设置端口的链路为接入链路模式
Switch(config-if)#switchport access vlan 2 //接入链路允许VLAN2的帧通过
Switch(config)#int f0/8 //进入快速以太网端口8的配置模式
Switch(config-if)#switchport mode access //设置端口的链路为接入链路模式
Switch(config-if)#switchport access vlan 3 //接入链路允许VLAN3的帧通过
Switch(config-if)#int f0/9 //进入快速以太网端口9的配置模式
Switch(config-if)#switchport mode access //设置端口的链路为接入链路模式
Switch(config-if)#switchport access vlan 2 //接入链路允许VLAN2的帧通过
Switch(config-if)#int f0/10 //进入快速以太网端口10的配置模式
Switch(config-if)#switchport mode access //设置端口的链路为接入链路模式
Switch(config-if)#switchport access vlan 3 //接入链路允许VLAN3的帧通过
Switch(config)#int f0/12 //进入快速以太网端口12的配置模式
Switch(config-if)#switchport mode trunk //设置当前端口为Trunk模式
3.在配置VLAN后,测试与交换机不同端口相连PC1、PC2、PC3、PC4间的连通性。
分别查看PC的IP地址;
用Ping尝试其连通性,验证在同一个Vlan2中的PC1与PC3间能Ping通,在同一个Vlan3中的PC2与PC4间能Ping通;而属于不同Vlan的PC间不能Ping通。
4.外部路由器的配置1
2
3
4
5
6
7
8
9
10
11Router(config)#int f0/0 //进入f0/0的接口配置模式
Router(config-if)#no shut //激活接口
Router(config)#int f0/0.2 //进入f0/0.2的逻辑子接口模式
Router(config-subif)#encapsulation dot1Q 2 //定义VLAN的封装,帧标识封装为IEEE802.1Q,允许VLAN2的帧过
Router(config-subif)#ip address 10.1.2.1 255.255.255.0 //配置f0/0.2的逻辑子接口的IP地址为10.1.2.1,子网掩为:255.255.255.0
Router(config)#int f0/0.3 //进入f0/0.3的逻辑子接口模式
Router(config-subif)#encapsulation dot1Q 3 //定义VLAN的封装,帧标识封装为IEEE802.1Q,允许VLAN3的帧过
Router(config-subif)#ip address 10.1.3.1 255.255.255.0 //配置f0/0.3的逻辑子接口的IP地址为10.1.3.1,子网掩为:255.255.255.0
Router(config)#router rip //启动RIP路由协议
Router(config-router)#network 10.1.2.0 //指明向网络10.1.2.0通告路由
Router(config-router)#network 10.1.3.0 //指明向网络10.1.3.0通告路由