R1跟R5 都有192.168.1.0跟192.168.2.0这两条路由
希望通过修改BGP的loal-pref属性
1.去192.168.1.0时走R1
2.去192.168.2.0时走R5
拓扑图如下
R1
bgp 1
peer 10.1.12.2 as-number 234
#
ipv4-family unicast
undo synchronization
import-route static
peer 10.1.12.2 enable
#
ip route-static 192.168.1.0 255.255.255.0 NULL0
ip route-static 192.168.2.0 255.255.255.0 NULL0
R2
bgp 234
peer 10.1.12.1 as-number 1
peer 10.1.23.3 as-number 234
peer 10.1.34.4 as-number 234
#
ipv4-family unicast
undo synchronization
peer 10.1.12.1 enable
peer 10.1.12.1 route-policy local import
peer 10.1.23.3 enable
peer 10.1.23.3 next-hop-local
peer 10.1.34.4 enable
peer 10.1.34.4 next-hop-local
#
route-policy local permit node 10
if-match ip-prefix 1
apply local-preference 200
#
ip ip-prefix 1 index 10 permit 192.168.1.0 24
R4
bgp 234
peer 10.1.23.2 as-number 234
peer 10.1.34.3 as-number 234
peer 10.1.45.5 as-number 5
#
ipv4-family unicast
undo synchronization
peer 10.1.23.2 enable
peer 10.1.23.2 next-hop-local
peer 10.1.34.3 enable
peer 10.1.34.3 next-hop-local
peer 10.1.45.5 enable
peer 10.1.45.5 route-policy local import
#
route-policy local permit node 20
if-match ip-prefix 2
apply local-preference 200
#
ip ip-prefix 2 index 10 permit 192.168.2.0 24
R5
bgp 5
peer 10.1.45.4 as-number 234
#
ipv4-family unicast
undo synchronization
import-route static
peer 10.1.45.4 enable
#
ip route-static 192.168.1.0 255.255.255.0 NULL0
ip route-static 192.168.2.0 255.255.255.0 NULL0