BGP+路由注入

三、BGP  边界网关路由协议

1,概述:

为方便管理规模不断扩大的网络,网络被分成了不同的AS(Autonomous System,自治系统)。早期,EGP(Exterior Gateway Protocol,外部网关协议)被用于实现在AS之间动态交换路由信息。但是EGP设计得比较简单,只发布网络可达的路由信息,而不对路由信息进行优选,同时也没有考虑环路避免等问题,很快就无法满足网络管理的要求。
BGP是为取代最初的EGP而设计的另一种外部网关协议。不同于最初的EGP,BGP能够进行路由优选、避免路由环路、更高效率的传递路由和维护大量的路由信息。

BGP   基于  TCP 协议的 目标端口  179  —跨设备建立邻居关系

运行BGP 协议的路由器  成为   BGP发言者   

运行BGP 的路由器建立的邻居互称为对等体 peer

bgp  承载大规模的 路由信息  ,并且可以使用路由策略 和丰富的路由属性 实现选路

BGP 这个协议运行在不同的AS之间的协议    ,不同的AS 使用AS号 来区分

AS  自治系统

表示:  采用2字节       私有AS:    64511-65534

09之后    4字节       私有AS:  4200000000 -4294967294

邻居关系类型:

相同AS内 BGP建立的邻居关系 称为  IBGP邻居关系  -一般使用逻辑接口

不同AS之间 BGP 建立的邻居关系 称为 EBGP邻居关系—一般使用物理接口

2,邻居关系基本配置

拓扑:

配置思路:

1,配置基本IP地址信息

2,配置IGP=OSPF ,不宣告外网段

3,配置BGP邻居关系

-EBGP

-IBGP

4, 验证

配置命令:

配置EBGP邻居关系:物理接口

[R1]bgp 100  // 配置BGP AS号
[R1-bgp]router-id 1.1.1.1   //配置BGP路由器的RID 
[R1-bgp]peer 192.168.12.2 as-number 200   
//与所属AS200 的路由器的  192.168.12.2接口建立邻居关系
[R2]bgp 200
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 192.168.12.1 as-number 100
[R7]bgp  700
[R7-bgp]router-id 7.7.7.7
[R7-bgp]peer 192.168.67.6 as-number 200
[R6]bgp  200
[R6-bgp]router-id 6.6.6.6
[R6-bgp]peer 192.168.67.7 as-number 700
[R7]dis bgp peer 
BGP local router ID : 7.7.7.7
Local AS number : 700    //本地路由器AS号 与peer 的AS 不同 ,为 EBGP
Total number of peers : 1      Peers in established state : 1
Peer             V          AS   MsgRcvd   MsgSent  OutQ  Up/Down       State           PrefRcv
192.168.67.6    4          200        2               3            0       00:00:06        Established    0
配置IBGP邻居 关系:物理接口
[R2]bgp 200
[R2-bgp]peer 192.168.56.6 as-number 200
[R6]bgp  200
[R6-bgp]peer 192.168.23.2 as-number 200
[R6]dis bgp peer 

3.BGP报文类型:

4.BGP 状态机:

5,用逻辑接口建立 IBGP邻居关系:在部署IBGP对等体关系时,建议使用Loopback地址作为更新源地址。

[R2]bgp  200
[R2-bgp]undo  peer 192.168.56.6
[R6]bgp 200
[R6-bgp]undo  peer 192.168.23.2 
[R6]dis bgp  peer 
[R2]bgp  200
[R2-bgp]peer 10.10.6.6 as-number 200
[R2-bgp]peer 10.10.6.6 connect-interface LoopBack 0
[R6]bgp 200
[R6-bgp]peer 10.10.2.2 as-number 200
[R6-bgp]peer  10.10.2.2 connect-interface LoopBack 0

6,BGP 注入路由的方式:

拓扑:

1)network    注入     

备注:IP路由表里必须存在的路由,才能通过network 注入到BGP 路由表

[R1]bgp 100
[R1-bgp]network 10.10.1.0 24
[R1]dis bgp routing-table 
BGP Local router ID is 1.1.1.1 
Status codes: * - valid, > - best, d - damped,
h - history,  i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 1
Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.10.1.0/24       0.0.0.0         0                     0      i
*表示路由是有效的的
| 表示路由是最优的

