bgp 使用route-map设置Local perference(本地优先属性)配置与详解

article/2025/10/23 10:26:09

实验目的:

 

1、掌握基于route-map的本地优先配置方法。

2、使用route-map配置可以定置基于目标网络的本地优先。

实验拓扑:

 接口IP配置及bgp基础配置详见

CSDNhttps://mp.csdn.net/mp_blog/creation/editor?spm=1001.2014.3001.5352

查看R3与R4的路由表:

R3#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 23.23.23.2, 01:58:36
//到达1.1.1.0/24网络的下一跳是23.23.23.22.0.0.0/24 is subnetted, 1 subnets
B       2.2.2.0 [20/0] via 23.23.23.2, 00:03:4223.0.0.0/24 is subnetted, 1 subnets
//到达2.2.2.0/24网络的下一跳是23.23.23.2
C       23.23.23.0 is directly connected, FastEthernet0/112.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 23.23.23.2, 01:58:3614.0.0.0/24 is subnetted, 1 subnets
B       14.14.14.0 [20/0] via 23.23.23.2, 00:00:27R4#sh ip route     Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 14.14.14.1, 00:00:06
//到达1.1.1.0/24网络的下一跳为14.14.14.12.0.0.0/24 is subnetted, 1 subnets
B       2.2.2.0 [20/0] via 14.14.14.1, 00:00:06
//到达2.2.2.0/24网络的下一跳为14.14.14.123.0.0.0/24 is subnetted, 1 subnets
B       23.23.23.0 [200/0] via 34.34.34.3, 00:00:0612.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 14.14.14.1, 00:00:0614.0.0.0/24 is subnetted, 1 subnets
C       14.14.14.0 is directly connected, FastEthernet0/1

对R3与R4的路由表进行分析结果如下:

R3 ————> R2————> 2.2.2.0/24

R3 ————> R2————> R1————> 2.2.2.0/24

R4 ————> R1————> 2.2.2.0/24

R4 ————> R1————> R2————> 2.2.2.0/24

通过上述分析及结合拓扑,可以得出R3到达1.1.1.0/24的网络最佳路由为:

R3 ————> R4 ————> R1————> 2.2.2.0/24

为了配置BGP协议能够为R3选择最佳路由到达2.2.2.0/24的网络,可以使用本地优先属性。但是如果仅仅简单的配置在R3的本地优先为100,R4的本地优先为200,那么又会产生另外一个问题,即R3如果需要到达2.2.2.0/24的网络,会选择如下路由:

R3 ————> R4————> R1————> R2 ————> 2.2.2.0/24

产生此问题的主要原因是:本地优先会影响数据流如何流出本地自治系统。

解决问题的方法是:使用基于route-map的策略配置,针对不同的目标进行路由调整。

首先查看R3和R4路由器的数据库:

R3#show ip bgp 
………………………………Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       14.14.14.1               0    100      0 12 i
*>                  23.23.23.2                             0 12 i
* i2.2.2.0/24       14.14.14.1               0    100      0 12 i
*>                  23.23.23.2               0             0 12 i
………………………………
*>                  0.0.0.0                  0         32768 i

​​​​​​​R3路由器的BGP协议没有选择14.14.14.0/24的原因是因为BGP的选路规则:EBGP对等体通告的路由优于IBGP对等体通告的路由。 

R4#show ip bgp 
…………………………Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       23.23.23.2               0    100      0 12 i
*>                  14.14.14.1               0             0 12 i
* i2.2.2.0/24       23.23.23.2               0    100      0 12 i
*>                  14.14.14.1                             0 12 i
…………………………

由于BGP的本地优先默认值为100,所以在R4上只需要将针对1.1.1.0/24网络路由的本地优先调整大于100即可,其配置如下:

R4(config)#access-list 1 permit 1.1.1.0 0.0.0.255
//使用ACL匹配需要修改本地优先的路由。
R4(config)#route-map set_lp permit 10
R4(config-route-map)#match ip address 1
//对ACL 1所指出的路由进行匹配
R4(config-route-map)#set local-preference 200
//对匹配ACL 1所指出的路由,修改其本地优先值为200
//此值将会影响本地自治系统的其它路由器,如何到达1.1.1.0/24的网络。
R4(config)#route-map set_lp permit 20
//配置空的路由图,保证其它路由均按默认方式进行通告。
R4(config)#router bgp 34
R4(config-router)#neighbor 14.14.14.1 route-map set_lp in  
//针对192.168.2.2的对等体发送的路由进行操作。其方向是in的方向。

