思科高级配置(三层交换配置路由)

三层交换机实现VLAN间互通后,需路由机制与其他网络通信。可将交换接口配置为三层接口并配置路由。实现此功能步骤包括:VLAN配置、将三层交换端口配为三层路由端口并设IP、配置路由器端口IP、在交换机配默认路由、在路由器配静态路由,最后测试连通性。

三层交换机实现了VLAN间互通后,还要与其他网络进行通信,这样就需要有相关的路由机制。
1)交换接口配置为三层接口实现路由间通信

三层交换机既然具有三层功能,也就可以实现与路由器相似的配置。既可以把交换接口配置为三层接口,也可以在其上配置静态、动态路由。通过对三层交换机的路由配置,实现VLAN与其他网络的互通。
网络的拓扑结构如图
在这里插入图片描述

实现此案例需要按照如下步骤进行。
步骤一:VLAN等配置与上面2 三层交换vlan间通信通完全一致,不再赘述
步骤二:将三层交换的Fa0/23口配置为三层路由端口,并配置IP地址
三层交换机的物理端口默认是二层端口,只具有二层特性,不能配置IP地址。把二层端口配置为三层端口后,该端口就具备路由功能了,可以配置IP地址,但同时也就关闭了其二层特性,比如不能把三层端口加入VLAN。
二层端口(交换机上的端口默认都是二层端口)默认是激活状态,那些没有使用到的端口为了安全应该手工将其禁用(shutdown);而三层端口(路由器上的端口或是三层交换机上被配置成路由端口的端口)默认是禁用状态,在使用之前务必要将其激活(no shutdown)。

tarenasw-3L(config)#interface f0/23
tarenasw-3L(config-if)#no switchport 
tarenasw-3L(config-if)#ip address 192.168.10.2 255.255.255.0
tarenasw-3L(config-if)#no shutdown

步骤三:配置路由器的端口IP地址

tarena-rouer(config)#interface f0/0
tarena-rouer(config-if)#ip address 192.168.10.1 255.255.255.0
tarena-rouer(config-if)#no shutdown
tarena-rouer(config-if)#interface f0/1
tarena-rouer(config-if)#ip address 200.1.1.1 255.255.255.0
tarena-rouer(config-if)#no shutdown

步骤四:在三层交换机上配置默认路由,以便VLAN内主机可以与外界网络互联

tarenasw-3L(config)#ip route 0.0.0.0 0.0.0.0 192.168.10.1
tarenasw-3L(config)#exit
tarenasw-3L#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 192.168.10.1 to network 0.0.0.0
C    192.168.1.0/24 is directly connected, Vlan1
C    192.168.2.0/24 is directly connected, Vlan2
C    192.168.3.0/24 is directly connected, Vlan3
C    192.168.10.0/24 is directly connected, FastEthernet0/23
S*   0.0.0.0/0 [1/0] via 192.168.10.1

步骤五:在路由器上配置到达三个VLAN网络的静路由

tarena-rouer(config)#ip route 192.168.1.0 255.255.255.0 192.168.10.2
tarena-rouer(config)#ip route 192.168.2.0 255.255.255.0 192.168.10.2
tarena-rouer(config)#ip route 192.168.3.0 255.255.255.0 192.168.10.2
tarena-rouer(config)#exit
tarena-rouer#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
S    192.168.1.0/24 [1/0] via 192.168.10.2
S    192.168.2.0/24 [1/0] via 192.168.10.2
S    192.168.3.0/24 [1/0] via 192.168.10.2
C    192.168.10.0/24 is directly connected, FastEthernet0/0
C    200.1.1.0/24 is directly connected, FastEthernet0/1
tarena-rouer#

步骤六:在Server上测试与三个VLAN的连通性

