一、拓扑

基础配置
AR1
system
sysname AR1
int g 0/0/0
ip add 10.0.12.1 24
int g 0/0/1
ip add 10.0.13.1 24
int l 0
ip add 1.1.1.1 32
AR2
system
sysname AR2
int g 0/0/0
ip add 10.0.12.2 24
int g 0/0/1
ip add 10.0.24.2 24
int l 0
ip add 2.2.2.2 32
AR3
system
sysname AR3
int g 0/0/0
ip add 10.0.13.2 24
int g 0/0/1
ip add 10.0.34.3 24
int l 0
ip add 3.3.3.3 32
AR4
system
sysname AR4
int g 0/0/0
ip add 10.0.24.4 24
int g 0/0/1
ip add 10.0.34.4 24
int l 0
ip add 4.4.4.4 32
底层路由协议配置
AR1
ospf 1 router-id 1.1.1.1
area 0
netw 10.0.12.1 0.0.0.0
netw 10.0.13.1 0.0.0.0
netw 1.1.1.1 0.0.0.0
AR2
ospf 1 router-id 2.2.2.2
area 0
netw 10.0.12.2 0.0.0.0
netw 2.2.2.2 0.0.0.0
AR3
ospf 1 router-id 3.3.3.3
area 0
netw 10.0.13.2 0.0.0.0
netw 3.3.3.3 0.0.0.0
BGP配置
AR1
bgp 100
peer 2.2.2.2 as 100
peer 3.3.3.3 as 100
AR2
bgp 100
peer 1.1.1.1 as 100
peer 1.1.1.1 con l 0
peer 10.0.24.4 as 200
peer 1.1.1.1 next-hop-local
AR3
bgp 100
peer 1.1.1.1 as 100
peer 1.1.1.1 con l 0
peer 10.0.34.4 as 200
peer 1.1.1.1 next-hop-local
AR4
bgp 200
peer 10.0.24.2 as 100
peer 10.0.34.3 as 100
netw 4.4.4.4 32
配置完后我们检查一下BGP邻居关系是否成功建立
[AR1]display bgp peer
BGP local router ID : 10.0.12.1
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
2.2.2.2 4 100 6 5 0 00:02:05 Established
1
3.3.3.3 4 100 5 4 0 00:01:48 Established
1
[AR2]display bgp peer
BGP local router ID : 10.0.12.2
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
1.1.1.1 4 100 4 6 0 00:02:19 Established
0
10.0.24.4 4 200 25 25 0 00:22:40 Established
1
[AR3]display bgp peer
BGP local router ID : 10.0.13.2
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
1.1.1.1 4 100 4 6 0 00:02:16 Established
0
10.0.34.4 4 200 25 25 0 00:22:54 Established
1
[AR4]display bgp peer
BGP local router ID : 10.0.24.4
Local AS number : 200
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
10.0.24.2 4 100 25 26 0 00:23:07 Established
0
10.0.34.3 4 100 25 26 0 00:23:07 Established
0
邻居状态没有问题,证明路由可以正常传递,我们在AR2与AR3上都设置了更新路由时将next-hop更改为出接口的IP,所以此时AR1应该会接收到两条路由
[AR1]dis bgp rout
BGP Local router ID is 10.0.12.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
*>i 4.4.4.4/32 2.2.2.2 0 100 0 200i
* i 3.3.3.3 0 100 0 200i
可以看到AR1上通过BGP学习到了两条路由,并且都是有效的,通过表中一些参数我们可以推断出这条路由是怎么产生的,Ogn起源属性为I说明这是通过Network宣告进来的,Path只有200是因为这条路由此时只经过了200并没有从100出去所以只有200,其他参数并无做更改所以都为默认属性。
现在我们去查看一下详细的BGP路由表项看看路由是通过哪条选路原则优先出来的
[AR1]display bgp routing-table 4.4.4.4
BGP local router ID : 10.0.12.1
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 4.4.4.4/32:
From: 2.2.2.2 (10.0.12.2)
Route Duration: 00h01m52s
Relay IP Nexthop: 10.0.12.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, bes
t, select, active, pre 255, IGP cost 1
Not advertised to any peer yet
BGP routing table entry information of 4.4.4.4/32:
From: 3.3.3.3 (10.0.13.2)
Route Duration: 00h01m48s
Relay IP Nexthop: 10.0.13.2
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 3.3.3.3
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre
255, IGP cost 1, not preferred for router ID
Not advertised to any peer yet
可以看到选路原则前八条全部一致,最后的优选原因是因为Router ID所以这是通过第10条优选原则优选出来的,AR2的Router-id为10.0.12.2,AR3的Router-id为10.0.13.2比较完后AR2的Router-id更小所以优选使用AR2的。