在R4上查看BGP的数据库

R4#show ip bgp 
BGP table version is 1, local router ID is 34.34.34.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incompleteNetwork          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       23.23.23.2               0    100      0 12 i
*                   14.14.14.1               0    200      0 12 i
//R4上显示相应的路由的本地优先已经为200。
* i2.2.2.0/24       23.23.23.2               0    100      0 12 i
……………………

查看R3的BGP的数据库

R3#show ip bgp     
BGP table version is 23, local router ID is 34.34.34.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incompleteNetwork          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.0/24       14.14.14.1               0    200      0 12 i
*                   23.23.23.2                             0 12 i
//此时,在R3上查看到达目标网络的路由的本地优先为200,其下一跳为14.14.14.1
* i2.2.2.0/24       14.14.14.1               0    100      0 12 i
*>                  23.23.23.2               0             0 12 i
………………………………

为了确切的判断出R3到达1.1.1.0/24的网络路由,使用的是最佳路由,在R4路由器上配置下一跳属性:

R4(config)#router bgp 34
R4(config-router)#neighbor 34.34.34.3 next-hop-self 

查看R3和R4的路由表,可以看出本地优先仅仅影响了34自治系统的所有路由器如何到达1.1.1.0/24的网络,没有影响到其它的目标路由。

R3#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [200/0] via 34.34.34.4, 00:00:472.0.0.0/24 is subnetted, 1 subnets
B       2.2.2.0 [20/0] via 23.23.23.2, 00:28:0023.0.0.0/24 is subnetted, 1 subnets
C       23.23.23.0 is directly connected, FastEthernet0/112.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 23.23.23.2, 02:22:5414.0.0.0/24 is subnetted, 1 subnets
B       14.14.14.0 [200/0] via 34.34.34.4, 00:02:57
R4#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 14.14.14.1, 00:03:272.0.0.0/24 is subnetted, 1 subnets
B       2.2.2.0 [20/0] via 14.14.14.1, 00:03:2723.0.0.0/24 is subnetted, 1 subnets
B       23.23.23.0 [200/0] via 34.34.34.3, 00:03:2712.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 14.14.14.1, 00:03:2714.0.0.0/24 is subnetted, 1 subnets
C       14.14.14.0 is directly connected, FastEthernet0/1

使用tracert命令确认路由信息:

R3#traceroute 1.1.1.1Type escape sequence to abort.
Tracing the route to 1.1.1.11 34.34.34.4 4 msec 36 msec 24 msec2 14.14.14.1 24 msec 48 msec 48 msecR3#traceroute 2.2.2.2Type escape sequence to abort.
Tracing the route to 2.2.2.21 23.23.23.2 12 msec 12 msec 12 msec


http://chatgpt.dhexx.cn/article/vZKwFSxF.shtml

相关文章

使用route-map 配置BGP本地优先级

一、实验目的: 1、掌握基于route-map的本地优先配置方法。 2、使用route-map配置可以定置基于目标网络的本地优先级。 二、拓扑图: 三、配置BGP基本的配置: 1、配置各路由器的IP地址和BGP协议。配置完之后,查看一下R3和R4的路由表…

Cisco route-map 源地址路由配置

拓朴图: 案例: 公司内部使用的是一条拨号光纤和一条固定专线光纤,默认是指向拨号光纤出口那个网关出去,现在2网段有两台服务器(WEB、Mail)映射到公网,让外部来访问。 办公区因工作需要&#xf…

bgp route-map应用 配置 学习笔记

先全运行bgp R2 router bgp 2 no auto-summary no synchronzation bgp router-id 2.2.2.2 neighbor 12.1.1.1 remtotes as 10 neighbor 24.1.1.4 remote-as 10r1: router bgp 10 no auto-summary no synchronization bgp router-id 1.1.1.1 neighbor 12.1.1.2…

重分布和Route-MAP

一般在做重分布的时候用route-map较多,当然也可以用分发列表或者前缀列表等等,重分布的时候为了干掉不需要的路由,节约路由器CPU和转发效率可以使用route-map,当然route-map也可以用在其他的场景。 本次实验将ospf与rip重分布来使…

使用Route-Map过滤BGP的路由

实验目的 1、掌握使用Route-Map过滤BGP的路由。 实验拓扑 接口ip配置与bgp基础配置详见: CSDNhttps://mp.csdn.net/mp_blog/creation/editor/125210020查看R3的路由表: R3#show ip route Gateway of last resort is not set1.0.0.0/24 is subnetted…

基于Route-map的路由过滤配置详解

