实例1:ospf多区域建立邻居+路由引入
LSA(链路状态通告)是用于在路由器之间交换链路状态信息的消息。这些LSA帮助路由器了解网络拓扑,从而计算出到达目标网络的最短路径。在OSPF中,存在多种类型的LSA,每种类型都有其特定的用途。以下是OSPF中的五类LSA的简要介绍:
Router LSA(类型1):
由每个OSPF路由器产生发送。主要描述该路由器的链路状态信息,包括所连接的网络、链路的类型、链路的带宽和延迟等。
Network LSA(类型2):由DR(指定路由器)产生发送,主要描述广播或NBMA网络中的链路状态。
Summary LSA(类型3):由ABR(区域边界路由器)产生并发送,主要描述不同区域之间的路由表信息交换。
ASBR-Summary LSA(类型4):由ASBR(自治系统边界路由器)产生,用于描述AS(自治系统)之间的网络。
External LSA(类型5):当路由器引入外部路由到OSPF中时,会生成External LSA。用于描述AS外部的路由信息。这些LSA包含了到达AS外部目的地的路由信息
设备配置:
------------------------AR1配置(area0内部路由)---------------------
sys
sysname R1
interface GigabitEthernet0/0/1
ip address 192.168.1.1 255.255.255.0
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 192.168.2.0 0.0.0.255
------------------------AR2配置(ABR区域边界路由:area0+area1的区域边界路由)---------------
sys
sysname R2
interface GigabitEthernet0/0/0
ip address 192.168.1.2 255.255.255.0
interface GigabitEthernet0/0/1
ip address 192.168.2.1 255.255.255.0
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 192.168.1.0 0.0.0.255
area 0.0.0.1
network 192.168.2.0 0.0.0.255
------------------------AR3配置(ASBR域外边界路由:area1+直连的域外边界路由)---------------
sys
sysname R3
interface GigabitEthernet0/0/0
ip address 192.168.2.2 255.255.255.0
interface GigabitEthernet0/0/1
ip address 192.168.3.1 255.255.255.0
ospf 1 router-id 3.3.3.3
import-route direct //在ospf里 引入直连路由
area 0.0.0.1
network 192.168.2.0 0.0.0.255
查看ospf引入状态:
<R1>dis ospf lsdb
OSPF Process 10 with Router ID 1.1.1.1
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router(1类LSA) 2.2.2.2 2.2.2.2 273 36 80000007 1
Router(1类LSA) 1.1.1.1 1.1.1.1 275 36 80000004 1
Network(2类LSA) 192.168.1.2 2.2.2.2 273 32 80000003 0
Sum-Net(3类LSA) 192.168.2.0 2.2.2.2 549 28 80000002 1
Sum-Asbr(4类LSA) 3.3.3.3 2.2.2.2 1310 28 80000001 1
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External(5类LSA) 192.168.2.0 3.3.3.3 1311 36 80000001 1
External(5类LSA) 192.168.3.0 3.3.3.3 1311 36 80000001 1
实例2:IS-IS多级别配置
1. 工作原理
IS-IS协议基于链路状态路由算法,每个路由器会收集其直接相连链路的状态信息,并构建链路状态数据库(LSP,Link State Packet)。这些信息随后在整个IS-IS域内泛洪,使得每个路由器都能了解整个网络的拓扑结构。基于这些信息,每个路由器使用SPF(Shortest Path First)算法计算出到达每个目的地的最短路径。2. 系统ID和网络实体标题
系统ID:用于唯一标识网络中的每个路由器。
网络实体标题(NET):由区域地址和系统ID组成,用于在整个IS-IS域中唯一标识路由器。
3. 区域和等级
IS-IS支持分层的路由设计,包括L1(区域内部)和L2(区域间)两个等级。L1:负责在单个区域内计算路由。
L2:负责在不同区域间计算路由。
路由器可以配置为L1/L2路由器(同时参与L1和L2路由计算),或仅作为L1或L2路由器。备注:L1建立领居必须区域ID一致,L2不需要区域ID一致。
设备配置:
---------------------- R2配置为L1-L2级别(相当于OSPF的ABR边界路由) ------------------
#
sysname R2
#
isis 1 // 创建isis进程
network-entity 4901.0000.0000.0002.00 //配置ID:4091=区域ID,0.0.0002=设备ID(RrouteID)
#
interface GigabitEthernet0/0/0
ip address 192.168.1.2 255.255.255.0
isis enable 1 //接口加入isis进程1
isis circuit-level level-1 //接口配置为L1级别(相当于加入ospf区域1)
#
interface GigabitEthernet0/0/1
ip address 192.168.2.1 255.255.255.0
isis enable 1 //接口加入isis进程1
isis circuit-level level-2 //接口配置为L2级别(相当于加入ospf区域2)
#
interface LoopBack1
ip address 20.0.0.1 255.255.255.0
isis enable 1
---------------------- R1配置为L1级别(相当于加入ospf区域1) ------------------------
#
sysname R1
#
isis 1
is-level level-1
network-entity 4901.0000.0000.0001.00
#
interface GigabitEthernet0/0/0
ip address 192.168.1.1 255.255.255.0
isis enable 1
#
interface LoopBack1
ip address 10.0.0.1 255.255.255.255
isis enable 1
---------------------- R3配置为L2级别(相当于加入ospf区域2) ------------------------
#
sysname R3
#
isis 1
is-level level-2
network-entity 4902.0000.0000.0003.00
#
interface GigabitEthernet0/0/0
ip address 192.168.2.2 255.255.255.0
isis enable 1
#
interface LoopBack1
ip address 30.0.0.1 255.255.255.255
isis enable 1
实例3:ospf+isis双点双向路由引入
在双点双向路由引入中,关键在于实现两个路由协议的路由信息的相互引入,以实现互通和冗余效果。这可以提高网络的可靠性和稳定性,因为在网络出现故障时,可以通过另一个路由协议提供的路由信息进行通信。然而,这种技术也可能引发一些问题,如次优路径和路由环路等。
次优路径问题:主要是由于不同路由协议的优先级不同而产生的。当低优先级的路由被引入到高优先级的路由中时,就可能产生次优路径。为了避免这种情况,需要仔细考虑路由协议的优先级设置,并在引入路由时进行必要的调整。
路由环路问题:则是由于路由信息的错误引入或更新不及时导致的。为了解决这个问题,需要采用一些防环机制,如水平分割、毒性逆转等,来避免路由环路的产生。
解决方法:主要使用不同的协议路由添加tag标记,通过边界路由 使用路由策略 添加和剥离tag标记,解决环路和次优问题。
设备配置:
---------------------- R1配置(isis路由) ----------------------
#
sysname R1
#
isis 15
is-level level-2
network-entity 4901.1111.1111.1111.00
import-route direct
#
interface GigabitEthernet0/0/0
ip address 192.168.13.1 255.255.255.0
isis enable 15
#
interface GigabitEthernet0/0/1
ip address 192.168.14.1 255.255.255.0
isis enable 15
#
interface LoopBack1
ip address 10.0.0.1 255.255.255.0
isis enable 15
---------------------- R2配置(ospf路由) ----------------------
#
sysname R2
#
interface GigabitEthernet0/0/0
ip address 192.168.23.1 255.255.255.0
ospf enable 10 area 0.0.0.0
#
interface GigabitEthernet0/0/1
ip address 192.168.24.1 255.255.255.0
ospf enable 10 area 0.0.0.0
#
interface LoopBack1
ip address 20.0.0.1 255.255.255.0
#
ospf 10 router-id 2.2.2.2
import-route direct
area 0.0.0.0
---------------------- R3配置(协议边界路由) ----------------------
#
sysname R3
#
isis 15
network-entity 4901.3333.3333.3333.00
import-route ospf 10 route-policy o2i
#
interface GigabitEthernet0/0/0
ip address 192.168.13.2 255.255.255.0
isis enable 15
#
interface GigabitEthernet0/0/1
ip address 192.168.23.2 255.255.255.0
ospf enable 10 area 0.0.0.0
#
ospf 10 router-id 3.3.3.3
import-route isis 15 route-policy i2o
area 0.0.0.0
#
route-policy o2i deny node 10
if-match tag 123
#
route-policy o2i permit node 20
apply tag 456
#
route-policy i2o deny node 10
if-match tag 456
#
route-policy i2o permit node 20
apply tag 123
---------------------- R4配置(协议边界路由) ----------------------
#
sysname R4
#
isis 15
network-entity 4901.4444.4444.4444.00
import-route ospf 10 route-policy o2i
#
interface GigabitEthernet0/0/0
ip address 192.168.14.2 255.255.255.0
isis enable 15
#
interface GigabitEthernet0/0/1
ip address 192.168.24.2 255.255.255.0
ospf enable 10 area 0.0.0.0
#
ospf 10 router-id 4.4.4.4
import-route isis 15 route-policy i2o
area 0.0.0.0
#
route-policy o2i deny node 10
if-match tag 123
#
route-policy o2i permit node 20
apply tag 456
#
route-policy i2o deny node 10
if-match tag 456
#
route-policy i2o permit node 20
apply tag 123
实例4:IBGP+EBGP建立邻居
BGP协议的工作原理涉及多个步骤,包括:
- 邻居建立:相邻的路由器通过建立BGP邻居关系来交换路由信息。这些邻居可以是物理连接的路由器,也可以是通过TCP/IP网络互连的路由器。每个路由器将自己的路由表中的前缀通过UPDATE消息发送给邻居。
- 路由选择:当一个路由器收到UPDATE消息后,它会根据一定的规则进行路由选择。BGP使用路径向量算法来确定最佳的路由路径,考虑因素包括路径的长度、AS路径、NEXT_HOP等。
- 路由通告:一旦确定了最佳的路由路径,路由器将该路径添加到自己的路由表中,并向相邻的路由器通告这个路由。通告可以通过UPDATE消息的WITHDRAW部分来撤销。
- 路由保持:BGP使用KEEPALIVE消息来保持邻居之间的连接。
设备配置:
---------------------- R4配置(IBGP路由) ----------------------
# 说明:使用回环口建立邻居 需要 指定源IP,不指定的话默认发包地址为接口IP(物理口)
#
sysname R4
#
interface GigabitEthernet0/0/0
ip address 14.0.0.2 24
#
interface LoopBack1
ip address 4.4.4.4 32
#
bgp 100
router-id 4.4.4.4
peer 1.1.1.1 as-number 100 // 建立邻居1 并 指定as号
peer 1.1.1.1 connect-interface LoopBack1 // 指定回环口为 源IP(发包IP)
peer 2.2.2.2 as-number 100 // 建立邻居2 并 指定as号
peer 2.2.2.2 connect-interface LoopBack1 // 指定回环口为 源IP(发包IP)
#
ospf 1 // 使用IGP协议 在 IBGP区域内路由互通
#
ospf 10 router-id 4.4.4.4
area 0
network 0.0.0.0 0.0.0.0
---------------------- R1配置(IBGP路由) ----------------------
#
sysname R1
#
interface GigabitEthernet0/0/0
ip address 12.0.0.1 24
#
interface GigabitEthernet0/0/1
ip address 14.0.0.1 24
#
interface LoopBack1
ip address 1.1.1.1 32
#
bgp 100
router-id 1.1.1.1
peer 2.2.2.2 as-number 100
peer 2.2.2.2 connect-interface LoopBack1
peer 4.4.4.4 as-number 100
peer 4.4.4.4 connect-interface LoopBack1
#
ospf 10 router-id 1.1.1.1
area 0
network 0.0.0.0 0.0.0.0
---------------------- R2配置(IBGP边界路由) ----------------------
# 说明:EBGP会更新源IP(下一跳),IBGP不会更新源IP(学习到的路由不可达),所以IBGP需要配置更新源IP
#
sysname R2
#
interface GigabitEthernet0/0/0
ip address 12.0.0.2 24
#
interface GigabitEthernet0/0/1
ip address 23.0.0.1 24
#
interface LoopBack1
ip address 2.2.2.2 32
#
bgp 100
router-id 2.2.2.2
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack1 // 指定发包IP为回环口
peer 1.1.1.1 next-hop-local // 更新源IP下一跳
peer 4.4.4.4 as-number 100
peer 4.4.4.4 connect-interface LoopBack1
peer 4.4.4.4 next-hop-local
peer 3.3.3.3 as-number 200 // EBGP建立邻居一般用直连,这里使用回环+直连双向建立
peer 3.3.3.3 ebgp-max-hop 255 // EBGP使用回环建立邻居 需要TTL一致
peer 3.3.3.3 connect-interface LoopBack1
peer 23.0.0.2 as-number 200 // EBGP使用直连建立邻居
#
ospf 10 router-id 2.2.2.2
area 0
network 0.0.0.0 0.0.0.0
#
ip route-static 3.3.3.3 32 23.0.0.2 // 静态路由(EBGP回程路由)
---------------------- R3配置(EBGP路由) ----------------------
#
sysname R3
#
interface GigabitEthernet0/0/0
ip address 23.0.0.2 24
#
interface LoopBack1
ip address 3.3.3.3 24
#
interface LoopBack2
ip address 33.33.33.33 32
#
bgp 200
router-id 3.3.3.3
peer 2.2.2.2 as-number 100 // 回环建立邻居
peer 2.2.2.2 ebgp-max-hop 255 // EBGP需要TTL一致
peer 2.2.2.2 connect-interface LoopBack1 // 指定发包IP为回环口
peer 23.0.0.1 as-number 100 // 直连建立邻居
network 33.33.33.33 32 // 精确宣告
ip route-static 2.2.2.2 32 23.0.0.1 // 静态路由(EBGP回程路由)
查看BGP的邻居状态:
[R2]dis bgp peer
BGP local router ID : 2.2.2.2
Local AS number : 100
Total number of peers : 4 Peers in established state : 4
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
1.1.1.1 4 100 1120 1124 0 18:37:52 Established
1
3.3.3.3 4 200 1118 1119 0 18:30:08 Established
1
4.4.4.4 4 100 1116 1121 0 18:34:40 Established
0
23.0.0.2 4 200 2908 2910 0 0048h20m Established
1
查看BGP的路由表:
[R2]dis bgp routing-table
BGP Local router ID is 2.2.2.2
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
i 1.1.1.1/32 1.1.1.1 0 100 0 i
*> 33.33.33.33/32 3.3.3.3 0 0 200i
* 23.0.0.2 0 0 200i
# 33有两个下一跳因为使用了直连加回环双向通道
BGP 路由聚合:
[R4-bgp]aggregate 172.16.0.0 22 detail-suppressed
aggregate:聚合
detail-suppressed:抑制明细路由
聚合了以下地址:
172.16.0.0
172.16.1.0
172.16.2.0
172.16.3.0
BGP反射器:
// 在IBGP里面,接收到的EBGP路由 只会传一跳,这样其他IBGP路由器就会收不到,
// 这就需要接收到路由的IBGP边界路由器去传播路由给其他IBGP路由器,
// 传播端为反射器服务器,被传播端被称为为客户端,
// 客户端和服务端可以有多个
# 指定1.1为客户段,本机为反射器
peer 1.1.1.1 reflect-client
实例5:MPLS静态LSP
设备配置:
---------------------- R1配置 ----------------------
#
sysname R1
#
mpls lsr-id 1.1.1.1 // 创建mpls
mpls // 开启mpls功能
#
interface GigabitEthernet0/0/1
ip address 11.0.0.1 255.255.255.0
mpls // 接口开启mpls
#
interface LoopBack1 // 创建回环口 用来充当pc端测试
ip address 1.1.1.1 255.255.255.255
#
ospf 1 // 使用IGP协议使区域路由互通
area 0.0.0.0
network 0.0.0.0 255.255.255.255
# // 双向隧道建立
static-lsp ingress 1-3 destination 3.3.3.3 32 nexthop 11.0.0.2 out-label 100
static-lsp egress 3-1 incoming-interface GigabitEthernet0/0/1 in-label 200
---------------------- R2配置 ----------------------
#
sysname R2
#
mpls lsr-id 2.2.2.2
mpls
#
interface GigabitEthernet0/0/0
ip address 11.0.0.2 255.255.255.0
mpls
#
interface GigabitEthernet0/0/1
ip address 12.0.0.1 255.255.255.0
mpls
#
interface LoopBack1
ip address 2.2.2.2 255.255.255.255
#
ospf 1
area 0.0.0.0
network 0.0.0.0 255.255.255.255
#
static-lsp transit 1-3 incoming-interface GigabitEthernet0/0/0 in-label 100 next hop 12.0.0.2 out-label 200
static-lsp transit 3-1 incoming-interface GigabitEthernet0/0/1 in-label 200 next hop 11.0.0.1 out-label 100
---------------------- R3配置 ----------------------
#
sysname R3
#
#
mpls lsr-id 3.3.3.3
mpls
#
interface GigabitEthernet0/0/0
ip address 12.0.0.2 255.255.255.0
mpls
#
interface LoopBack1
ip address 3.3.3.3 255.255.255.255
#
ospf 1
area 0.0.0.0
network 0.0.0.0 255.255.255.255
#
static-lsp egress 1-3 incoming-interface GigabitEthernet0/0/0 in-label 200
static-lsp ingress 3-1 destination 1.1.1.1 32 nexthop 12.0.0.1 out-label 200
验证配置:
#
dis fib //查看FIB表(转发信息表)
#
dis mpls lsp //查看LFIB表(标签转发信息表)
#
dis mpls lsp verbose //查看详细FFIB表
#
tracert lsp ip 192.168.6.0 24
#
tracert -v 192.168.6.100
#
ping lsp ip 192.168.6.0 2
实例6:MPLS动态LDP
设备配置:
#
sysname R1
#
mpls lsr-id 1.1.1.1 // 创建mpls
mpls // 全局开启mpls功能
#
mpls ldp // 全局开启mpls ldp功能
#
interface GigabitEthernet0/0/0
ip address 12.0.0.1 255.255.255.0
mpls // 接口开启mpls功能
mpls ldp // 接口开启mpls ldp功能
#
interface LoopBack1 // 创建回环地址 作为mpls ID
ip address 1.1.1.1 255.255.255.255
#
ospf 1 router-id 1.1.1.1 // 创建ospf 使区域路由互通
area 0.0.0.0 // 懒人配置,直接宣告所有地址
network 0.0.0.0 255.255.255.255
---------------------- R2配置 ----------------------
#
sysname R2
#
mpls lsr-id 2.2.2.2
mpls
#
mpls ldp
#
interface GigabitEthernet0/0/0
ip address 12.0.0.2 255.255.255.0
mpls
mpls ldp
#
interface GigabitEthernet0/0/1
ip address 23.0.0.1 255.255.255.0
mpls
mpls ldp
#
interface LoopBack1
ip address 2.2.2.2 255.255.255.255
#
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 0.0.0.0 255.255.255.255
---------------------- R3配置 ----------------------
#
sysname R3
#
mpls lsr-id 3.3.3.3
mpls
#
mpls ldp
#
interface GigabitEthernet0/0/0
ip address 23.0.0.2 255.255.255.0
mpls
mpls ldp
#
interface GigabitEthernet0/0/1
ip address 34.0.0.1 255.255.255.0
mpls
mpls ldp
#
interface LoopBack1
ip address 3.3.3.3 255.255.255.255
#
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 0.0.0.0 255.255.255.255
---------------------- R4配置----------------------
#
sysname R4
#
mpls lsr-id 4.4.4.4
mpls
#
mpls ldp
#
interface GigabitEthernet0/0/0
ip address 34.0.0.2 255.255.255.0
mpls
mpls ldp
#
interface GigabitEthernet0/0/1
#
interface LoopBack1
ip address 4.4.4.4 255.255.255.255
#
ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 0.0.0.0 255.255.255.255
验证配置:
#
dis fib //查看FIB表(转发信息表)
#
dis mpls lsp //查看LFIB表(标签转发信息表)
#
dis mpls lsp verbose //查看详细FFIB表
#
tracert lsp ip 192.168.6.0 24
#
tracert -v 192.168.6.100
#
ping lsp ip 192.168.6.0 2