目录
BGP的选路原则 --- 前提 --- 丢弃所有不可用的路由系信息

- [R1]display ip interface brief
- *down: administratively down
- ^down: standby
- (l): loopback
- (s): spoofing
- The number of interface that is UP in Physical is 4
- The number of interface that is DOWN in Physical is 1
- The number of interface that is UP in Protocol is 4
- The number of interface that is DOWN in Protocol is 1
-
- Interface IP Address/Mask Physical Protocol
- GigabitEthernet0/0/0 12.0.0.1/24 up up
- GigabitEthernet0/0/1 13.0.0.1/24 up up
- GigabitEthernet0/0/2 unassigned down down
- LoopBack0 1.1.1.1/24 up up(s)
- NULL0 unassigned up up(s)
- [R1]
- [R2]display ip interface brief
- *down: administratively down
- ^down: standby
- (l): loopback
- (s): spoofing
- The number of interface that is UP in Physical is 4
- The number of interface that is DOWN in Physical is 1
- The number of interface that is UP in Protocol is 4
- The number of interface that is DOWN in Protocol is 1
-
- Interface IP Address/Mask Physical Protocol
- GigabitEthernet0/0/0 12.0.0.2/24 up up
- GigabitEthernet0/0/1 24.0.0.1/24 up up
- GigabitEthernet0/0/2 unassigned down down
- LoopBack0 2.2.2.2/24 up up(s)
- NULL0 unassigned up up(s)
- [R2]
- [R3]display ip interface brief
- *down: administratively down
- ^down: standby
- (l): loopback
- (s): spoofing
- The number of interface that is UP in Physical is 4
- The number of interface that is DOWN in Physical is 1
- The number of interface that is UP in Protocol is 4
- The number of interface that is DOWN in Protocol is 1
-
- Interface IP Address/Mask Physical Protocol
- GigabitEthernet0/0/0 13.0.0.2/24 up up
- GigabitEthernet0/0/1 34.0.0.1/24 up up
- GigabitEthernet0/0/2 unassigned down down
- LoopBack0 3.3.3.3/24 up up(s)
- NULL0 unassigned up up(s)
- [R3]
- [R4]display ip interface brief
- *down: administratively down
- ^down: standby
- (l): loopback
- (s): spoofing
- The number of interface that is UP in Physical is 5
- The number of interface that is DOWN in Physical is 0
- The number of interface that is UP in Protocol is 5
- The number of interface that is DOWN in Protocol is 0
-
- Interface IP Address/Mask Physical Protocol
- GigabitEthernet0/0/0 24.0.0.2/24 up up
- GigabitEthernet0/0/1 34.0.0.2/24 up up
- GigabitEthernet0/0/2 45.0.0.1/24 up up
- LoopBack0 4.4.4.4/24 up up(s)
- NULL0 unassigned up up(s)
- [R4]\
- [R5]display ip interface brief
- *down: administratively down
- ^down: standby
- (l): loopback
- (s): spoofing
- The number of interface that is UP in Physical is 3
- The number of interface that is DOWN in Physical is 2
- The number of interface that is UP in Protocol is 3
- The number of interface that is DOWN in Protocol is 2
-
- Interface IP Address/Mask Physical Protocol
- GigabitEthernet0/0/0 45.0.0.2/24 up up
- GigabitEthernet0/0/1 unassigned down down
- GigabitEthernet0/0/2 unassigned down down
- LoopBack0 5.5.5.5/24 up up(s)
- NULL0 unassigned up up(s)
- [R5]
R2
- [R2]display ip routing-table protocol ospf
- Route Flags: R - relay, D - download to fib
- ------------------------------------------------------------------------------
- Public routing table : OSPF
- Destinations : 3 Routes : 3
-
- OSPF routing table status :
- Destinations : 3 Routes : 3
-
- Destination/Mask Proto Pre Cost Flags NextHop Interface
-
- 3.3.3.3/32 OSPF 10 2 D 24.0.0.2 GigabitEthernet
- 0/0/1
- 4.4.4.4/32 OSPF 10 1 D 24.0.0.2 GigabitEthernet
- 0/0/1
- 34.0.0.0/24 OSPF 10 2 D 24.0.0.2 GigabitEthernet
- 0/0/1
-
- OSPF routing table status :
- Destinations : 0 Routes : 0
-
- [R2]
R3
- [R3]display ip routing-table protocol ospf
- Route Flags: R - relay, D - download to fib
- ------------------------------------------------------------------------------
- Public routing table : OSPF
- Destinations : 3 Routes : 3
-
- OSPF routing table status :
- Destinations : 3 Routes : 3
-
- Destination/Mask Proto Pre Cost Flags NextHop Interface
-
- 2.2.2.2/32 OSPF 10 2 D 34.0.0.2 GigabitEthernet
- 0/0/1
- 4.4.4.4/32 OSPF 10 1 D 34.0.0.2 GigabitEthernet
- 0/0/1
- 24.0.0.0/24 OSPF 10 2 D 34.0.0.2 GigabitEthernet
- 0/0/1
-
- OSPF routing table status :
- Destinations : 0 Routes : 0
-
- [R3]
R4
- [R4]display ip routing-table protocol ospf
- Route Flags: R - relay, D - download to fib
- ------------------------------------------------------------------------------
- Public routing table : OSPF
- Destinations : 2 Routes : 2
-
- OSPF routing table status :
- Destinations : 2 Routes : 2
-
- Destination/Mask Proto Pre Cost Flags NextHop Interface
-
- 2.2.2.2/32 OSPF 10 1 D 24.0.0.1 GigabitEthernet
- 0/0/0
- 3.3.3.3/32 OSPF 10 1 D 34.0.0.1 GigabitEthernet
- 0/0/1
-
- OSPF routing table status :
- Destinations : 0 Routes : 0
-
- [R4]
R1
- [R1-bgp]display 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
-
- *> 1.1.1.0/24 0.0.0.0 0 0 i
-
- [R1-bgp]display bgp peer
-
- BGP local router ID : 1.1.1.1
- Local AS number : 1
- Total number of peers : 2 Peers in established state : 2
-
- Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
- fRcv
-
- 12.0.0.2 4 2 22 24 0 00:20:04 Established
- 0
- 13.0.0.2 4 2 21 23 0 00:19:59 Established
- 0
- [R1-bgp]
R2
- [R2]display 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: 1
- Network NextHop MED LocPrf PrefVal Path/Ogn
-
- *> 1.1.1.0/24 12.0.0.1 0 0 1i
-
- [R2]display bgp peer
-
- BGP local router ID : 2.2.2.2
- Local AS number : 2
- Total number of peers : 2 Peers in established state : 2
-
- Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
- fRcv
-
- 4.4.4.4 4 2 14 21 0 00:12:02 Established
- 0
- 12.0.0.1 4 1 23 22 0 00:20:50 Established
- 1
- [R2]
R3
- [R3]display bgp peer
-
- BGP local router ID : 3.3.3.3
- Local AS number : 2
- Total number of peers : 2 Peers in established state : 2
-
- Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
- fRcv
-
- 4.4.4.4 4 2 14 22 0 00:12:02 Established
- 0
- 13.0.0.1 4 1 24 23 0 00:21:17 Established
- 1
-
- [R3]display bgp routing-table
-
- BGP Local router ID is 3.3.3.3
- 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
-
- *> 1.1.1.0/24 13.0.0.1 0 0 1i
- [R3]
R4
- [R4]display bgp routing-table
-
- BGP Local router ID is 4.4.4.4
- 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
-
- *>i 1.1.1.0/24 2.2.2.2 0 100 0 1i
- * i 3.3.3.3 0 100 0 1i
-
- [R4]display bgp peer
-
- BGP local router ID : 4.4.4.4
- Local AS number : 2
- Total number of peers : 3 Peers in established state : 3
-
- Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
- fRcv
-
- 2.2.2.2 4 2 17 15 0 00:13:18 Established
- 1
- 3.3.3.3 4 2 16 14 0 00:12:46 Established
- 1
- 45.0.0.2 4 3 23 25 0 00:21:52 Established
- 0

