实验拓扑

实验要求
- 实现通过修改AS-Path属性来影响路径选择
- 实现通过修改Local_Preference属性来影响路径选择
- 实现通过修改MED属性来影响路径选择
- 实现通过修改preferred-value属性来影响路径选择
实验配置与效果
1.改名与IP配置
2.as300配置OSPF
R3已经学到R2和R4的路由

3.配置BGP
查看R4和R2确保全部peer成功建立,值得注意的是,由于ospf没有宣告AS300和其他两个区域间的信息,在R2和R4上搭建10.0.3.3的peer时,需要将下一跳修改为本地


上述操作省略,仅贴出配置图
4.发布路由
[R1]bgp 100
[R1-bgp]net 172.16.1.0 24
[R1-bgp]net 172.16.2.0 24
[R1-bgp]net 172.16.3.0 24
[R1-bgp]net 172.16.4.0 24
[R5]bgp 200
[R5-bgp]net 172.16.1.0 24
[R5-bgp]net 172.16.2.0 24
[R5-bgp]net 172.16.3.0 24
[R5-bgp]net 172.16.4.0 24

修改AS_Path
创建前缀列表匹配相关流量,用路由策略修改172.16.1.0的as-path,最后在R1的出口方向调用路由策略,实现修改,这里我 选择添加as-path400 500,值得注意的是,路由策略需要写一条空语句以放行其他路由信息

打入refresh bgp all export 刷新下R1bgp路由的出方向,在R3路由器上查看相关路由可见其as-path加上了500 和 400

还是R3,可以看到其优选R4的路径

修改Local_Preference属性
同上创建路由策略修改指定参数,同样的,bgp调用将要发送给R3的172.16.2.0的路由local_preference修改为200

同样查看表项,来自R4的路由被优选


修改MED属性
修改MED由于其继承上个区域的cost,因此只要在边界设备修改cost即可
值得注意的是这里要使用import刷新的时候也是一样,同时还需要在R3上开启med比较
使用此条命令打开compare-different-as-med

打开R3查看信息,ok的老弟,也是选上了R4


修改preferred-value属性
同理,在R3上修改preferred-value值,在R3的bgp上对来自R4的import方向调用相关策略
刷新路由表,查看R3路由信息

可见路由优选R4,值也被改为300


相关配置
R1
interface LoopBack0
ip address 10.0.1.1 255.255.255.255
#
interface LoopBack1
ip address 172.16.1.1 255.255.255.0
#
interface LoopBack2
ip address 172.16.2.1 255.255.255.0
#
interface LoopBack3
ip address 172.16.3.1 255.255.255.0
#
interface LoopBack4
ip address 172.16.4.1 255.255.255.0
#
bgp 100
router-id 10.0.1.1
peer 10.0.12.2 as-number 300
#
ipv4-family unicast
undo synchronization
network 172.16.1.0 255.255.255.0
network 172.16.2.0 255.255.255.0
network 172.16.3.0 255.255.255.0
network 172.16.4.0 255.255.255.0
peer 10.0.12.2 enable
peer 10.0.12.2 route-policy as export
#
route-policy as permit node 10
if-match ip-prefix 1
apply as-path 500 400 additive
#
route-policy as permit node 20
#
ip ip-prefix 1 index 10 permit 172.16.1.0 24 greater-equal 24 less-equal 24
R2
interface GigabitEthernet0/0/0
ip address 10.0.12.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.23.2 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 10.0.2.2 255.255.255.255
#
bgp 300
router-id 10.0.2.2
peer 10.0.3.3 as-number 300
peer 10.0.3.3 connect-interface LoopBack0
peer 10.0.12.1 as-number 100
#
ipv4-family unicast
undo synchronization
peer 10.0.3.3 enable
peer 10.0.3.3 next-hop-local
peer 10.0.12.1 enable
peer 10.0.12.1 route-policy med import
#
ospf 1 router-id 10.0.2.2
area 0.0.0.0
network 10.0.2.2 0.0.0.0
network 10.0.23.2 0.0.0.0
#
route-policy med permit node 10
if-match ip-prefix 1
apply cost 200
#
route-policy med permit node 20
#
ip ip-prefix 1 index 10 permit 172.16.3.0 24 greater-equal 24 less-equal 24
#
R3
interface GigabitEthernet0/0/0
ip address 10.0.23.3 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.34.3 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 10.0.3.3 255.255.255.255
#
bgp 300
router-id 10.0.3.3
peer 10.0.2.2 as-number 300
peer 10.0.2.2 connect-interface LoopBack0
peer 10.0.4.4 as-number 300
peer 10.0.4.4 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
compare-different-as-med
peer 10.0.2.2 enable
peer 10.0.4.4 enable
peer 10.0.4.4 route-policy pv import
#
ospf 1 router-id 10.0.3.3
area 0.0.0.0
network 10.0.3.3 0.0.0.0
network 10.0.23.3 0.0.0.0
network 10.0.34.3 0.0.0.0
#
route-policy pv permit node 10
if-match ip-prefix 1
apply preferred-value 300
#
route-policy pv permit node 20
#
ip ip-prefix 1 index 10 permit 172.16.4.0 24 greater-equal 24 less-equal 24
#
R4
#
interface GigabitEthernet0/0/0
ip address 10.0.34.4 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.45.4 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 10.0.4.4 255.255.255.255
#
bgp 300
router-id 10.0.4.4
peer 10.0.3.3 as-number 300
peer 10.0.3.3 connect-interface LoopBack0
peer 10.0.45.5 as-number 200
#
ipv4-family unicast
undo synchronization
peer 10.0.3.3 enable
peer 10.0.3.3 route-policy lp export
peer 10.0.3.3 next-hop-local
peer 10.0.45.5 enable
#
ospf 1 router-id 10.0.4.4
area 0.0.0.0
network 10.0.4.4 0.0.0.0
network 10.0.34.4 0.0.0.0
#
route-policy lp permit node 10
if-match ip-prefix 1
apply local-preference 200
#
route-policy lp permit node 20
#
ip ip-prefix 1 index 10 permit 172.16.2.0 24 greater-equal 24 less-equal 24
#
R5
interface GigabitEthernet0/0/0
ip address 10.0.45.5 255.255.255.0
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 10.0.5.5 255.255.255.255
#
interface LoopBack1
ip address 172.16.1.1 255.255.255.0
#
interface LoopBack2
ip address 172.16.2.1 255.255.255.0
#
interface LoopBack3
ip address 172.16.3.1 255.255.255.0
#
interface LoopBack4
ip address 172.16.4.1 255.255.255.0
#
bgp 200
router-id 10.0.5.5
peer 10.0.45.4 as-number 300
#
ipv4-family unicast
undo synchronization
network 172.16.1.0 255.255.255.0
network 172.16.2.0 255.255.255.0
network 172.16.3.0 255.255.255.0
network 172.16.4.0 255.255.255.0
peer 10.0.45.4 enable
#