要求:
1、使用preval策略,確保R4通過R2到達192.168.10.0/24
2、使用AS Path策略,確保R4通過R3到達192.168.11.0/24
3、配置MED策略,確保R4通過R3到達192.168.12.0/24
4、使用Local Preference策略,確保R1通過R2到達192.168.1.0/24
5、使用Local Preference策略,確保R1通過R3到達192.168.2.0/24
6、配置負載均衡,確保R1通過R2和R3到達192.168.3.0/24
7、使用As策略,AS 500不接受任何始發于AS 123的路由
8、使用自定義Community策略,確保192.168.3.0/24路由不會被發布到AS 500
9、IBGP使用環回接口建鄰,EBGP使用物理接口建鄰
10、修改AS 123中的用戶網段為Broadcast,方便后續在BGP中宣告
11、BGP宣告路由時,僅宣告24網段的用戶路由
做法:
首先,配置IP和環回地址
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip ad 12.0.0.1 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip ad 13.0.0.1 24
[R1-GigabitEthernet0/0/1]int g0/0/2
[R1-GigabitEthernet0/0/2]ip ad 15.0.0.1 24
[R1-GigabitEthernet0/0/2]int l 0
[R1-LoopBack0]ip ad 1.1.1.1 32
[R1-LoopBack0]int l 1
[R1-LoopBack1]ip ad 192.168.100.1 24
[R1-LoopBack1]ospf network-type broadcast
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip ad 24.0.0.2 24
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip ad 12.0.0.2 24
[R2-GigabitEthernet0/0/1]int l 0
[R2-LoopBack0]ip ad 2.2.2.2 32
[R2-LoopBack0]int l 1
[R2-LoopBack1]ip ad 192.168.20.1 24
[R2-LoopBack1]ospf network-type? broadcast
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip ad 34.0.0.3 24
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip ad 13.0.0.3 24
[R3-GigabitEthernet0/0/1]int l 0
[R3-LoopBack0]ip ad 3.3.3.3 32
[R3-LoopBack0]int l 1
[R3-LoopBack1]ip ad 192.168.30.1 24
[R3-LoopBack1]ospf network-type? broadcast
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ip ad 24.0.0.4 24
[R4-GigabitEthernet0/0/0]int g0/0/1
[R4-GigabitEthernet0/0/0]ip ad 34.0.0.4 24
[R4-GigabitEthernet0/0/0]int l 0
[R4-LoopBack0]ip ad 192.168.1.1 24
[R4-LoopBack0]int l 1
[R4-LoopBack1]ip ad 192.168.2.1 24
[R4-LoopBack1]int l 2
[R4-LoopBack2]ip ad 192.168.3.1 24
[R5]int g0/0/0
[R5-GigabitEthernet0/0/0]ip ad 15.0.0.5 24
[R5-GigabitEthernet0/0/0]int l 0
[R5-LoopBack0]ip ad 192.168.10.1 24
[R5-LoopBack0]int l 1
[R5-LoopBack1]ip ad 192.168.11.1 24
[R5-LoopBack1]int l 2
[R5-LoopBack2]ip ad 192.168.12.1 24
隨后,測試是否互通,若可以,進入下一步
隨后,配置ospf,搭建IGP
[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.0.0.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 13.0.0.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network? 192.168.100.1 0.0.0.0
[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.0.0.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 192.168.20.1 0.0.0.0
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 13.0.0.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 192.168.30.1 0.0.0.0
隨后,配置BGP
[R1]bgp 123
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 15.0.0.5 as-number 500
[R1-bgp]peer 2.2.2.2 as-number 123?? ?
[R1-bgp]peer 2.2.2.2 connect-interface l0
[R1-bgp]peer 2.2.2.2 next-hop-local
[R1-bgp]peer 3.3.3.3 as-number 123?? ?
[R1-bgp]peer 3.3.3.3 connect-interface l0
[R1-bgp]peer 3.3.3.3 next-hop-local
[R2]bgp 123
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 24.0.0.4 as-number 400
[R2-bgp]peer 1.1.1.1 as-number 123
[R2-bgp]peer 1.1.1.1 connect-interface l0
[R2-bgp]peer 1.1.1.1 next-hop-local
?
[R3]bgp 123
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 34.0.0.4 as-number 400
[R3-bgp]peer 1.1.1.1 as-number 123
[R3-bgp]peer 1.1.1.1 connect-interface l0
[R3-bgp]peer 1.1.1.1 next-hop-local
?
???
[R4]bgp 400
[R4-bgp]router-id 4.4.4.4?? ?
[R4-bgp]peer 24.0.0.2 as-number 123
[R4-bgp]peer 34.0.0.3 as-number 123
?
[R5]bgp 500
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 15.0.0.1 as-number 123
隨后,使用preval策略,確保R4通過R2到達192.168.10.0 24
??? [R4]ip ip-prefix PV permit 192.168.10.0 24
??? [R4]route-policy PV permit node 10
??? [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
??? [R4-route-policy]q
??? [R4]bgp 400
??? [R4-bgp]peer 24.0.0.2 route-policy PV import
?
??? display bgp routing-table 192.168.10.0
使用AS Path策略,確保R4通過R3到達192.168.11.0/24
???????? AS-Path屬性越短則該路由越優,因為這條路徑距離目的地所要經過的AS個數更少。
???????? AS_Path屬性最開始是空的列表,當該路由被通告給一個EBGP對等體鄰居時,才會被加上一個AS號,在每次經過一個AS時,都會在AS_Path屬性的最前端增加最新的AS號。
??????????? 而該屬性在IBGP對等體之間傳播時,這條屬性是不會發生改變
R4配置
??? [R4]ip ip-prefix AS permit 192.168.11.0 24
??? [R4]route-policy AS permit node 10
??? [R4-route-policy]if-match ip-prefix AS
??? [R4-route-policy]apply as-path 123 123 500 overwrite
??? [R4-route-policy]q
??? ?
??? [R4]bgp 400
??? [R4-bgp]peer 24.0.0.2 route-policy AS import
??? 當然,我們也可以使用方法二
??? [R4]ip ip-prefix AS permit 192.168.11.0 24
??? [R4]route-policy PV permit node 15
??? [R4-route-policy]if-match ip-prefix PV
??? [R4-route-policy]apply as-path 123 123 500 overwrite
??? [R4-route-policy]q
??? 不需要調用,因為PV已經調用過了
???
配置MED策略,確保R4通過R3到達192.168.12.0/24
?
??????? MED值是繼承了IGP協議的度量值。
??????? MED屬性值可以傳遞給自己的EBGP對等體,并且該EBGP對等體可以將該路由傳遞給
IBGP對等體,并且因為AS-BY-AS規則,該屬性在IBGP對等體之間傳遞時不變。
??????? MED屬性可以干擾訪問本地的流量的走向。也就是說,本AS的策略調整可以影響到別的AS對路徑的判斷,這是在BGP選路中唯一一個可以影響到其他AS的屬性
??????????? 即MED是干涉其他的設備,所以MED不在R4上配置
??????? BGP規定,非本地始發的BGP路由信息,在傳遞給自己的EBGP對等體時,將MED值修改為0。
R2配置
??? [R2]ip ip-prefix MED permit 192.168.12.0 24
??? [R2]route-policy MED permit node 10
??? [R2-route-policy]if-match ip-prefix MED
??? [R2-route-policy]apply cost 200
??? [R2-route-policy]q
??? [R2]route-policy MED permit node 20
??? ?
??? [R2]bgp 123
??? [R2-bgp]peer 24.0.0.4 route-policy MED export
R3配置
??? [R3]ip ip-prefix MED permit 192.168.12.0 24
??? [R3]route-policy MED permit node 10
??? [R3-route-policy]if-match ip-prefix MED
??? [R3-route-policy]apply cost 20
??? [R3-route-policy]q
??? [R3]route-policy MED permit node 20
??? ?
??? [R3]bgp 123
??? [R3-bgp]peer 34.0.0.4 route-policy MED export
使用Local Preference策略,確保R1通過R2到達192.168.1.0/24
??????? 該屬性的默認值為100,并且LP屬性只能在IBGP對等體之間傳遞,而不能在EBGP對等體之間傳遞。
??????? 如果路由在傳遞到本地時并不攜帶LP屬性,則BGP在決策時,使用缺省值來計算。
??????? 該屬性越大越優。
??????? 該屬性的傳遞范圍為本AS內部。
??????? 該屬性是AS內部優選路由的最佳選擇。
R1配置
??? [R1]ip ip-prefix LP1 permit 192.168.1.0 24
??? [R1]route-policy LP1 permit node 10
??? [R1-route-policy]if-match ip-prefix LP1
??? [R1-route-policy]apply local-preference 200
??? [R1-route-policy]q
??? [R1]route-policy LP1 permit node 20
??? ?
??? [R1]bgp 123
??? [R1-bgp]peer 2.2.2.2 route-policy LP1 import
使用Local Preference策略,確保R1通過R3到達192.168.2.0/24
??? [R1]ip ip-prefix LP2 permit 192.168.2.0 24
??? [R1]route-policy LP2 permit node 10
??? [R1-route-policy]if-match ip-prefix LP2
??? [R1-route-policy]apply local-preference 200
??? [R1-route-policy]q
??? [R1]route-policy LP2 permit node 20
??? ?
??? [R1]bgp 123
??? [R1-bgp]peer 3.3.3.3 route-policy LP2 import
配置負載均衡,確保R1通過R2和R3到達192.168.3.0/24
R1配置
??? [R1]bgp 123
??? [R1-bgp]maximum load-balancing 2
使用As策略,AS 500不接受任何始發于AS 123的路由
R1配置
??? 方法一:
??? [R5]ip as-path-filter 1 deny? ^123$
??? [R5]ip as-path-filter 1 permit .*
??? ?
??? [R5]bgp 500
??? [R5-bgp]peer 15.0.0.1 as-path-filter 1 import
??? 方法二:
??? [R1]ip as-path-filter 1 deny ^$??? 抓空列表
??? [R1]ip as-path-filter 1 permit .*
??? ?
??? [R1]bgp 123
??? [R1-bgp]peer 15.0.0.5 as-path-filter 1 export
使用自定義Community策略,確保192.168.3.0/24路由不會被發布到AS 500
自定義Community策略
打上社團屬性標記和打開社團屬性傳播功能
R4配置
??? [R4]route-policy com permit node 10
??? [R4-route-policy]apply community 400:500
??? ?
??? [R4]bgp 400
??? [R4-bgp]network 192.168.3.0 24 route-policy com
??? [R4-bgp]peer 24.0.0.2 advertise-community
??? [R4-bgp]peer 34.0.0.3 advertise-community
R2配置
??? [R2]bgp 123
??? [R2-bgp]peer 1.1.1.1 advertise-community
R3配置
??? [R3]bgp 123
??? [R3-bgp]peer 1.1.1.1 advertise-community
R1配置
??? [R1]bgp 123
??? [R1-bgp]peer 15.0.0.5 advertise-community
社團屬性過濾器
R1配置
??? [R1]ip community-filter 1 permit 400:500
??? [R1]route-policy com deny node 10
??? [R1-route-policy]if-match community-filter 1
??? [R1-route-policy]q
??? [R1]route-policy com permit node 20
??? ?
??? [R1]bgp 123
??? [R1]peer 15.0.0.5 route-policy com export
至此,實驗完成。