local preference值缺省为100(从IBGP学习)和0(从EBGP学习),local preference只在AS内部传递,不能传递给EBGP,local preference值越大越优先。
1.R1配置OSPF
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.255.255.255
2.R2配置OSPF
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.255.255.255
3.R1配置IBGP、EBGP
[R1]bgp 12
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 2.2.2.2 as-number 12
[R1-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[R1-bgp]peer 2.2.2.2 next-hop-local
[R1-bgp]peer 13.1.1.3 as-number 300
4.R2配置IBGP、EBGP
[R2]bgp 12
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 1.1.1.1 as-number 12
[R2-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[R2-bgp]peer 1.1.1.1 next-hop-local
[R2-bgp]peer 23.1.1.3 as-number 300
5.R3配置EBGP,宣告3.3.3.3/32到BGP
[R3]bgp 300
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 13.1.1.1 as-number 12
[R3-bgp]peer 23.1.1.2 as-number 12
[R3-bgp]network 3.3.3.3 32
6.R1查看BGP路由信息,AR2对应LocPrf为100,AR2对应LocPrf为0(EBGP学习到条目不带local preference值)
<R1>display bgp routing-table
Total Number of Routes: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 3.3.3.3/32 13.1.1.3 0 0 300i
* i 2.2.2.2 0 100 0 300i
7.R1查看BGP路由信息(3.3.3.3/32),从R3学习
<R1>display bgp routing-table 3.3.3.3
BGP local router ID : 1.1.1.1
Local AS number : 12
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 3.3.3.3/32:
From: 13.1.1.3 (3.3.3.3)
Route Duration: 00h38m12s
Direct Out-interface: GigabitEthernet0/0/2
Original nexthop: 13.1.1.3
Qos information : 0x0
AS-path 300, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 1 peers:
2.2.2.2
BGP routing table entry information of 3.3.3.3/32:
From: 2.2.2.2 (2.2.2.2)
Route Duration: 00h25m18s
Relay IP Nexthop: 12.1.1.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 300, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for peer type
Not advertised to any peer yet
8.使用策略方法修改local preference值
[R1]ip ip-prefix dsrw.com permit 3.3.3.3 32
[R1]route-policy dsrw permit node 10
[R1-route-policy]if-match ip-prefix dsrw.com
[R1-route-policy]apply local-preference 200
[R1-route-policy]quit
[R1]route-policy dsrw permit node 20
[R1]bgp 12
[R1-bgp]peer 2.2.2.2 route-policy dsrw import
9.查看BGP路由信息
<R1>refresh bgp all import
<R1>display bgp routing-table
*>i 3.3.3.3/32 2.2.2.2 0 200 0 300i
* 13.1.1.3 0 0 300i
<R1>display bgp routing-table 3.3.3.3
BGP local router ID : 1.1.1.1
Local AS number : 12
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 3.3.3.3/32:
From: 2.2.2.2 (2.2.2.2)
Route Duration: 00h00m30s
Relay IP Nexthop: 12.1.1.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path 300, origin igp, MED 0, localpref 200, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1
Advertised to such 1 peers:
13.1.1.3
BGP routing table entry information of 3.3.3.3/32:
From: 13.1.1.3 (3.3.3.3)
Route Duration: 00h00m30s
Direct Out-interface: GigabitEthernet0/0/2
Original nexthop: 13.1.1.3
Qos information : 0x0
AS-path 300, origin igp, MED 0, pref-val 0, valid, external, pre 255, not preferred for Local_Pref
Not advertised to any peer yet
10.删除使用策略方法修改local preference值方法
[R1]bgp 12
[R1-bgp]undo peer 2.2.2.2 route-policy dsrw import
[R1]undo route-policy dsrw
[R1]undo ip ip-prefix dsrw.com
//删除使用策略方法修改local preference值方法
11.使用直接修改local preference值方法,查看BGP路由,没有从R2学习到路由
[R1]bgp 12
[R1-bgp]default local-preference 300
[R1]display bgp routing-table
*> 3.3.3.3/32 13.1.1.3 0 0 300i
12.查看R2的BGP路由表,R2从R1学习到了3.3.3.3/32路由,没有再回传给R1
<R2>display bgp routing-table
*>i 3.3.3.3/32 1.1.1.1 0 300 0 300i
* 23.1.1.3 0 0 300i
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后查看评论内容