接下来我们从最下面依次按照倒叙往上使用优选原则来实现选路策略。
1、优选到Next_Hop的IGP度量值最小的路由

上面通过比较Router-id优选出来优先通过AR2去访问目的网络,现在我们通过修改IGP的度量值的方法实现让AR1优先走AR3去访问,由于OSPF的COST默认为1我们去修改AR2的COST更简单所以这里我们就直接将AR2的COST设置的比AR3更大即可。
AR1
int g 0/0/0
ospf cost 2
[AR1]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.2/32 OSPF 10 2 D 10.0.12.2 GigabitEthernet
0/0/0
3.3.3.3/32 OSPF 10 1 D 10.0.13.2 GigabitEthernet
0/0/1
4.4.4.4/32 IBGP 255 0 RD 3.3.3.3 GigabitEthernet
0/0/1
10.0.12.0/24 Direct 0 0 D 10.0.12.1 GigabitEthernet
0/0/0
10.0.12.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.12.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.13.0/24 Direct 0 0 D 10.0.13.1 GigabitEthernet
0/0/1
10.0.13.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.0.13.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[AR1]display bgp routing-table
BGP Local router ID is 10.0.12.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
*>i 4.4.4.4/32 3.3.3.3 0 100 0 200i
* i 2.2.2.2 0 100 0 200i
[AR1]display bgp routing-table 4.4.4.4
BGP local router ID : 10.0.12.1
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 4.4.4.4/32:
From: 3.3.3.3 (10.0.13.2)
Route Duration: 00h03m26s
Relay IP Nexthop: 10.0.13.2
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 3.3.3.3
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, bes
t, select, active, pre 255, IGP cost 1
Not advertised to any peer yet
BGP routing table entry information of 4.4.4.4/32:
From: 2.2.2.2 (10.0.12.2)
Route Duration: 00h03m30s
Relay IP Nexthop: 10.0.12.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre
255, IGP cost 2, not preferred for IGP cost
Not advertised to any peer yet
可以看到在修改完COST值之后,BGP就优先走AR3去往4.4.4.4,通过查看详细的路由表显示原因为IGP的COST导致的优选。
2、优选从EBGP对等体学来的路由。

做这个实验我们得让AR2与AR3也建立一个邻居这样AR2或AR3就会学习到对方发来的IBGP路由与AR4发来的EBGP路由。

AR2
bgp 100
peer 3.3.3.3 as 100
peer 3.3.3.3 con l 0
peer 3.3.3.3 next-hop-local
AR3
bgp 100
peer 2.2.2.2 as 100
peer 2.2.2.2 con l 0
peer 2.2.2.2 next-hop-local
[AR2]display bgp peer
BGP local router ID : 10.0.12.2
Local AS number : 100
Total number of peers : 3 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
1.1.1.1 4 100 24 26 0 00:22:52 Established
0
3.3.3.3 4 100 4 6 0 00:01:05 Established
1
10.0.24.4 4 200 46 46 0 00:43:13 Established
1
[AR3]display bgp peer
BGP local router ID : 10.0.13.2
Local AS number : 100
Total number of peers : 3 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
1.1.1.1 4 100 24 26 0 00:22:30 Established
0
2.2.2.2 4 100 4 3 0 00:01:00 Established
1
10.0.34.4 4 200 46 46 0 00:43:08 Established
1
[AR3]display bgp routing-table
BGP Local router ID is 10.0.13.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
*> 4.4.4.4/32 10.0.34.4 0 0 200i
* i 2.2.2.2 0 100 0 200i
[AR3]display bgp routing-table 4.4.4.4
BGP local router ID : 10.0.13.2
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 4.4.4.4/32:
From: 10.0.34.4 (10.0.24.4)
Route Duration: 00h44m48s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.0.34.4
Qos information : 0x0
AS-path 200, origin igp, MED 0, pref-val 0, valid, external, best, select, acti
ve, pre 255
Advertised to such 2 peers:
1.1.1.1
2.2.2.2
BGP routing table entry information of 4.4.4.4/32:
From: 2.2.2.2 (10.0.12.2)
Route Duration: 00h02m40s
Relay IP Nexthop: 10.0.13.1
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre
255, IGP cost 3, not preferred for peer type
Not advertised to any peer yet
3、优选MED属性值最小的路由。

