400-035-6699
当前位置: 首页 » 技术支持 » 博文资讯 »

BGP路由策略实战:深入讲解过滤、路由引入及缺省路由配置技巧

BGP(边界网关协议)是一种用于互联网中的外部网关协议,它用于自治系统之间的路由选择。BGP通过传递可达性和路由信息来建立和维护互联网的路由表。在处理大量数据时,为了维护网络的安全和稳定,我们通常需要对BGP路由进行过滤。本文将介绍几种常见的BGP路由过滤方法,并解释如何配置这些过滤规则。
首先,我们来看看BGP路由过滤的几种常见方法:
1. **基于AS-Path的路由过滤**:AS-Path是BGP路由信息中的一个属性,它记录了路由从源点到目的地的路径。通过配置正则表达式,我们可以过滤掉不符合特定AS-Path模式的路由。例如,我们可以让某个路由器只接收来自特定自治系统的路由。
2. **基于Community属性的路由过滤**:Community是一个扩展的BGP属性,它允许路由器之间传递额外的信息。通过设置Community属性,我们可以控制路由的传播。例如,我们可以设置一个Community属性,指示某个路由器不将其路由信息传播到其他自治系统。
3. **基于Next Hop属性的路由过滤**:Next Hop是BGP路由信息中的一个属性,它指示了到达目的地的下一跳路由器。通过配置规则,我们可以过滤掉下一跳地址不符合特定条件的路由。例如,我们可以让某个路由器不接收下一跳地址为特定ip地址的路由。
下面,我们将以一个具体的例子来演示如何配置BGP路由过滤规则。
假设我们有一个网络,包含6台路由器(R1-R6),它们之间通过BGP协议交换路由信息。我们希望实现以下路由过滤目标:
1. 让R3只接收来自AS 100的路由。 2. 让R4环回接口4.4.4.4的路由只发送给R1和R2,其他路由器都收不到。 3. 让R6不接收R5发过来的路由条目。
为了实现这些目标,我们需要对路由器进行如下配置:
1. 在R3上配置AS-Path过滤规则,使其只接收来自AS 100的路由。 2. 在R4上配置Community过滤规则,使其只将环回接口4.4.4.4的路由发送给R1和R2。 3. 在R2上配置Next Hop过滤规则,使其不接收下一跳地址为R5的路由。
配置完成后,我们可以通过查看路由表来验证路由过滤的效果。
总结起来,BGP路由过滤是网络管理和维护中非常重要的一环。通过合理配置BGP路由过滤规则,我们可以有效地控制路由信息的传播,确保网络的安全和稳定。

BGP 路由过滤

BGP路由策略实战:深入讲解过滤、路由引入及缺省路由配置技巧

006fece2-e856-11ee-a297-92fbcf53809c.png

 

R1:
bgp 100
roruter-id 1.1.1.1
peer 192.168.13.3 as-n 200
peer 192.168.14.4 as-n 300
peer 192.168.12.2 as-n 100
peer 192.168.12.2 next-hop-local
net 1.1.1.0 24

R2:
bgp 100
router-id 2.2.2.2
peer 192.168.25.5 as-n 400
peer 192.168.26.6 as-n 500
peer 192.168.12.1 as-n 100
peer 192.168.12.1 next-hop-local
net 2.2.2.0 24

R3:
bgp 200
router-id 3.3.3.3
peer 192.168.13.1 as-n 100
net 3.3.3.0 24

R4:
bgp 300
router-id 4.4.4.4
peer 192.168.14.1 as-n 100
net 4.4.4.0 24

R5:
bgp 400
router-id 5.5.5.5
peer 192.168.25.2 as-n 100
net 5.5.5.0 24

R6:
bgp 500
router-id 6.6.6.6
peer 192.168.26.2 as-n 100
net 6.6.6.0 24

 

 

没做过滤前,dis bgp routing-table

0087b7aa-e856-11ee-a297-92fbcf53809c.png

第一个用 AS-Path进行路由过滤
利用 AS-Path 进行路由过滤
让R3只接收来自AS 100的
做正则表达式

R3:
ip as-path-filter 1 permit 100$ 匹配始发AS 100
bgp 200
peer 192.168.13.1 as-path-filter 1 import
做完过滤后再R3上, dis bgp routing-table

00b52b04-e856-11ee-a297-92fbcf53809c.png

正则表达式

00cd7fc4-e856-11ee-a297-92fbcf53809c.png


第二个用 Community 属性进行路由过滤
R4环回接口 4.4.4.4 只发给R1和R2,其他都收不到。community no-export

没做过滤前,先在R6查看 bgp路由表,有4.4.4.4

00f050b2-e856-11ee-a297-92fbcf53809c.png

R1:
[R1]bgp 100
peer 192.168.12.2 advertise-community

R4:
[R4]route-policy 10 permit node 1 不写if-match,默认是所有
apply community no-export

[R4]bgp 300
peer 192.168.14.1 route-policy 10 export
peer 192.168.14.1 advertise-community 为了让这个属性值能被识别到

R1上dis bgp communtiy

00f4bd82-e856-11ee-a297-92fbcf53809c.png

R6查看 dis bgp routing-table

01057f3c-e856-11ee-a297-92fbcf53809c.png


第三个用 Next Hop 属性进行路由过滤
R6不接收R5发过来的路由条目

没过滤前,在R6 dis bgp routing-table

0115a8f8-e856-11ee-a297-92fbcf53809c.png