2)import-route方式注入路由

Network方式注入路由虽然是精确注入,但是只能一条条配置逐条注入IP路由表中的路由,如果注入的路由条目很多配置命令将会非常复杂,为此可以使用import-route方式,将:直连路由静态路由OSPF路由IS-IS路由等协议的路由注入到BGP路由表中。

[R7]bgp  700 
[R7-bgp]import-route direct 
[R7]dis bgp  routing-table 

当向BGP路由表注入路由之后,发现通信双方没有对方的路由 ,在R2 和 R6上发现,R2从R1 获取的10.10.1.0 的路由下一跳,传给R6时没有改变,R6上的10.10.7.0 路由传递给R2时下一跳也没有变 ,所以需要在R2和R6建立邻居关系时,更改下一跳为本地地址

[R6]bgp  200
[R6-bgp]peer 10.10.2.2 next-hop-local  //与R2建立邻居时,更改自己的下一跳地址为本地
[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: 2
Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.10.1.0/24       192.168.12.1    0                     0      100i
*>i  10.10.7.0/24       10.10.6.6       0          100        0      700?
[R1]dis bgp  routing-table 
BGP Local router ID is 1.1.1.1 
Status codes: * - valid, > - best, d - damped,
h - history,  i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 2
Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.10.1.0/24       0.0.0.0         0                     0      i
*>   10.10.7.0/24       192.168.12.2                          0      200 700?
由EBGP获取的路由再传递给IBGP时,下一跳要改变
[R2]bgp  200
[R2-bgp]peer 10.10.6.6 next-hop-local
[R6]dis bgp routing-table
BGP Local router ID is 6.6.6.6 
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  10.10.1.0/24       10.10.2.2       0          100        0      100i
*>   10.10.7.0/24       192.168.67.7    0                     0      700?
192.168.67.0       192.168.67.7    0                     0      700?
<R7>dis bgp  routing-table 
BGP Local router ID is 7.7.7.7 
Status codes: * - valid, > - best, d - damped,
h - history,  i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.10.1.0/24       192.168.67.6                          0      200 100i
*>   10.10.7.0/24       0.0.0.0         0                     0      ?
*>   10.10.7.7/32       0.0.0.0         0                     0      ?
*>   127.0.0.0          0.0.0.0         0                     0      ?
*>   127.0.0.1/32       0.0.0.0         0                     0      ?
*>   192.168.67.0       0.0.0.0         0                     0      ?
*>   192.168.67.7/32    0.0.0.0         0                     0      ?

此时R1 和R7 BGP路由表都有双方的 最优有效路由,测试连通性。

发现:R2/R3/R4/R5/R6   上面没有路由  ,原因涉及到  BGP路由通告原则:

BGP通过network、import-route、aggregate聚合方式生成BGP路由后,通过Update报文将BGP路由传递给对等体。

7,BGP通告遵循以下原则:
通告原则一:只发布最优且有效路由的路由通告给对等体
通告原则二:从EBGP对等体获取的路由,会发布给所有对等体。
通告原则三:IBGP水平分割:从IBGP对等体获取的路由,不会发送给IBGP对等体。
通告原则四:BGP同步规则

指的是:当一台路由器从自己的IBGP对等体学习到一条BGP路由时(这类路由被称为IBGP路由),它将不能使用该条路由或把这条路由通告给自己的EBGP对等体,除非它又从IGP协议(例如OSPF等,此处也包含静态路由)学习到这条路由,也就是要求IBGP路由与IGP路由同步。同步规则主要用于规避BGP路由黑洞问题。

解决BGP 同步规则问题,方案有两个:1), 通过BGP 与OSPF 互相引入,但是OSPF引入BGP时 ,由于BGP路由量太大,容易将路由器管瘫痪,所以一般不用这种方法  。

2),全互联  ,由于AS内部有水平分割  ,所以让AS内所有设备都运行BGP,且通过全互联实现互通

