实验拓扑图如下:
配置接口IP地址、环回
[R1]int GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.0.0.1 24
[R1-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 13.0.0.1 24
[R1-GigabitEthernet0/0/1]q
[R1]int l0
[R1-LoopBack0]ip add 1.1.1.1 32
[R1-LoopBack0]q
[R2]int GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R2-GigabitEthernet0/0/0]int g
[R2-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 24.0.0.1 24
[R2-GigabitEthernet0/0/1]q
[R2]int l0
[R2-LoopBack0]ip add 2.2.2.2 32
[R2-LoopBack0]q
[R3]int GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip add 13.0.0.2 24
[R3-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip add 34.0.0.1 24
[R3-GigabitEthernet0/0/1]q
[R3]int l0
[R3-LoopBack0]ip add 3.3.3.3 32
[R3-LoopBack0]q
[R4]int GigabitEthernet 0/0/0
[R4-GigabitEthernet0/0/0]ip add 24.0.0.2 24
[R4-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R4-GigabitEthernet0/0/1]ip add 34.0.0.2 24
[R4-GigabitEthernet0/0/1]int GigabitEthernet 0/0/2
[R4-GigabitEthernet0/0/2]ip add 45.0.0.1 24
[R4-GigabitEthernet0/0/2]int GigabitEthernet 3/0/0
[R4-GigabitEthernet3/0/0]ip add 46.0.0.1 24
[R4-GigabitEthernet3/0/0]q
[R4]int l0
[R4-LoopBack0]ip add 4.4.4.4 32
[R4-LoopBack0]q
[R5]int GigabitEthernet 0/0/0
[R5-GigabitEthernet0/0/0]ip add 45.0.0.2 24
[R5-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R5-GigabitEthernet0/0/1]ip add 57.0.0.1 24
[R5-GigabitEthernet0/0/1]q
[R5]int l0
[R5-LoopBack0]ip add 5.5.5.5 32
[R5-LoopBack0]q
[R6]int GigabitEthernet 0/0/0
[R6-GigabitEthernet0/0/0]ip add 46.0.0.2 24
[R6-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R6-GigabitEthernet0/0/1]ip add 67.0.0.1 24
[R6-GigabitEthernet0/0/1]q
[R6]int l0
[R6-LoopBack0]ip add 6.6.6.6 32
[R6-LoopBack0]q
[R7]int GigabitEthernet 0/0/0
[R7-GigabitEthernet0/0/0]ip add 57.0.0.2 24
[R7-GigabitEthernet0/0/0]int GigabitEthernet 0/0/1
[R7-GigabitEthernet0/0/1]ip add 67.0.0.2 24
[R7-GigabitEthernet0/0/1]q
[R7]int l0
[R7-LoopBack0]ip add 7.7.7.7 32
[R7-LoopBack0]q
建邻
IBGP建邻使用环回所以先保证环回能正常访问
宣告
[R1]ospf
[R1-ospf-1]a 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.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 13.0.0.0 0.0.0.255
[R2]ospf
[R2-ospf-1]a 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.0 0.0.0.255
[R3-ospf-1]a 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 13.0.0.0 0.0.0.255
[R5]ospf
[R5-ospf-1]a 0
[R5-ospf-1-area-0.0.0.0]network 5.5.5.5 0.0.0.0
[R5-ospf-1-area-0.0.0.0]network 57.0.0.0 0.0.0.255
[R6]ospf
[R6-ospf-1]a 0
[R6-ospf-1-area-0.0.0.0]network 6.6.6.6 0.0.0.0
[R6-ospf-1-area-0.0.0.0]network 67.0.0.0 0.0.0.255
[R7]ospf
[R7-ospf-1]a 0
[R7-ospf-1-area-0.0.0.0]network 7.7.7.7 0.0.0.0
[R7-ospf-1-area-0.0.0.0]network 57.0.0.0 0.0.0.255
[R7-ospf-1-area-0.0.0.0]network 67.0.0.0 0.0.0.255
as1建立IBGP邻居
[R1]bgp 1
[R1-bgp]group IBGP
[R1-bgp]peer IBGP connect-interface l0
[R1-bgp]peer 2.2.2.2 group IBGP
[R1-bgp]peer 3.3.3.3 group IBGP
[R1-bgp]network 1.1.1.1 32
[R2]bgp 1
[R2-bgp]group IBGP
[R2-bgp]peer IBGP connect-interface l0
[R2-bgp]peer IBGP next-hop-local
[R2-bgp]peer 1.1.1.1 group IBGP
[R2-bgp]peer 3.3.3.3 group IBGP
[R2-bgp]network 2.2.2.2 32
[R3]bgp 1
[R3-bgp]group IBGP
[R3-bgp]peer IBGP connect-interface l0
[R3-bgp]peer IBGP next-hop-local
[R3-bgp]peer 1.1.1.1 group IBGP
[R3-bgp]peer 2.2.2.2 group IBGP
[R3-bgp]network 3.3.3.3 32
查看
[R1]display bgp routing-table
BGP Local router ID is 12.0.0.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 0.0.0.0 0 0 i
i 2.2.2.2/32 2.2.2.2 0 100 0 i
i 3.3.3.3/32 3.3.3.3 0 100 0 i
[R2]display bgp routing-table
BGP Local router ID is 12.0.0.2
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
i 1.1.1.1/32 1.1.1.1 0 100 0 i
*> 2.2.2.2/32 0.0.0.0 0 0 i
i 3.3.3.3/32 3.3.3.3 0 100 0 i
[R3]dis bgp routing-table
BGP Local router ID is 13.0.0.2
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
i 1.1.1.1/32 1.1.1.1 0 100 0 i
i 2.2.2.2/32 2.2.2.2 0 100 0 i
*> 3.3.3.3/32 0.0.0.0 0 0 i
as2EBGP建邻
[R4]bgp 2
[R4-bgp]peer 24.0.0.1 group EBGP
[R4-bgp]peer 34.0.0.1 group EBGP
[R4-bgp]group EBGP3 external
[R4-bgp]peer EBGP3 as-number 3
[R4-bgp]peer 15.0.0.2 group EBGP3
[R4-bgp]peer 45.0.0.2 group EBGP3
[R4-bgp]peer 46.0.0.2 group EBGP3
[R4-bgp]network 4.4.4.4 32
[R2-bgp]peer 24.0.0.2 as-number 2
[R3-bgp]peer 34.0.0.2 as-number 2
[R5-bgp]peer 46.0.0.1 as-number 2
[R6-bgp]peer 46.0.0.1 as-number 2
查看
[R4]display bgp peer
BGP local router ID : 24.0.0.2
Local AS number : 2
Total number of peers : 4 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
24.0.0.1 4 1 10 13 0 00:07:14 Established
1
34.0.0.1 4 1 11 13 0 00:06:45 Established
1
45.0.0.2 4 3 7 11 0 00:05:03 Established
0
46.0.0.2 4 3 0 1 0 00:17:13 Active
0
as3IBGP建邻居
[R5]bgp 3
[R5-bgp]group IBGP
[R5-bgp]peer IBGP connect-interface l0
[R5-bgp]peer IBGP next-hop-local
[R5-bgp]peer 6.6.6.6 group IBGP
[R5-bgp]peer 7.7.7.7 group IBGP
[R6]bgp 3
[R6-bgp]group IBGP
[R6-bgp]peer IBGP connect-interface l0
[R6-bgp]peer IBGP next-hop-local
[R6-bgp]peer 5.5.5.5 group IBGP
[R6-bgp]peer 7.7.7.7 group IBGP
[R7]bgp 3
[R7-bgp]group IBGP
[R7-bgp]peer IBGP connect-interface l0
[R7-bgp]peer 5.5.5.5 group IBGP
[R7-bgp]peer 6.6.6.6 group IBGP
查看
[R5]display bgp peer
BGP local router ID : 45.0.0.2
Local AS number : 3
Total number of peers : 4 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
6.6.6.6 4 3 6 7 0 00:02:09 Established
3
7.7.7.7 4 3 3 6 0 00:01:01 Established
0
45.0.0.1 4 2 18 15 0 00:13:54 Established
3
45.0.0.2 4 2 0 0 0 00:15:37 Idle
0
[R6]disp bgp peer
BGP local router ID : 46.0.0.2
Local AS number : 3
Total number of peers : 3 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
5.5.5.5 4 3 6 6 0 00:02:50 Established
3
7.7.7.7 4 3 3 6 0 00:01:28 Established
0
46.0.0.1 4 2 14 11 0 00:09:24 Established
3
[R7]disp bgp peer
BGP local router ID : 57.0.0.2
Local AS number : 3
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
5.5.5.5 4 3 5 3 0 00:01:57 Established
3
6.6.6.6 4 3 5 3 0 00:01:43 Established
3
as3 内有两个用户网段(100,200),as 1 内用户访问这两个网段时,希望在R2和R3上实现流量分担,as 2访问这两个网段时,希望在R5和R6上实现流量分担。
R7上添加两个环回作为用户网段
[R7]int l1
[R7-LoopBack1]ip add 200.0.0.1 24
[R7-LoopBack1]q
[R7]int l2
[R7-LoopBack2]ip add 100.0.0.1 24
[R7-LoopBack2]q
添加团体值
[R7]route-policy com permit node 10
[R7-route-policy]if-match interface l1
[R7-route-policy]apply community 300:200
[R7-route-policy]q
[R7]route-policy com permit node 20
[R7-route-policy]if-match interface l2
[R7-route-policy]apply community 300:100
[R7-route-policy]q
重发布导入直连
[R7]bgp 3
[R7-bgp]import-route direct route-policy com
[R7]dis bgp routing-table community
*> 100.0.0.0/24 0.0.0.0 0 0 <300:100>
*> 200.0.0.0 0.0.0.0 0 0 <300:200>
打开通告团体值的开关
[R7]bgp 3
[R7-bgp]peer IBGP advertise-community
[R7-bgp]q
[R6]bgp 3
[R6-bgp]peer 46.0.0.1 advertise-community
[R6-bgp]q
[R5]bgp 3
[R5-bgp]peer 45.0.0.1 advertise-community
[R5-bgp]q
[R4]bgp 2
[R4-bgp]peer EBGP advertise-community
[R4-bgp]q
[R3]bgp 1
[R3-bgp]peer IBGP advertise-community
[R3-bgp]q
[R2]bgp 1
[R2-bgp]peer IBGP advertise-community
[R2-bgp]q
<R1>display bgp routing-table community
Network NextHop MED LocPrf PrefVal Community
*>i 100.0.0.0/24 2.2.2.2 100 0 <300:100>
* i 3.3.3.3 100 0 <300:100>
*>i 200.0.0.0 2.2.2.2 100 0 <300:200>
* i 3.3.3.3 100 0 <300:200>
使用抓取community的方法使得100.0.0.0/24走下面一条链路
[R4]ip community-filter 100 permit 300:100
[R4]route-policy 100 permit node 10
[R4-route-policy]if-match community-filter 100
[R4-route-policy]apply cost 1
[R4-route-policy]q
[R4]bgp 2
[R4-bgp]peer 45.0.0.2 route-policy 100 import
[R4-bgp]q
[R4]route-policy 100 permit node 20
[R4-route-policy]q
[r1]ip community-filter 100 permit 300:100
[r1]route-policy 100 permit node 10
[r1-route-policy]if-match community-filter 100
[r1-route-policy]apply local-preference 101
[r1-route-policy]q
[r1]route-policy 100 permit node 20
[r1]bgp 1
[r1-bgp]peer 3.3.3.3 route-policy 100 import
[R4]display bgp routing-table community
Network NextHop MED LocPrf PrefVal Community
*> 100.0.0.0/24 46.0.0.2 0 <300:100>
* 45.0.0.2 1 0 <300:100>
*> 200.0.0.0 45.0.0.2 0 <300:200>
* 46.0.0.2 0 <300:200>