由于MED属性是使用在AS间的在AS内选路时不会去比较MED属性,所以这个属性的实验我们需要在AR1上发布一条路由然后在AR4上去做选路,MED是影响入流量的一个属性,一般入方向都是去更改别人的,出方向是更改自己的。
AR1
int l 1
ip add 10.0.1.1 32
q
bgp 100
netw 10.0.1.1 32
[AR4]display bgp routing-table
BGP Local router ID is 10.0.24.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 4.4.4.4/32 0.0.0.0 0 0 i
*> 10.0.1.1/32 10.0.24.2 0 100i
* 10.0.34.3 0 100i
可以看到现在AR4上通过AR2和AR3分别学习到了两条10.0.1.1的路由通过比较Router-id优选出了通过AR2去访问目的网络,现在我们分别在AR2与AR3上做相应策略修改MED值使AR4优先通过AR3去访问目的网络
通过入流量影响选路(以AR4视角为主)
AR2
ip ip-prefix med index 10 permit 10.0.1.1 32
route-policy med permit node 10
if-match ip-prefix med
apply cost 200
q
route-policy med permit node 20
q
bgp 100
peer 10.0.24.4 route-policy med export
AR3
ip ip-prefix med index 10 permit 10.0.1.1 32
route-policy med permit node 10
if-match ip-prefix med
apply cost 100
q
route-policy med permit node 20
q
bgp 100
peer 10.0.34.4 route-policy med export
export是将路由传递给别人时使用route-policy,import是别人将路由传递给自己时使用route-policy。
[AR4]dis bgp rout
BGP Local router ID is 10.0.24.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 4.4.4.4/32 0.0.0.0 0 0 i
*> 10.0.1.1/32 10.0.34.3 100 0 100i
* 10.0.24.2 200 0 100i
[AR4]dis bgp routing-table 10.0.1.1
BGP local router ID : 10.0.24.4
Local AS number : 200
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.0.1.1/32:
From: 10.0.34.3 (10.0.13.2)
Route Duration: 00h02m09s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.0.34.3
Qos information : 0x0
AS-path 100, origin igp, MED 100, pref-val 0, valid, external, best, select, ac
tive, pre 255
Advertised to such 2 peers:
10.0.24.2
10.0.34.3
BGP routing table entry information of 10.0.1.1/32:
From: 10.0.24.2 (10.0.12.2)
Route Duration: 00h02m59s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.0.24.2
Qos information : 0x0
AS-path 100, origin igp, MED 200, pref-val 0, valid, external, pre 255, not pre
ferred for MED
Not advertised to any peer yet
修改完后AR4通过比较MED属性就会优先走AR3去访问目的网络了。
通过出流量影响选路(以AR4视角为主)
ip ip-prefix med index 10 permit 10.0.1.1 32
route-policy AR2 permit node 10
if-match ip-prefix med
apply cost 200
q
route-policy AR2 permit node 20
q
route-policy AR3 permit node 10
if-match ip-prefix med
apply cost 100
q
route-policy AR3 permit node 20
q
bgp 200
peer 10.0.24.2 route-policy AR2 import
peer 10.0.34.3 route-policy AR3 import
我们很少会使用MED来当作出流量的选路原则,这是因为出流量非常好控制我们可以直接使用前两个选路原则即可控制出流量的选路,没必要多此一举使用MED。
4、优选Origin属性优选的路由。