R2在发给R6的时候,把下一跳是R5的地址,做拒绝后 发送给R6
R2收到5.5.5.5的路由条目,然后发送给R6。如果想拒绝就要在R2上匹配到5.5.5.5,即下一跳是 192.168.25.5

01306378-e856-11ee-a297-92fbcf53809c.png

R2:
ip ip-prefix 1 permit 192.168.25.5 32
route-policy 10 deny node 1
if-match ip next-hop ip-prefix 1
route-policy 10 permit node 2
bgp 100
peer 192.168.26.6 route-policy 10 export

配置完成后,在R6上查看,等一会 或者直接 [R6]refresh bgp all import

0148a46a-e856-11ee-a297-92fbcf53809c.png

BGP 路由引入

在多协议混合的网络环境中,不同的路由协议使用的协议报文各不相同,就好比说着不同的语言。如果一种路由协议需要从别的路由协议那里获取路由信息,则可以使用路由引入技术。

0161f186-e856-11ee-a297-92fbcf53809c.png

希望1.1.1.1能和5.5.5.5互通
R2和R4间采用静态路由
[R2]ip route-static 192.168.34.0 24 192.168.23.3
[R4]ip route-static 192.168.23.0 24 192.168.34.3

建立BGP邻居
[R2]bgp 100
router-id 2.2.2.2
peer 192.168.23.3 as-n 100
peer 192.168.34.4 as-n 100

[R3]bgp 100
router-id 3.3.3.3
peer 192.168.23.2 as-n 100
peer 192.168.34.4 as-n 100

[R4]bgp 100
router-id 4.4.4.4
peer 192.168.34.3 as-n 100
peer 192.168.23.2 as-n 100

R2和R1运行的是RIP
[R2]rip
version 2
net 192.168.12.0

[R1]rip
version 2
net 192.168.12.0
net 1.0.0.0

R4和R5运行的是OSPF
[R4]OSPF router-id 4.4.4.4
area 0
net 192.168.45.4 0.0.0.0

[R5]ospf router-id 5.5.5.5
area 0
net 192.168.45.5 0.0.0.0
net 5.5.5.5 0.0.0.0

为了能互通,rip引入bgp,ospf引入bgp,在bgp的路由上做
[R2]bgp 100
import-route rip 1

[R3]bgp 100
import-route ospf 1

0165ee44-e856-11ee-a297-92fbcf53809c.png

会发现除了1.1.1.1和5.5.5.5需要的外, 12和45网段的也引进来了
如果想精确引入呢?
[R2]acl 2000
rule permit source 1.1.1.0 0.0.0.255
route-policy 10 permit node 10
if-match acl 2000
[R2]bgp 100
import-route rip 1 route-policy 10

[R4]ip ip-prefix 10 permit 5.5.5.5 32
route-policy 10 permit node 1
if-match ip-prefix 10
[R4]bgp 100
import-route ospf 1 route-policy 10

[R3]dis brp routing-table

0179a3bc-e856-11ee-a297-92fbcf53809c.png

这样做好之后,R1并不能ping通R5
因为R1没有R5的路由,只做了单向引入, bgp不适合引入到rip,可以通过下放默认路由。bgp的路由条目要下放默认路由
[R2]rip
default-route origiNATe

[R4]ospf
default-route-advertise always
因为R4没有一个缺省路由,只能采用强制下放

BGP 缺省路由

019ae50e-e856-11ee-a297-92fbcf53809c.png

这个环境是直接用物理接口建立IBGP邻居。主要是为了说缺省路由有这么几种方式
R1
bgp 100
peer 192.168.12.2 as-n 100
peer 192.168.13.3 as-n 100
peer 192.168.14.4 as-n 100
net 1.1.1.0 255.255.255.0

R2
bgp 100
router-id 2.2.2.2
peer 192.168.12.1 as-n 100
peer 192.168.12.1 next-hop-local
peer 192.168.25.5 as-n 200

R3
bgp 100
router-id 3.3.3.3
peer 192.168.13.1 as-n 100
peer 192.168.13.1 next-hop-local
peer 192.168.35.5 as-n 200

R4
bgp 100
router-id 4.4.4.4
peer 192.168.14.1 as-n 100
peer 192.168.14.1 next-hop-local
peer 192.168.45.5 as-n 200

R5
bgp 200
router-id 5.5.5.5
peer 192.168.25.2 as-n 100
peer 192.168.35.3 as-n 100
peer 192.168.45.4 as-n 100
net 5.5.5.0 255.255.255.0

让R1收不到R5的环回口。为了验证缺省路由

01d2aaf2-e856-11ee-a297-92fbcf53809c.png

这个配置就是告诉R2R3R4,你们不要把我5.5.5.5的条目告诉其他设备。

第一种方式(比较好)
[R4]bgp 100
[R4-bgp]peer 192.168.14.1 default-route-advertise
发一条缺省路由给R1

第二种方式
[R3]ip route-static 0.0.0.0 0 NULL 0
[R3]bgp 100
net 0.0.0.0 0 要宣告前必须存在路由条目
就可以下放到整个AS

第三种方式
[R1]ip route-static 0.0.0.0 0 192.168.12.2

最后在R1上dis ip routing-table

审核编辑:黄飞

 

【限时免费】一键获取网络规划系统模板+传输架构设计+连通性评估方案

相关文章

服务电话:
400-035-6699
企服商城