SERVER>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::2E0:8FFF:FE14:BB43
IP Address......................: 200.1.1.10
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 200.1.1.1
SERVER>ping 192.168.1.10
Pinging 192.168.1.10 with 32 bytes of data:
Request timed out.
Reply from 192.168.1.10: bytes=32 time=0ms TTL=126
Reply from 192.168.1.10: bytes=32 time=0ms TTL=126
Reply from 192.168.1.10: bytes=32 time=1ms TTL=126
Ping statistics for 192.168.1.10:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms
SERVER>ping 192.168.2.10
Pinging 192.168.2.10 with 32 bytes of data:
Reply from 192.168.2.10: bytes=32 time=0ms TTL=126
Reply from 192.168.2.10: bytes=32 time=0ms TTL=126
Reply from 192.168.2.10: bytes=32 time=0ms TTL=126
Reply from 192.168.2.10: bytes=32 time=0ms TTL=126
Ping statistics for 192.168.2.10:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
SERVER>ping 192.168.3.10
Pinging 192.168.3.10 with 32 bytes of data:
Reply from 192.168.3.10: bytes=32 time=1ms TTL=126
Reply from 192.168.3.10: bytes=32 time=0ms TTL=126
Reply from 192.168.3.10: bytes=32 time=0ms TTL=126
Reply from 192.168.3.10: bytes=32 time=0ms TTL=126
Ping statistics for 192.168.3.10:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms
SERVER>
网络路由表是路由器用于确定如何转发 IP 数据报的关键工具,包含了 IP 地址段和 OSPF 协议信息等内容。 ### IP 地址段信息 IP 地址段通常以“IP 地址/前缀长度”的形式表示,如 10.1.21.0/24。其中,IP 地址是网络中的唯一标识符,前缀长度则表示网络地址的位数。以 10.1.21.0/24 为例,24 表示前 24 位是网络地址,后 8 位是主机地址。这意味着该网络段包含从 10.1.21.0 到 10.1.21.255 的 256 个 IP 地址,其中 10.1.21.0 是网络地址,10.1.21.255 是广播地址,可分配给主机使用的 IP 地址范围是 10.1.21.1 - 10.1.21.254。 ### OSPF 协议信息 在网络路由表中,OSPF 协议信息主要包括区域号、路由类型等。区域号用于将自治系统划分为不同的区域,以减少路由信息的传播范围,提高网络的可扩展性和稳定性。区域号可以用点分十进制表示,如 0.0.0.0 表示骨干区域。 当路由表中存在多条相同网络地址的记录时,会根据最长匹配原则选择路由。也就是说,如果目标地址与多个路由条目匹配,会选择前缀长度最长的条目,因为它表示的网络范围更精确。 例如,在发送 IP 数据报时,路由器会先确定 IP 数据报首部中的目标地址,然后从路由控制表中查找与该地址具有相同网络地址的记录,根据该记录将 IP 数据报转发给相应的下一个路由器。如果存在多条匹配记录,就选择相同位数最多的网络地址进行转发 [^2]。 ### 路由配置示例 在使用 OSPF 协议时,需要在路由器上进行相应的配置。例如,要让处在 MGRE 环境的路由器连通,可以在不同路由器上进行如下配置: ```plaintext R3 上的配置 ospf 1 router-id 3.3.3.3 area 0.0.0.0 network 172.16.9.1 0.0.0.0 R5 上的配置 ospf 1 router-id 5.5.5.5 area 0.0.0.0 network 172.16.6.1 0.0.0.0 network 172.16.9.2 0.0.0.0 R6 上的配置 ospf 1 router-id 6.6.6.6 area 0.0.0.0 network 172.16.7.1 0.0.0.0 network 172.16.9.3 0.0.0.0 R7 上的配置 ospf 1 router-id 7.7.7.7 area 0.0.0.0 network 172.16.8.1 0.0.0.0 network 172.16.9.4 0.0.0.0 ``` 上述配置中,通过 `network` 命令宣告了各个路由器接口的 IP 地址,使其参与 OSPF 进程,从而实现网络的连通 [^3]。 ### 路由表中的特殊宣告 在 OSPF 配置中,还可以使用一些特殊的宣告方式。例如,`Network 0.0.0.0 0.0.0.0 area 0` 或 `Network 0.0.0.0 255.255.255.255 area 0` 表示让所有接口都启动 OSPF 进程 [^1]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值