Origin当学习到两条同样的路由条目时优选Network学习到的。这个实验我们在AR1上在发布一条loobpack路由到OSPF当中,让AR3去import到BGP当中,AR2通过Network方式宣告到BGP当中。
AR1
int l 2
ip add 10.1.1.1 32
q
ospf 1
area 0
netw 10.1.1.1 0.0.0.0
[AR2]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 17
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 OSPF 10 2 D 10.0.12.1 GigabitEthernet
0/0/0
2.2.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.3/32 OSPF 10 3 D 10.0.12.1 GigabitEthernet
0/0/0
4.4.4.4/32 EBGP 255 0 D 10.0.24.4 GigabitEthernet
0/0/1
10.0.1.1/32 IBGP 255 0 RD 1.1.1.1 GigabitEthernet
0/0/0
10.0.12.0/24 Direct 0 0 D 10.0.12.2 GigabitEthernet
0/0/0
10.0.12.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.12.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.13.0/24 OSPF 10 3 D 10.0.12.1 GigabitEthernet
0/0/0
10.0.24.0/24 Direct 0 0 D 10.0.24.2 GigabitEthernet
0/0/1
10.0.24.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.0.24.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.1.1/32 OSPF 10 2 D 10.0.12.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
<AR3>dis ip rout
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 17
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 OSPF 10 1 D 10.0.13.1 GigabitEthernet
0/0/0
2.2.2.2/32 OSPF 10 3 D 10.0.13.1 GigabitEthernet
0/0/0
3.3.3.3/32 Direct 0 0 D 127.0.0.1 LoopBack0
4.4.4.4/32 EBGP 255 0 D 10.0.34.4 GigabitEthernet
0/0/1
10.0.1.1/32 IBGP 255 0 RD 1.1.1.1 GigabitEthernet
0/0/0
10.0.12.0/24 OSPF 10 3 D 10.0.13.1 GigabitEthernet
0/0/0
10.0.13.0/24 Direct 0 0 D 10.0.13.2 GigabitEthernet
0/0/0
10.0.13.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.13.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.0.34.0/24 Direct 0 0 D 10.0.34.3 GigabitEthernet
0/0/1
10.0.34.3/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.0.34.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.1.1/32 OSPF 10 1 D 10.0.13.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
现在AR2与AR3都通过OSPF学习到了10.1.1.1的路由现在我们让AR3将OSPF的路由引入到BGP当中
AR3
bgp 100
import ospf 1
<AR4>display bgp routing-table
BGP Local router ID is 10.0.24.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: 9
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 10.0.34.3 1 0 100?
*> 2.2.2.2/32 10.0.34.3 3 0 100?
*> 3.3.3.3/32 10.0.34.3 0 0 100?
*> 4.4.4.4/32 0.0.0.0 0 0 i
*> 10.0.1.1/32 10.0.34.3 100 0 100i
* 10.0.24.2 200 0 100i
*> 10.0.12.0/24 10.0.34.3 3 0 100?
*> 10.0.13.0/24 10.0.34.3 0 0 100?
*> 10.1.1.1/32 10.0.34.3 1 0 100?
在让AR2将10.1.1.1/32的路由通过Network的方式宣告到BGP当中
AR2
bgp 100
netw 10.1.1.1 32
<AR4>display bgp routing-table
BGP Local router ID is 10.0.24.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: 10
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 10.0.34.3 1 0 100?
*> 2.2.2.2/32 10.0.34.3 3 0 100?
*> 3.3.3.3/32 10.0.34.3 0 0 100?
*> 4.4.4.4/32 0.0.0.0 0 0 i
*> 10.0.1.1/32 10.0.34.3 100 0 100i
* 10.0.24.2 200 0 100i
*> 10.0.12.0/24 10.0.34.3 3 0 100?
*> 10.0.13.0/24 10.0.34.3 0 0 100?
*> 10.1.1.1/32 10.0.24.2 2 0 100i
* 10.0.34.3 1 0 100?
<AR4>dis bgp rout 10.1.1.1
BGP local router ID : 10.0.24.4
Local AS number : 200
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.1/32:
From: 10.0.24.2 (10.0.12.2)
Route Duration: 00h01m32s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.0.24.2
Qos information : 0x0
AS-path 100, origin igp, MED 2, pref-val 0, valid, external, best, select, acti
ve, pre 255
Advertised to such 2 peers:
10.0.24.2
10.0.34.3
BGP routing table entry information of 10.1.1.1/32:
From: 10.0.34.3 (10.0.13.2)
Route Duration: 00h02m36s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.0.34.3
Qos information : 0x0
AS-path 100, origin incomplete, MED 1, pref-val 0, valid, external, pre 255, no
t preferred for Origin
Not advertised to any peer yet
可以看到AR4同时学习到了两条10.1.1.1的路由条目优选了Origin属性为I的路由条目
5、优选AS_Path属性最短的路由
AS_Path属性有两个作用,一个是防止路由环路,一个是选路,当学习到两条一样的路由条目时,优选AS_Path少的。这个实验我们同样可以使用Router-policy来做。

