三层交换机实现vlan间路由配置

  • 基础知识
  • 常用命令
  • 实验流程
  • 1.设计拓扑
  • 2.配置主机IP地址
  • 3.配置交换机
  • 4.验证主机是否连通
  • 5.查看三层交换机路由信息
  • 6.查看三层交换机ARP缓存


基础知识

二层交换机是利用Mac地址表进行转发操作的,三层交换机是一个带有路由功能的二层交换机,是二者的结合,三层意思是网络层,其优势就是在网络模型的第三层实现数据包的高速转发。

当目的ip与源ip不在同一个三层网段时,发送方会向网关请求ARP解析,这个网关往往是三层交换机里的一个地址,三层交换模块会运用其路由功能,找到下一跳的Mac地址,一方面将该地址保存,并将其发送给请求方,另一方面将该Mac地址发送到二层交换引擎的Mac地址表中,这样以后就可以进行高速地二层转发了,所以 三层交换机有时被描述为“一次路由,多次交换”。

常用命令

命令格式

含义

interface vlan vlan号

进入SVI配置模式

switch trunk encapsulation dot1q

端口模式下用dot1q封装该端口

show arp

查看交换机ARP缓存

show ip route

查看路由信息

ip routing

开启交换机路由功能

实验流程








开始

设计拓扑

配置主机IP地址

配置交换机

验证主机是否连通

查看三层交换机路由信息

查看三层交换机ARP缓存


1.设计拓扑

三层路由器配置VLAN 三层交换机vlan路由配置_OSPF

2.配置主机IP地址

三层路由器配置VLAN 三层交换机vlan路由配置_OSPF_02


三层路由器配置VLAN 三层交换机vlan路由配置_三层交换机_03


三层路由器配置VLAN 三层交换机vlan路由配置_三层交换机_04


三层路由器配置VLAN 三层交换机vlan路由配置_Internet_05

3.配置交换机

1.配置三层交换机

Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#ip routing //开启三层交换机路由功能
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#exit
Switch(config)#interface range g0/1-2
Switch(config-if-range)#switch trunk encapsulation dot1q //默认不封装dot1q,必须先封装然后将其设为trunk
Switch(config-if-range)#switch mode trunk
Switch(config-if-range)#end
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int vlan 10
Switch(config-if)#ip address 192.168.1.1 255.255.255.0
Switch(config-if)#int vlan 20
Switch(config-if)#ip address 192.168.2.1 255.255.255.0

2.配置交换机0

Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#int range f0/1-2
Switch(config-if-range)#switch mode access
Switch(config-if-range)#switch access vlan 10
Switch(config-if-range)#exit
Switch(config)#int g0/1
Switch(config-if)#switch mode trunk

3.配置交换机1

Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 20
Switch(config-vlan)#int range f0/1-2
Switch(config-if-range)#switch mode access
Switch(config-if-range)#switch access vlan 20
Switch(config-if-range)#exit
Switch(config)#int g0/2
Switch(config-if)#switch mode trunk

4.验证主机是否连通

C:\>ping 192.168.2.11

Pinging 192.168.2.11 with 32 bytes of data:

Reply from 192.168.2.11: bytes=32 time=1ms TTL=127
Reply from 192.168.2.11: bytes=32 time<1ms TTL=127
Reply from 192.168.2.11: bytes=32 time<1ms TTL=127
Reply from 192.168.2.11: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.2.11:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

C:\>ping 192.168.2.12

Pinging 192.168.2.12 with 32 bytes of data:

Request timed out.
Reply from 192.168.2.12: bytes=32 time=13ms TTL=127
Reply from 192.168.2.12: bytes=32 time<1ms TTL=127
Reply from 192.168.2.12: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.2.12:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 13ms, Average = 4ms

C:\>

可以看出已经可以连通了。

5.查看三层交换机路由信息

Switch#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, Vlan10
C    192.168.2.0/24 is directly connected, Vlan20

6.查看三层交换机ARP缓存

Switch#show arp
Protocol  Address          Age (min)  Hardware Addr   Type   Interface
Internet  192.168.1.1             -   0030.F2CE.1E01  ARPA   Vlan10
Internet  192.168.1.11            8   0001.974D.848C  ARPA   Vlan10
Internet  192.168.2.1             -   0030.F2CE.1E02  ARPA   Vlan20
Internet  192.168.2.11            8   0002.17DA.951C  ARPA   Vlan20
Internet  192.168.2.12            7   0060.47AD.23BD  ARPA   Vlan20
Switch#