全互联配置:
[R2]bgp  200
[R2-bgp]peer 10.10.3.3 as-number 200
[R2-bgp]peer 10.10.3.3 connect-interface LoopBack 0
[R2-bgp]peer 10.10.3.3 next-hop-local
[R2-bgp]peer 10.10.4.4 as-number 200
[R2-bgp]peer  10.10.4.4 connect-interface  LoopBack 0
[R2-bgp]peer  10.10.4.4 next-hop-local
[R2-bgp]peer 10.10.5.5 as-number 200
[R2-bgp]peer  10.10.5.5 connect-interface LoopBack 0
[R2-bgp]peer  10.10.5.5 next-hop-local
[R2-bgp]peer 10.10.6.6 as-number 200
[R2-bgp]peer  10.10.6.6 connect-interface LoopBack 0
[R2-bgp]peer 10.10.6.6 next-hop-local
[R3]bgp  200
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 10.10.2.2 as-number 200
[R3-bgp]peer  10.10.2.2 connect-interface LoopBack 0
[R3-bgp]peer 10.10.4.4 as-number 200
[R3-bgp]peer  10.10.4.4 connect-interface LoopBack 0
[R3-bgp]peer  10.10.5.5 as-number 200
[R3-bgp]peer  10.10.5.5 connect-interface LoopBack 0
[R3-bgp]peer  10.10.6.6 as-number 200
[R3-bgp]peer  10.10.6.6 connect-interface LoopBack 0
[R4]bgp  200
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 10.10.2.2 as-number 200
[R4-bgp]peer  10.10.2.2 connect-interface LoopBack 0
[R4-bgp]peer  10.10.3.3 as-number 200
[R4-bgp]peer  10.10.3.3 connect-interface LoopBack 0
[R4-bgp]peer  10.10.5.5 as-number 200
[R4-bgp]peer  10.10.5.5 connect-interface LoopBack 0
[R4-bgp]peer  10.10.6.6 as-number 200
[R4-bgp]peer  10.10.6.6 connect-interface LoopBack 0
[R5]bgp  200
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 10.10.2.2 as-number 200
[R5-bgp]peer  10.10.2.2 connect-interface LoopBack 0
[R5-bgp]peer  10.10.3.3 as-number 200
[R5-bgp]peer  10.10.3.3 connect-interface LoopBack 0
[R5-bgp]peer  10.10.4.4 as-number 200
[R5-bgp]peer  10.10.4.4 connect-interface LoopBack 0
[R5-bgp]peer  10.10.6.6 as-number 200
[R5-bgp]peer  10.10.6.6 connect-interface LoopBack 0
[R6]bgp  200
[R6-bgp]router-id 6.6.6.6
[R6-bgp]peer 10.10.2.2 as-number 200
[R6-bgp]peer  10.10.2.2 connect-interface  LoopBack 0
[R6-bgp]peer  10.10.2.2 next-hop-local
[R6-bgp]peer  10.10.3.3 as-number 200
[R6-bgp]peer  10.10.3.3 connect-interface LoopBack 0
[R6-bgp]peer 10.10.3.3 next-hop-local
[R6-bgp]peer  10.10.4.4 as-number 200
[R6-bgp]peer  10.10.4.4 connect-interface LoopBack 0
[R6-bgp]peer  10.10.4.4 next-hop-local
[R6-bgp]peer 10.10.5.5 as-number 200
[R6-bgp]peer  10.10.5.5 connect-interface LoopBack 0
[R6-bgp]peer  10.10.5.5 next-hop-local
[R1]ping -a 10.10.1.1 10.10.7.7
PING 10.10.7.7: 56  data bytes, press CTRL_C to break
Reply from 10.10.7.7: bytes=56 Sequence=1 ttl=250 time=190 ms
Reply from 10.10.7.7: bytes=56 Sequence=2 ttl=250 time=50 ms
Reply from 10.10.7.7: bytes=56 Sequence=3 ttl=250 time=60 ms
Reply from 10.10.7.7: bytes=56 Sequence=4 ttl=250 time=60 ms
Reply from 10.10.7.7: bytes=56 Sequence=5 ttl=250 time=50 ms
[R1]ping 10.10.7.7
PING 10.10.7.7: 56  data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值