• 地址前缀列表+改修属性


    二、知识点:

    BGP路由优选规则

    当到达同一个目的网段存在多条路由时,BGP通过如下的次序进行路由优选:

    1)丢弃下一跳不可达的路由。

    2)优选Preferred-Value属性值最大的路由。

    3)优选Local_Preference属性值最大的路由。

    4)本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。

    5)优选AS_Path属性值最短的路由。

    6)优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。

    7)优选MED属性值最小的路由。

    8)优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)。

    9)优选到Next_Hop的IGP度量值最小的路由。

    10)优选Cluster_List最短的路由。

    11)优选Router ID(Orginator_ID)最小的设备通告的路由。

    12)优选具有最小IP地址的对等体通告的路由。

    1,丢弃下一跳不可达路由

    2, 优选Preferred-Value属性值最大的路由。

    协议优选值 属性为 华为的私有属性,默认值为0  ,值越大越有 ,只在本地设备有效。

    3,优选Local_Preference属性值最大的路由。

    本地优先级应用于 对等体之间 ,值越大越优,默认值为100  。

    1. [R1]undo acl 2000
    2. [R1]undo route-policy wt
    3. [R1]bgp 100
    4. [R1-bgp]undo peer 10.10.3.3 route-policy wt import
    5. 1)用地址前缀列表 抓取需要修改属性的路由
    6. [R3]ip ip-prefix cw index 10 permit 200.1.1.0 24
    7. 2)用路由策略修改匹配条件的 路由属性 本地优先级的值
    8. [R3]route-policy wt permit node 10
    9. [R3-route-policy]if-match ip-prefix cw
    10. [R3-route-policy]apply local-preference 1000
    11. [R3-route-policy]q
    12. [R3]route-policy wt permit node 20
    13. 3) 在向邻居1.1 发送路由的出向调用策略,生效,实现R1上路由优选
    14. [R3]bgp 100
    15. [R3-bgp]peer 10.10.1.1 route-policy wt export
    16. 4)[R1]dis bgp routing-table
    17. BGP Local router ID is 1.1.1.1
    18. Status codes: * - valid, > - best, d - damped,
    19. h - history, i - internal, s - suppressed, S - Stale
    20. Origin : i - IGP, e - EGP, ? - incomplete
    21. Total Number of Routes: 2
    22. Network NextHop MED LocPrf PrefVal Path/Ogn
    23. *>i 200.1.1.0 10.10.3.3 0 1000 0 200i
    24. ●i 10.10.2.2 0 100 0 200i
    25. 4,本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。
    26. [R3]undo ip ip-prefix cw
    27. [R3]undo route-policy wt
    28. [R3]bgp 100
    29. [R3-bgp]undo peer 10.10.1.1 route-policy wt export
    30. 在R1 创建一条 lo1 : 100.1.1.1 /24 ,使用network 和import 向BGP 注入100.1.1.0/24 的路由
    31. ip route-static 100.1.1.0 25 null 0
    32. ip route-static 100.1.1.0 26 null 0
    33. ip route-static 100.1.1.0 27 null 0
    34. 通过引入上面的静态路由 ,进行聚合 ,聚合 100.1.1.0 /24 的路由
    35. [R1]interface LoopBack 1
    36. [R1-LoopBack1]ip add 100.1.1.1 24
    37. [R1-LoopBack1]q
    38. [R1]ip route-static 100.1.1.0 25 NULL 0
    39. [R1]ip route-static 100.1.1.0 26 NULL 0
    40. [R1]ip route-static 100.1.1.0 27 NULL 0
    41. [R1]bgp 100
    42. [R1-bgp]network 100.1.1.0 24
    43. [R1-bgp]import-route direct
    44. [R1-bgp]import-route static
    45. [R1]dis bgp routing-table
    46. BGP Local router ID is 1.1.1.1
    47. Status codes: * - valid, > - best, d - damped,
    48. h - history, i - internal, s - suppressed, S - Stale
    49. Origin : i - IGP, e - EGP, ? - incomplete
    50. Total Number of Routes: 16
    51. Network NextHop MED LocPrf PrefVal Path/Ogn
    52. *> 10.10.1.0/24 0.0.0.0 0 0 ?
    53. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    54. *> 100.1.1.0/24 0.0.0.0 0 0 i
    55. 0.0.0.0 0 0 ?
    56. 通过上述信息,表明 network > import
    57. 接下来将注入BGP 的具有相同前缀的静态路由进行手动聚合:
    58. [R1]bgp 100
    59. [R1-bgp]aggregate 100.1.1.0 24
    60. [R1]dis bgp routing-table
    61. BGP Local router ID is 1.1.1.1
    62. Status codes: * - valid, > - best, d - damped,
    63. h - history, i - internal, s - suppressed, S - Stale
    64. Origin : i - IGP, e - EGP, ? - incomplete
    65. Total Number of Routes: 17
    66. Network NextHop MED LocPrf PrefVal Path/Ogn
    67. *> 10.10.1.0/24 0.0.0.0 0 0 ?
    68. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    69. *> 100.1.1.0/24 127.0.0.1 0 ? //手动聚合得来的路由
    70. 0.0.0.0 0 0 i //network 进来的路由
    71. 0.0.0.0 0 0 ? //import 进来的路由
    72. *> 100.1.1.0/25 0.0.0.0 0 0 ?
    73. *> 100.1.1.0/26 0.0.0.0 0 0 ?
    74. *> 100.1.1.0/27 0.0.0.0 0 0 ?
    75. [R1]bgp 100
    76. [R1-bgp]summary automatic //自动聚合 ,聚合默认掩码
    77. [R1]dis bgp routing-table
    78. BGP Local router ID is 1.1.1.1
    79. Status codes: * - valid, > - best, d - damped,
    80. h - history, i - internal, s - suppressed, S - Stale
    81. Origin : i - IGP, e - EGP, ? - incomplete
    82. Total Number of Routes: 19
    83. Network NextHop MED LocPrf PrefVal Path/Ogn
    84. *> 10.0.0.0 127.0.0.1 0 ?
    85. s> 10.10.1.0/24 0.0.0.0 0 0 ?
    86. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    87. *> 100.0.0.0 127.0.0.1 0 ? //自动聚合 100.0.0.0 /8
    88. *> 100.1.1.0/24 127.0.0.1 0 ?
    89. 0.0.0.0 0 0 i
    90. 0.0.0.0 0 0 ?
    91. s> 100.1.1.0/25 0.0.0.0 0 0 ?
    92. [R1]bgp 100
    93. [R1-bgp]aggregate 100.0.0.0 8 //手动聚合 100.0.0.0 /8
    94. [R1]dis bgp routing-table
    95. BGP Local router ID is 1.1.1.1
    96. Status codes: * - valid, > - best, d - damped,
    97. h - history, i - internal, s - suppressed, S - Stale
    98. Origin : i - IGP, e - EGP, ? - incomplete
    99. Total Number of Routes: 20
    100. Network NextHop MED LocPrf PrefVal Path/Ogn
    101. *> 10.0.0.0 127.0.0.1 0 ?
    102. s> 10.10.1.0/24 0.0.0.0 0 0 ?
    103. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    104. *> 100.0.0.0 127.0.0.1 0 ? //手动聚合
    105. 127.0.0.1 0 ? //自动聚合 ,区分不开?
    106. [R1]dis bgp routing-table 100.0.0.0 8 //查看具体 100.0.0.0 8 的路由信息,来区分手动和自动谁优先
    107. BGP local router ID : 1.1.1.1
    108. Local AS number : 100
    109. Paths: 2 available, 1 best, 1 select
    110. BGP routing table entry information of 100.0.0.0/8:
    111. Aggregated route.
    112. Route Duration: 00h00m48s
    113. Direct Out-interface: NULL0
    114. Original nexthop: 127.0.0.1
    115. Qos information : 0x0
    116. AS-path Nil, origin incomplete, pref-val 0, valid, local, best, select, active,
    117. pre 255
    118. Aggregator: AS 100, Aggregator ID 1.1.1.1
    119. Advertised to such 2 peers: //手动聚合路由通告给邻居
    120. 10.10.3.3
    121. 10.10.2.2
    122. BGP routing table entry information of 100.0.0.0/8:
    123. Summary automatic route
    124. Route Duration: 00h01m48s
    125. Direct Out-interface: NULL0
    126. Original nexthop: 127.0.0.1
    127. Qos information : 0x0
    128. AS-path Nil, origin incomplete, pref-val 0, valid, local, pre 255, not preferre
    129. d for route type
    130. Aggregator: AS 100, Aggregator ID 1.1.1.1
    131. Not advertised to any peer yet //自动聚合路由不通告
    132. 通过以上整体操作验证: 本地产生的路由 手动聚合 > 自动聚合 > network > import >对等体学习来
    133. [R1]bgp 100
    134. [R1-bgp]undo summary automatic //关闭自动聚合
    135. [R1-bgp]aggregate 100.1.1.0 24 //手动聚合 掩码24网段
    136. [R1]dis bgp routing-table
    137. BGP Local router ID is 1.1.1.1
    138. Status codes: * - valid, > - best, d - damped,
    139. h - history, i - internal, s - suppressed, S - Stale
    140. Origin : i - IGP, e - EGP, ? - incomplete
    141. Total Number of Routes: 18
    142. Network NextHop MED LocPrf PrefVal Path/Ogn
    143. *> 10.10.1.0/24 0.0.0.0 0 0 ?
    144. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    145. *> 100.0.0.0 127.0.0.1 0 ?
    146. *> 100.1.1.0/24 127.0.0.1 0 ? //手动聚合优先
    147. 0.0.0.0 0 0 i
    148. 0.0.0.0 0 0 ?
    149. *> 100.1.1.0/25 0.0.0.0 0 0 ? //明细路由
    150. *> 100.1.1.0/26 0.0.0.0 0 0 ?
    151. *> 100.1.1.0/27 0.0.0.0 0 0 ?
    152. 在邻居设备查看BGP路由表,发现 聚合路由传递给邻居的同时,明细路由也传递给邻居啦 ?
    153. [R2]dis bgp routing-table
    154. BGP Local router ID is 2.2.2.2
    155. Status codes: * - valid, > - best, d - damped,
    156. h - history, i - internal, s - suppressed, S - Stale
    157. Origin : i - IGP, e - EGP, ? - incomplete
    158. Total Number of Routes: 9
    159. Network NextHop MED LocPrf PrefVal Path/Ogn
    160. *>i 10.10.1.0/24 10.10.1.1 0 100 0 ?
    161. *>i 100.0.0.0 10.10.1.1 100 0 ?
    162. *>i 100.1.1.0/24 10.10.1.1 100 0 ?
    163. *>i 100.1.1.0/25 10.10.1.1 0 100 0 ?
    164. *>i 100.1.1.0/26 10.10.1.1 0 100 0 ?
    165. *>i 100.1.1.0/27 10.10.1.1 0 100 0 ?
    166. *>i 192.168.12.0 10.10.1.1 0 100 0 ?
    167. *>i 192.168.13.0 10.10.1.1 0 100 0 ?
    168. *> 200.1.1.0 192.168.24.4 0 0 200i
    169. 进行手动聚合之后,不向邻居发送明细路由,所以要进行明细抑制。
    170. [R1]bgp 100
    171. [R1-bgp]aggregate 100.1.1.0 24 detail-suppressed
    172. [R1-bgp]q
    173. [R1]dis bgp routing-table
    174. BGP Local router ID is 1.1.1.1
    175. Status codes: * - valid, > - best, d - damped,
    176. h - history, i - internal, s - suppressed, S - Stale
    177. Origin : i - IGP, e - EGP, ? - incomplete
    178. Total Number of Routes: 18
    179. Network NextHop MED LocPrf PrefVal Path/Ogn
    180. *> 10.10.1.0/24 0.0.0.0 0 0 ?
    181. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    182. *> 100.0.0.0 127.0.0.1 0 ?
    183. *> 100.1.1.0/24 127.0.0.1 0 ?
    184. 0.0.0.0 0 0 i
    185. 0.0.0.0 0 0 ?
    186. s> 100.1.1.0/25 0.0.0.0 0 0 ? //s 表示抑制
    187. s> 100.1.1.0/26 0.0.0.0 0 0 ?
    188. s> 100.1.1.0/27 0.0.0.0 0 0 ?
    189. *> 100.1.1.1/32 0.0.0.0 0 0 ?
    190. *> 127.0.0.0 0.0.0.0 0 0 ?
    191. *> 127.0.0.1/32 0.0.0.0 0 0 ?
    192. *> 192.168.12.0 0.0.0.0 0 0 ?
    193. *> 192.168.12.1/32 0.0.0.0 0 0 ?
    194. *> 192.168.13.0 0.0.0.0 0 0 ?
    195. *> 192.168.13.1/32 0.0.0.0 0 0 ?
    196. *>i 200.1.1.0 10.10.2.2 0 100 0 200i
    197. ●i 10.10.3.3 0 100 0 200i
    198. 再到邻居设备查看BGP 路由表
    199. [R2]dis bgp routing-table
    200. BGP Local router ID is 2.2.2.2
    201. Status codes: * - valid, > - best, d - damped,
    202. h - history, i - internal, s - suppressed, S - Stale
    203. Origin : i - IGP, e - EGP, ? - incomplete
    204. Total Number of Routes: 6
    205. Network NextHop MED LocPrf PrefVal Path/Ogn
    206. *>i 10.10.1.0/24 10.10.1.1 0 100 0 ?
    207. *>i 100.0.0.0 10.10.1.1 100 0 ?
    208. *>i 100.1.1.0/24 10.10.1.1 100 0 ? //发现明细路由被抑制啦
    209. *>i 192.168.12.0 10.10.1.1 0 100 0 ?
    210. *>i 192.168.13.0 10.10.1.1 0 100 0 ?
    211. *> 200.1.1.0 192.168.24.4 0 0 200i
    212. 新需求: 传递给邻居路由时,除了聚合路由,还将部分明细路由传递过去
    213. [R1]ip route-static 100.1.1.0 25 NULL 0
    214. [R1]ip route-static 100.1.1.0 26 NULL 0 —不允许掩码26明细路由传递给邻居(路由策略工具可以实现过滤)
    215. [R1]ip route-static 100.1.1.0 27 NULL 0
    216. 1)用地址前缀列表精确匹配掩码26的路由
    217. [R1]ip ip-prefix 26 index 10 permit 100.1.1.0 24 greater-equal 26 less-equal 26
    218. 2)用路由策略实现过滤,只要匹配前缀列表,就允许策略
    219. [R1]route-policy 25 permit node 10
    220. [R1-route-policy]if-match ip-prefix 26
    221. [R1-route-policy]q
    222. 3)在手动聚合的时候调用抑制策略,所以掩码26的路由就不会发送给邻居了啊
    223. [R1]bgp 100
    224. [R1-bgp]aggregate 100.1.1.0 24 suppress-policy 25
    225. [R1-bgp]q
    226. [R1]dis bgp routing-table
    227. BGP Local router ID is 1.1.1.1
    228. Status codes: * - valid, > - best, d - damped,
    229. h - history, i - internal, s - suppressed, S - Stale
    230. Origin : i - IGP, e - EGP, ? - incomplete
    231. Total Number of Routes: 18
    232. Network NextHop MED LocPrf PrefVal Path/Ogn
    233. *> 10.10.1.0/24 0.0.0.0 0 0 ?
    234. *> 10.10.1.1/32 0.0.0.0 0 0 ?
    235. *> 100.0.0.0 127.0.0.1 0 ?
    236. *> 100.1.1.0/24 127.0.0.1 0 ?
    237. 0.0.0.0 0 0 i
    238. 0.0.0.0 0 0 ?
    239. *> 100.1.1.0/25 0.0.0.0 0 0 ?
    240. s> 100.1.1.0/26 0.0.0.0 0 0 ?
    241. *> 100.1.1.0/27 0.0.0.0 0 0 ?
    242. *> 100.1.1.1/32 0.0.0.0 0 0 ?
    243. *> 127.0.0.0 0.0.0.0 0 0 ?
    244. *> 127.0.0.1/32 0.0.0.0 0 0 ?
    245. *> 192.168.12.0 0.0.0.0 0 0 ?
    246. *> 192.168.12.1/32 0.0.0.0 0 0 ?
    247. *> 192.168.13.0 0.0.0.0 0 0 ?
    248. *> 192.168.13.1/32 0.0.0.0 0 0 ?
    249. *>i 200.1.1.0 10.10.2.2 0 100 0 200i
    250. ●i 10.10.3.3 0 100 0 200i
    251. 5)优选AS_Path属性值最短的路由。
    252. AS 之间防环
    253. 路径优选 -列表越短越优
    254. [R1]undo ip ip-prefix 26
    255. [R1]undo route-policy 25
    256. [R1]bgp 100
    257. [R1-bgp]undo aggregate 100.1.1.0 24 suppress-policy 25
    258. [R1]bgp 100
    259. [R1-bgp]undo import-route direct
    260. [R1-bgp]undo import-route static
    261. [R1-bgp]undo network 100.1.1.0 24
    262. 1)配置地址前缀列表,抓取需要修改属性的路由
    263. [R2]ip ip-prefix 200 index 10 permit 200.1.1.0 24 greater-equal 24 less-equal 24
    264. 2)配置路由策略,给匹配的路由,修改属性值
    265. [R2]route-policy 200 permit node 10
    266. [R2-route-policy]if-match ip-prefix 200
    267. [R2-route-policy]apply as-path 300 additive
    268. [R2-route-policy]q
    269. [R2]route-policy 200 permit node 20 //放行没有匹配的其他路由
    270. 3)在与R1建立邻居的出方向调用策略
    271. [R2]bgp 100
    272. [R2-bgp]peer 10.10.1.1 route-policy 200 export
    273. [R2-bgp]q
    274. 4)[R1]dis bgp routing-table
    275. BGP Local router ID is 1.1.1.1
    276. Status codes: * - valid, > - best, d - damped,
    277. h - history, i - internal, s - suppressed, S - Stale
    278. Origin : i - IGP, e - EGP, ? - incomplete
    279. Total Number of Routes: 2
    280. Network NextHop MED LocPrf PrefVal Path/Ogn
    281. *>i 200.1.1.0 10.10.3.3 0 100 0 200i
    282. ●i 10.10.2.2 0 100 0 300 200i
    283. 6)优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。
    284. i > e > ?
    285. 7)优选MED属性值最小的路由。
    286. 应用于AS 之间 , 从一个AS 传递过来带有MED 的路由,这个MED值这个属性不会再传递给第三个AS , MED 默认 0 ,值 越大越不优 。 用来选择AS 入向最优的路由
    287. [R2]undo ip ip-prefix 200
    288. [R2]undo route-policy 200
    289. [R2]bgp 100
    290. [R2-bgp]undo peer 10.10.1.1 route-policy 200 export
    291. [R1]bgp 100
    292. [R1-bgp]network 100.1.1.0 24
    293. [R1-bgp]q
    294. [R4]dis bgp routing-table
    295. BGP Local router ID is 4.4.4.4
    296. Status codes: * - valid, > - best, d - damped,
    297. h - history, i - internal, s - suppressed, S - Stale
    298. Origin : i - IGP, e - EGP, ? - incomplete
    299. Total Number of Routes: 6
    300. Network NextHop MED LocPrf PrefVal Path/Ogn
    301. *> 100.1.1.0/24 192.168.24.2 0 100i
    302. 192.168.34.3 0 100i
    303. 1)配置地址前缀列表,抓取需要修改属性的路由
    304. [R2]ip ip-prefix 100 index 10 permit 100.1.1.0 24
    305. 2)配置路由策略,给匹配的路由,修改属性值
    306. [R2]route-policy 100 permit node 10
    307. [R2-route-policy]if-match ip-prefix 100
    308. [R2-route-policy]apply cost 100
    309. [R2-route-policy]q
    310. [R2]route-policy 100 permit node 20
    311. 3)在与R4建立邻居的出方向调用策略
    312. [R2]bgp 100
    313. [R2-bgp]peer 192.168.24.4 route-policy 100 export
    314. 在R4上 通过在R2上修改过的MED 值 ,来改变 R4访问R1 上100段的 选路
    315. [R4]dis bgp routing-table
    316. BGP Local router ID is 4.4.4.4
    317. Status codes: * - valid, > - best, d - damped,
    318. h - history, i - internal, s - suppressed, S - Stale
    319. Origin : i - IGP, e - EGP, ? - incomplete
    320. Total Number of Routes: 5
    321. Network NextHop MED LocPrf PrefVal Path/Ogn
    322. *> 10.10.4.0/24 0.0.0.0 0 0 i
    323. *> 100.0.0.0 192.168.34.3 0 100i
    324. *> 100.1.1.0/24 192.168.34.3 0 100i
    325. 192.168.24.2 100 0 100i
    326. *> 200.1.1.0 0.0.0.0 0 0 i

     

  • 相关阅读:
    保护互联网数据安全:关键方法与最佳实践
    milvus
    C++ :全局变量(extern int a;)、全局函数【可跨文件/模块使用】【只在头文件中做“声明”】
    Linux root用户忘记密码的恢复方法
    深度学习之 8 深度模型优化与正则化2
    JAVA 编程中的SOLID设计原则
    JavaCV + FFmpeg 播放音视频
    Linux下导出dump文件(Oracle和PG数据)
    GL_TEXTURE_SWIZZLE_R GL_TEXTURE_SWIZZLE_G等详解
    深度之眼(二十一)——概率论
  • 原文地址:https://blog.csdn.net/qq_65225435/article/details/133514988