实验目的: 1、掌握基于Route-map的路由过滤配置方法。 2、掌握route-map的命令语法。 实验拓扑: 步骤1:接口ip配置路由协议基础配置重分发详见CSDNhttps://mp.csdn.net/mp_blog/creation/editor/125018583查看R1、R3路由表 R1#show ip route Gateway …

带你轻轻松松了解route-map

一、Route-map概述 1.技术背景 首先来初步认识一下route-map。看上图,我们在R2上,将OSPF路由重发布进RIP,前面已经说过了,在重发布时,可以使用metric关键字来设置路由被重发布进RIP后的metric,这里设置为…

Route-Map个人理解及实验解析

Route-Map:功能性非常强的策略列表,可以用来过滤路由也可以调整路由的属性,自身具备过滤功能。 Route-Map的作用: 1.在重发布的过程中做route-map,重发布过程中可以改变路由的属性;(次要作用) 2.PBR 策略路…

Route map应用策略路由(上)

一、拓扑图: 二、配置说明: 1、根据拓扑图的配置,R4上面跑OSPF,下面走静态路由,R5和R6走默认路由上去。但是要注意的一点是R4上要加一条命令:default-information originate always (向OSPF区域通知一条默认…

CISCO ROUTE-MAP

强制指定源地址的下一跳 match定义匹配条件 match ip address匹配访问列表或前缀列表 match interface匹配下一跳出接口为指定接口之一的路由 match ip next-hop匹配下一跳地址为特定访问列表中被允许的那些路由 match metric匹配具有指定度量值的路由 match route-type匹…

Route-map扩展(讲解+配置)

目录 ——Route-map扩展一般形式: ——案列(1): ——案列(2): ——Route-map扩展一般形式: Ip policy-list aaa per/denyMatch …………(前缀列表/ACL....&#xff…

路由策略route-map

路由策略 route-map 定义 route-map,路由图,用于实现路由策略。 功能 部署 route-map NM permit 10 match ip address 1 2 match ip address 1 match ip address 2 match interface f0/0 f1/0 route-map NM deny 20 match ip address 2 set weight …

route-map的使用介绍

一、关于route-map route map可用于路由的再发布和策略路由,还经常使用在BGP中。策略路由实际上是复杂的静态路由,静态路由是基于数据包的目标地址并转发到指定的下一跳路由器,策略路由还利用和扩展IP ACL链接,以便提供更多功能的…

011mmap进程通信

LINUX学习笔记 mmap 进程通信1. mmap 函数声明及头文件包含1.1 参数说明1.2 mmap 通信demo 2. mmap 注意事项:2.1 mmap 函数的保险使用方法: 3. demo 父子进程间mmap通信4. demo 非血缘关系进程间mmap通信5. mmap通信与fifo和文件通信的差异6. 匿名映射(…

Linux mmap内存映射

一、什么是mmap mmap是一种内存映射文件的方法,即将一个文件或者其它对象映射到进程的地址空间,实现文件磁盘地址和进程虚拟地址空间中一段虚拟地址的一一对映关系,函数原型如下 void *mmap(void *addr, size_t length, int prot, int flags,…

Linux下mmap

目录 一.mmap简介 二.为什么需要使用mmap 三.mmap的使用 四.mmap原理 一.mmap简介 什么是mmap了?从名字上来看是memory map也就是地址映射,是一种内存映射文件的方法。mmap是一个可以将一个文件或者其它对象映射到进程的地址空间实现磁盘的地址和进程虚…

Android 进程间通信机制(二) mmap 原理

一. 前言 Binder中一次拷贝的实现就是利用mmap(memory mapping)内存映射机制,我们来看看它的工作原理. 二. 参考文章 下面这几篇文章建议先好好阅读一下,都是总结的很好的文章, 每个人理解可能不一样 笔者也是看了好多博客文章和B站视频讲解, 然后加上自己的理解后 输出的一…

Linux mmap讲解

0 引言 Linux 提供了非常强大的 mmap(2) 系统调用; 它使开发人员能够将任何内容直接映射到进程虚拟地址空间 (VAS)。 此内容包括文件数据、硬件设备(适配器)内存区域,或只是通用内存区域。 在本文中,我们将只关注使用…

mmap内存映射

内存映射通信 一、mmap (memory_map) 1.1 简介 存储映射I/O (Memory-mapped I/O) 使一个磁盘文件与存储空间中的一个缓冲区相映射。于是当从缓冲区中取数据,就相当于读文件中的相应字节。于此类似,将数据存入缓冲区,则相应的字节就自动写入…