| 属性名 | 传播范围 | 默认值 | 评判标准 |
| PV | 不传播 | 0(0-65535) | 越大越优 |
| LP | IBGP对等体之间 | 100 | 越大越优 |
| AS_PATH | BGP对等体之间 | 记录数量越少越优 | |
| OGN | bgp对等体之间 | 根据起源类型决定 | I>e>? |
| MED | bgp对等体之间 | 默认继承全局路由表中的开销值 | 越小越优 |
PV值是华为的私有属性,可以理解为是权重,数值越大,其优先级越高,又因为他是所有选路原则中的第一条原则,所以,该属性是本设备上选路最方便的一个属性。 --- 这个属性只能在本设备上生效,他无法传递给任何BGP对等体。
方法一 --- 全局修改
- [R4-bgp]peer 3.3.3.3 preferred-value ?
- INTEGER<0-65535> Preference value
- [R4-bgp]peer 3.3.3.3 preferred-value 100
-
- AS-path 1, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for PreVal
负载分担 --- 即让不同的流量走不同的线路,分担单一线路的压力
方法二 --- 精细化控制
1.抓取流量
[R4]ip ip-prefix PV permit 10.0.0.0 24
2.做路由策略
- [R4]route-policy PV permit node 10
- Info: New Sequence of this List.
- [R4-route-policy]if-match ip-prefix pv
- [R4-route-policy]apply preferred-value 100
- [R4-route-policy]q
- [R4]route-policy PV permit node 20 --- 配置空列表放通剩余所有流量
- Info: New Sequence of this List.
- [R4-route-policy]q
注意:
必须要配置空列表放通剩余所有流量
3.在BGP中调用路由策略
[r4-bgp]peer 3.3.3.3 route-policy PV import
LP --- 本地优先级 --- 默认值为100,越大越优。这个属性可以再IBGP对等体之间进行传递,所以,他是AS内部选路最常用的属性。路由信息在传递给EBGP对等体时将不携带这个属性
方法一 --- 全局修改
[R3-bgp]default local-preference 200
方法二 --- 精细化控制
在R3的出方向做
1.抓取路由
[r3]ip ip-prefix lp permit 10.0.0.0 24
2.做路由策略
- [r3]route-policy lp permit node 10
- Info: New Sequence of this List.
- [r3-route-policy]if-match ip-prefix lp
- [r3-route-policy]apply local-preference 300
- [r3-route-policy]q
- [r3]route-policy lp permit node 20
- Info: New Sequence of this List.
- [r3-route-policy]q
3.在BGP进程中调用
[r3-bgp]peer 4.4.4.4 route-policy lp export
自己始发的路由优先级高于对等体处学来的,自己始发的方法也存在多种,他们的优先级关系为手工聚合>自动聚合>network>import
1.我们在进行路由聚合时,如果激活AS_SET关键字之后,将不同AS的明细路由进行聚合,则我们将AS_PATH属性中携带所有明细AS的AS号,并用大括号括起来。在进行选路比较时,大括号的内容当做一个AS号来看待。
2.在联邦时,我们联邦内部也需要使用AS_PATH来进行防环,我们使用小括号将AS号括起来,在进行选路比较时,将不计算小圆括号里的内容。
在R1的出方向修改AS_PATH属性
1.抓取路由
[r1]ip ip-prefix as permit 10.0.0.0 24
2.配置路由策略
- [r1]route-policy as permit node 10
- Info: New Sequence of this List.
- [r1-route-policy]if-match ip-prefix as
- [R1-route-policy]apply as-path 11 22 33 ?
- INTEGER<1-4294967295> AS number in asplain format (number<1-4294967295>)
- STRING<3-11> AS number in asdot format
- (number<1-65535>.number<0-65535>)
- additive Append to original As Number
- overwrite Overwrite original As Number
-
- [R1-route-policy]apply as-path 11 22 33 additive
- [R1]route-policy as permit node 20
- Info: New Sequence of this List.
解析:
additive Append to original As Number --- 在原有AS_PATH属性的基础上添加配置的AS号
overwrite Overwrite original As Number --- 直接覆盖原有的AS_PATH属性值
[R1-route-policy]apply as-path 11 22 33 additive --- 建议使用添加,因为AS_PATH属性主要任务用来防止环路,将原有属性覆盖可能导致路由回传,造成环路产生
3.在BGP中调用策略
[R1-bgp]peer 12.0.0.2 route-policy as export
[r2-route-policy]apply as-path 1 1 1 additive --- 建议在AS_PATH属性中添加真实离开的AS的AS号,因为AS_PATH属性本身具有防环作用,添加AS号后可能导致路由无法发送到对应的AS当中,影响陆游的传递。AS_PATH属性在进行选路时,仅关注AS号的长短,不关注内容。
起源码的优先级 --- I>E>?
OGN --- 起源码 --- I,e,?--- 用来表示路由条目的起源
I --- 代表该路由信息起源于IGP协议(不局限于IGP协议,包括静态,直连),代表该路由条目起源于AS内部 --- 通过network发不出来的路由信息起源码为I
E --- 代表该路由信息起源于EGP协议 --- EGP指的是BGP之前使用的外部网关协议
?--- 通过除了以上两种方式学习到的路由 --- 重发布导入的路由起源码都是 ?
1.抓取路由
[r2]ip ip-prefix ogn permit 10.0.0.0 24
- [r2]route-policy ogn permit node 10
- Info: New Sequence of this List.
- [r2-route-policy]if-match ip-prefix ogn
- [r2-route-policy]apply origin ?
- egp Remote EGP
- igp Local IGP
- incomplete Unknown heritage
- [r2-route-policy]apply origin incomplete
- [r2-route-policy]q
- [r2]route-policy ogn permit node 20
- Info: New Sequence of this List.
- [r2-route-policy]q
3.在BGP中进行调用
[r2-bgp]peer 12.0.0.1 route-policy ogn import
MED --- 多出口鉴别属性 --- MED值默认初始值并不是0,而是继承了路由表中该路由条目的开销值,所以,他可以反应到达目标网段在本AS内部的开销值大小,通过这个参数,别的AS的流量在进入本AS时将可以选择开销值较小的入口进入。通过修改这个属性值,我们也可以影响其他AS的流量流入本AS的路径。若本地通过IBGP毒地鞥提学习到一条BGP路由,其中存在MED值,之后需要将这条路由再传递给本地的EBGP对等体,则他将不再携带这个MED值,这种设置将有可能造成选路不佳的情况。所以,讲义,如果存在多边界设备需要将路由发送给EBGP对等体关系时,需要将所有的路由信息都发布。(每台设备都需要发布)
在R2配置,影响R1的选路
1.抓取路由
[r2]ip ip-prefix med permit 4.4.4.0 24
2.配置路由策略
- [r2]route-policy med permit node 10
- Info: New Sequence of this List.
- [r2-route-policy]if-match ip-prefix med
- [r2-route-policy]apply cost 10
- [r2-route-policy]q
- [r2]route-policy med permit node 20
- Info: New Sequence of this List.
- [r2-route-policy]q
3.在BGP进程中调用
[r2-bgp]peer 12.0.0.1 route-policy med export
注意:
MED值影响的是别的AS的流量通过多个出口进入到本AS内部,如果流入的不是同一个AS,即收到的路由条目中AS_PATH属性最左边的AS号不同,则将不比较第六条,直接比较第七条