原理简述:
跨交换机实现VLAN间通信的方式:(1)单臂路由;(2)三层交换机。
(1)然而利用单臂路由实现VLAN间主机的访问,存在一些局限:如带宽、转发效率这些问题。
(2)三层交换机在原有二层交换机的基础上增加了路由功能,而且数据也没有想单臂路由那样进过物理线路进行路由。
(3)VLANIF接口:基于网络层的接口,可以进行IP地址的配置。通过VLANIF接口,三层交换机可以实现路由转发功能。
实验内容:
通过配置三层交换机实现所有的主机之间都能互相访问。
实验目的:
(1)掌握配置VLANIF接口的方法;
(2)理解数据包跨VLAN路由的原理;
(3)掌握测试多层交换机网络连通性的方法。
实验拓扑:
实验步骤:
1.基础配置:根据实验要求,完成PC机上相应的配置,如:IP地址的配置。测试一下PC-1与PC-2和PC-3的连通性。
PC>ping 192.168.1.2
Ping 192.168.1.2: 32 data bytes, Press Ctrl_C to break
From 192.168.1.2: bytes=32 seq=1 ttl=128 time=47 ms
From 192.168.1.2: bytes=32 seq=2 ttl=128 time=47 ms
From 192.168.1.2: bytes=32 seq=3 ttl=128 time=47 ms
From 192.168.1.2: bytes=32 seq=4 ttl=128 time=47 ms
From 192.168.1.2: bytes=32 seq=5 ttl=128 time=47 ms
--- 192.168.1.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/47/47 ms
PC>ping 192.168.2.1 //PC-1与PC-3之间不能通信 原因:未在交换机上做任何的配置,故没有设备应答PC-1发出的ARP请求数据包,无法正常封装和转发。
Ping 192.168.2.1: 32 data bytes, Press Ctrl_C to break
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
--- 192.168.1.254 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
数据包转发过程:
主机发出数据包之前,将查看数据包中的目的IP地址,如果目的IP地址和本机的IP地址在同一网段上,主机会直接发出一个ARP请求数据包来请求对方主机的MAC地址,然后封装数据包,继而发送这个数据包。如果目的IP地址与本机的IP地址不在同一个网段上,主机会发送一个ARP请求数据包来请求网关的MAC地址,在收到网关的MAC地址恢复后,才封装数据包发送出去。
2.三层交换机的配置:通过在交换机上配置不同的VLAN实现主机间的相互隔离。
使用interface VLANif命令创建VLANIF接口,并指定接口对应的VLAN ID。在该接口的视图下,可配置其IP地址。
[S1]int Vlanif 10
[S1-Vlanif10]ip ad 192.168.1.254 24
[S1]int Vlanif 20
[S1-Vlanif20]ip ad 192.168.2.254 24
配置完后,查看接口状态。
[S1]dis ip int brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2
Interface IP Address/Mask Physical Protocol
MEth0/0/1 unassigned down down
NULL0 unassigned up up(s)
Vlanif1 unassigned down down
Vlanif10 192.168.1.254/24 up up
Vlanif20 192.168.2.254/24 up up
观察:两个VLANif接口已经生成并生效。
测试PC-1与PC-3间的连通性。
PC>ping 192.168.2.1
Ping 192.168.2.1: 32 data bytes, Press Ctrl_C to break
From 192.168.2.1: bytes=32 seq=1 ttl=127 time=78 ms
From 192.168.2.1: bytes=32 seq=2 ttl=127 time=31 ms
From 192.168.2.1: bytes=32 seq=3 ttl=127 time=47 ms
From 192.168.2.1: bytes=32 seq=4 ttl=127 time=31 ms
From 192.168.2.1: bytes=32 seq=5 ttl=127 time=47 ms
--- 192.168.2.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/46/78 ms
可在PC-1上查看ARP的信息。使用arp -a命令。
PC>arp -a
Internet Address Physical Address Type
192.168.1.254 4C-1F-CC-3C-27-81 dynamic
//只有交换机VLANif 10的地址,没有对端的地址。即先发送给网关(VLANif),由VLANif接口发送至对端。