我们通过Router-policy策略使AR2在传递路由时添加两个AS_Path,AR3正常传递路由
AR1
bgp 100
netw 10.1.1.1 32
AR2
ip ip-prefix as index 10 permit 10.1.1.1 32
route-policy as permit node 10
if-match ip-prefix as
apply as-path 300 additive
q
route-policy as permit node 20
q
bgp 100
peer 10.0.24.4 route-policy as export
这里AS_Path设置有三种模式
none Clear as-path list(不管之前携带了多少AS_Path属性统统删除不携带往下进行传递)
additive Append to original As Number(不管之前携带了多少AS_Path属性,在此基础上在添加xxAS_Path属性)
overwrite Overwrite original As Number(不管之前携带了多少AS_Path属性,统统更改为设置好的xxAS_Path属性)
<AR4>dis bgp rout
BGP Local router ID is 10.0.24.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: 5
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 4.4.4.4/32 0.0.0.0 0 0 i
*> 10.0.1.1/32 10.0.34.3 100 0 100i
* 10.0.24.2 200 0 100i
*> 10.1.1.1/32 10.0.34.3 0 100i
* 10.0.24.2 0 100 300i
<AR4>dis bgp rout 10.1.1.1
BGP local router ID : 10.0.24.4
Local AS number : 200
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.1/32:
From: 10.0.34.3 (10.0.13.2)
Route Duration: 00h03m01s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.0.34.3
Qos information : 0x0
AS-path 100, origin igp, pref-val 0, valid, external, best, select, active, pre
255
Advertised to such 2 peers:
10.0.24.2
10.0.34.3
BGP routing table entry information of 10.1.1.1/32:
From: 10.0.24.2 (10.0.12.2)
Route Duration: 00h03m01s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.0.24.2
Qos information : 0x0
AS-path 100 300, origin igp, pref-val 0, valid, external, pre 255, not preferre
d for AS-Path
Not advertised to any peer yet
配置完后AR4发现AR3传递过来的路由AS_Path经过的更少所以优先通过AR3去访问目的网络。
这里其实不建议大家添加AS_Path时添加其他的AS_Path,因为添加了其他的AS_Path比如300,假如网络中有一个AS网络就是AS300,当AS300接收到我们发出去的路由后就会丢弃该路由,因为该路由条目中的AS_Path中已存在了AS300,对方就会以为这是AS300发送出来的则不会接收。
所以一般我们可以添加多个自己所在的AS_Path的AS号,比如这张拓扑中我们AR2属于AS100,那我们可以添加多个100也可以到达选路的效果且不会影响其他AS接收这条路由条目。
6、本地始发的BGP路由优于其他对等体学习到的路由。

这条选路原则,我们还没有学习路由聚合所以这里先不和大家进行讲解,等学习完路由聚合后,我们再详细给大家解释。
7、优选Local_Preference属性最大的路由

