學習新思想,爭做新青年,今天學習的是BGP路徑選擇Community
實驗目的
·理解團體屬性的概念與作用
·熟悉運用團體屬性來控制路由傳遞的方法
·理解 No-Export、No-Advertise、No-Export-Subconfed 屬性的區別
實驗內容
本實驗網絡中,R1 屬於 AS 100,R2、R3 和 R4
屬於 AS 編號為 200 的一個聯盟,R5 屬於 AS 300。在聯盟 AS 200 中,R2 和 R4 屬於成員 AS 2001,R3
屬於成員 AS 2002,整個聯盟內使用 OSPF 作為 IGP。全網路由器都使用直連接口建立 BGP 鄰居關係,R1 上的 Loopback
1~Loopback 5 接口用來模擬 AS 100 需要傳遞的路由信息。
網絡管理員需要利用 BGP 團體屬性來實現下面的需求:
①.10.0.100.2/32 這條路由信息只能夠被 AS 200 的路由器接收到,不能夠被 AS 300 中的路由器接收到;
②.10.0.100.3/32 這條路由信息只能夠被成員 AS 2001 的路由器接收到,不能被成員 AS 2002 以及 AS 300 的路由器接收到;
③.10.0.100.4/32 這條路由信息只能夠被 R2 接收到,不能被其他路由器接收到;
④.10.0.100.5/32 這條路由信息只能夠被 R2 和 R3 接收到,不能被其他路由器接收到。
實驗拓撲
實驗配置
1、基本配置
R1:
sys
sysname R1
int loop 0
ip add 10.0.1.1 32
int loop 1
ip add 10.0.100.1 32
int loop 2
ip add 10.0.100.2 32
int loop 3
ip add 10.0.100.3 32
int loop 4
ip add 10.0.100.4 32
int loop 5
ip add 10.0.100.5 32
int g0/0/0
ip add 10.0.12.1 24
q
R2:
sys
sysname R2
int loop 0
ip add 10.0.2.2 32
int g0/0/0
ip add 10.0.12.2 24
int g0/0/1
ip add 10.0.23.2 24
int g0/0/2
ip add 10.0.24.2 24
q
R3:
sys
sysname R3
int loop 3
ip add 10.0.3.3 32
int g0/0/1
ip add 10.0.23.3 24
q
R4:
sys
sysname R4
int loop 0
ip add 10.0.4.4 32
int g0/0/2
ip add 10.0.24.4 24
int g0/0/0
ip add 10.0.45.4 24
q
R5:
sys
sysname R5
int loop 0
ip add 10.0.5.5 32
int g0/0/0
ip add 10.0.45.5 24
q
2.配置BGP路由協議
先在AS 200內進行OSPF協議的配置。
[R2]ospf 1 router-id 10.0.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.23.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 10.0.24.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[R3]ospf 1 router-id 10.0.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.23.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 10.0.3.3 0.0.0.0
[R4]ospf 1 router-id 10.0.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 10.0.24.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]network 10.0.4.4 0.0.0.0
接下來在每一台路由器上配置 BGP 協議,其中 R1 屬於 AS 100,R2 和 R4 屬於聯盟 AS 200 的成員 AS 2001,R3 屬於聯盟 AS 200 的成員 AS 2002,R5 屬於 AS 300。
[R1]bgp 100
[R1-bgp]router-id 10.0.1.1
[R1-bgp]peer 10.0.12.2 as-number 200
[R1-bgp]network 10.0.100.1 32
[R1-bgp]network 10.0.100.2 32
[R1-bgp]network 10.0.100.3 32
[R1-bgp]network 10.0.100.4 32
[R1-bgp]network 10.0.100.5 32
[R2]bgp 2001
[R2-bgp]router-id 10.0.2.2
[R2-bgp]confederation id 200
[R2-bgp]confederation peer-as 2002
[R2-bgp]peer 10.0.23.3 as-number 2002
[R2-bgp]peer 10.0.23.3 next-hop-local
[R2-bgp]peer 10.0.24.4 as-number 2001
[R2-bgp]peer 10.0.24.4 next-hop-local
[R2-bgp]peer 10.0.12.1 as-number 100
[R3]bgp 2002
[R3-bgp]router-id 10.0.3.3
[R3-bgp]confederation id 200
[R3-bgp]confederation peer-as 2001
[R3-bgp]peer 10.0.23.2 as-number 2001
[R4]bgp 2001
[R4-bgp]router-id 10.0.4.4
[R4-bgp]confederation id 200
[R4-bgp]peer 10.0.24.2 as-number 2001
[R4-bgp]peer 10.0.24.2 next-hop-local
[R4-bgp]peer 10.0.45.5 as-number 300
[R5]bgp 300
[R5-bgp]router-id 10.0.5.5
[R5-bgp]peer 10.0.45.4 as-number 200
3.使用 No_Export 團體屬性控制路由信息傳遞
接下來的需求是:10.0.100.2/32這條路由信息只能夠被聯盟AS200中的路由器接收到,而不能夠被AS300中的路由器接收到。
利用團體屬性No_Export來滿足這個需求,因為路由器接收到一條攜帶No-Export團體屬性的路由後,不會將它發佈給 EBGP對等體,但可以發佈給聯盟EBGP對等體。
在R1上使用前綴列表方法來匹配路由10.0.100.2/32。
[R1]ip ip-prefix 1 permit 10.0.100.2 32
在R1上創建Route-Policy。
[R1]route-policy 1 permit node 10
[R1-route-policy]if-match ip-prefix 1
[R1-route-policy]apply community no-export
[R1-route-policy]route-policy 1 permit node 20
在R1上調用Route-Policy。
[R1]bgp 100
[R1-bgp]peer 10.0.12.2 route-policy 1 export
在缺省情況下,路由器向BGP對等體傳遞路由信息時不會攜帶團體屬性。
在R1的BGP視圖下增加如下的配置,使得R1在向R2傳遞BGP路由信息時攜帶團體屬性。
[R1-bgp]peer 10.0.12.2 advertise-community
在R2、R4上增加同樣的配置,使得R2在向R3和R4傳遞BGP路由信息時攜帶團體屬性,並且R4在向R5傳遞BGP路由信息時也攜帶團體屬性。
[R2-bgp]peer 10.0.23.3 advertise-community
[R2-bgp]peer 10.0.24.4 advertise-community
[R4-bgp]peer 10.0.45.5 advertise-community
4.使用 No_Export_Subconfed 團體屬性控制路由信息傳遞
接下來的需求是:10.0.100.3/32 這條路由信息只能夠被聯盟 AS 200 的成員 AS 2001 中的路由器收到,而不能夠被成員 AS 2002 以及 AS 300 中的路由器收到。
可以利用團體屬性 No_Export_Subconfed 來滿足這個需求,因為路由器接收到一條攜帶 No-Export-Subconfed 團體屬性的路由後,不會將它發佈給 EBGP 對等體,也不會將它發佈給聯盟 EBGP 對等體。
在 R1 上使用前綴列表方法來匹配路由 10.0.100.3/32。
[R1]ip ip-prefix 2 permit 10.0.100.3 32
在 R1 上創建新的路由策略的 Node。
[R1]route-policy 1 permit node 11
[R1-route-policy]if-match ip-prefix 2
[R1-route-policy]apply community no-export-subconfed
5.使用 No_Advertise 團體屬性控制路由信息傳遞
接下來的需求是: 10.0.100.4/32 這條路由信息只能夠被 R2 接收到,而不能被其他路由器接收到。
可以利用團體屬性 No_Advertise 來滿足這個需求, 因為路由器接收 到一條攜帶 No-Advertise 團體屬性的路由後,不會將它發佈給任何 BGP 對等體。
在 R1上使用前綴列表方法來匹配路由 10.0.100.4/32。
[R1]ip ip-prefix 3 permit 10.0.100.4 32
在 R1 上創建新的路由策略的 Node。
[R1]route-policy 1 permit node 12
[R1-route-policy]if-match ip-prefix 3
[R1-route-policy]apply community no-advertise
6.使用自定義團體屬性控制路由信息傳遞
接下來的需求是:10.0.100.5/32 這條路由信息只能夠被 R2 和 R3 接收到,而不能被 R4 和 R5 接收到。為路由信息添加自定義團體屬性,然後通過匹配自定義團體屬性來控制路由信息的傳遞。
在 R1 上使用前綴列表方法來匹配路由 10.0.100.5/32。
[R1]ip ip-prefix 4 permit 10.0.100.5 32
在 R1 上創建新的路由策略的 Node。
[R1]route-policy 1 permit node 13
[R1-route-policy]if-match ip-prefix 4
[R1-route-policy]apply community 100:1
由於R2、R3、R4和R5都接收到了10.0.100.5/32這條路由信息,這説明需求並沒有得到實現。
自定義團體屬性在缺省情況下沒有相應的動作,僅僅是為路由信息添加了標識而已。
在R4上匹配自定義團體屬性為100:1的路由。
[R4]ip community-filter 1 permit 100:1
然後在R4上創建Route-Policy。
[R4]route-policy 1 deny node 10
[R4-route-policy]if-match community-filter 1
[R4-route-policy]route-policy 1 permit node 20
R4在接收R2傳遞過來的路由時調用Route-Policy。
[R4]bgp 2001
[R4-bgp]peer 10.0.24.2 route-policy 1 import