该属性我们在实际网络中用的比较多,该属性只能在本地起效,传递给其他AS时不会携带该属性。
该属性一般影响出流量与上面我们介绍的MED刚好相反,并且越大越优,默认为100。MED是在AS间使用的,Local_Preference是在AS内使用的,他们完完全全刚好相反。
<AR1>dis bgp rout
BGP Local router ID is 10.0.12.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: 4
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 4.4.4.4/32 3.3.3.3 0 100 0 200i
* i 2.2.2.2 0 100 0 200i
*> 10.0.1.1/32 0.0.0.0 0 0 i
*> 10.1.1.1/32 0.0.0.0 0 0 i
现在AR1去访问4.4.4.4是优先走AR3,我们通过route-plicy来让AR1优先走AR2去访问4.4.4.4。
AR2
ip ip-prefix local index 10 permit 4.4.4.4 32
route-policy local permit node 10
if-match ip-prefix local
apply local-preference 200
q
route-policy local permit node 20
q
bgp 100
peer 1.1.1.1 route-policy local export
<AR1>dis bgp rout
BGP Local router ID is 10.0.12.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: 4
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 4.4.4.4/32 2.2.2.2 0 200 0 200i
* i 3.3.3.3 0 100 0 200i
*> 10.0.1.1/32 0.0.0.0 0 0 i
*> 10.1.1.1/32 0.0.0.0 0 0 i
<AR1>dis bgp rout 4.4.4.4
BGP local router ID : 10.0.12.1
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 4.4.4.4/32:
From: 2.2.2.2 (10.0.12.2)
Route Duration: 00h00m47s
Relay IP Nexthop: 10.0.12.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 200, pref-val 0, valid, internal, bes
t, select, active, pre 255, IGP cost 2
Not advertised to any peer yet
BGP routing table entry information of 4.4.4.4/32:
From: 3.3.3.3 (10.0.13.2)
Route Duration: 00h20m53s
Relay IP Nexthop: 10.0.13.2
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 3.3.3.3
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre
255, IGP cost 1, not preferred for Local_Pref
Not advertised to any peer yet
修改完后AR1在接收到两条一样的路由条目时,发现AR2传递过来的本地优先级高于AR3传递过来的所以会优先采用AR2传递的路由。
8、优选Preferred-Value属性值最大的路由。 
前面所说的大部分属性都是用来改变别人的选路,如果想要实现改变自己的选路没必要那么麻烦可以直接使用Preferred-Value属性,该属性是华为私有的属性其他厂商没有,该属性只在本地有效,这个本地和Local_Preference属性的本地不一样,Local_Preference的本地是指本地的AS内,Preferred-Value的本地是指本设备,该属性在离开本设备时不会携带该属性。一般只有在想要改变自己的选路原则时使用该属性,该属性默认为0越大越优。
[AR1]dis bgp rout
BGP Local router ID is 10.0.12.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
*>i 4.4.4.4/32 2.2.2.2 0 100 0 200i
* i 3.3.3.3 0 100 0 200i
现在AR1是优先通过AR2去访问4.4.4.4网络的,我们通过配置route-policy修改Preferred-Value属性使AR1优先通过AR3去访问4.4.4.4网络。
AR1
ip ip-prefix pre index 10 permit 4.4.4.4 32
route-policy pre permit node 10
if-match ip-prefix pre
apply preferred-value 100
q
route-policy pre permit node 20
q
bgp 100
peer 3.3.3.3 route-policy pre import
[AR1]dis bgp rout
BGP Local router ID is 10.0.12.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
*>i 4.4.4.4/32 3.3.3.3 0 100 100 200i
* i 2.2.2.2 0 100 0 200i
因为我们是对别人发给我的数据进行添加Preferrd-Value属性所以是入方向,修改完后我们可以看到AR1优先走AR3去访问4.4.4.4网络了。
总结:实际网络当中使用Local_Preference、AS_Path、MED的会比较多一点,Local_Preference是对入流量进行选路,MED是对出流量进行选路,AS_Path对入和出都可以选路,如果只是对本地的路由进行选路的话就可以直接使用Preferrd-Value直接进行选路即可。