配ip
[r4-GigabitEthernet0/0/0]ip address 24.0.0.4 24
[r4-GigabitEthernet0/0/1]ip address 34.0.0.4 24
[r4-LoopBack0]ip address 192.168.1.1 24
[r4-LoopBack1]ip address 192.168.2.1 24
[r4-LoopBack2]ip address 192.168.3.1 24
#
[r2-GigabitEthernet0/0/0]ip address 24.0.0.2 24
[r2-GigabitEthernet0/0/1]ip address 12.0.0.2 24
[r2-LoopBack0]ip address 2.2.2.2 32
[r2-LoopBack1]ip address 192.168.20.1 24
#
[r3-GigabitEthernet0/0/0]ip address 34.0.0.3 24
[r3-GigabitEthernet0/0/1]ip address 13.0.0.3 24
[r3-LoopBack0]ip address 3.3.3.3 32
[r3-LoopBack1]ip address 192.168.30.1 24
#
[r1-GigabitEthernet0/0/0]ip address 12.0.0.1 24
[r1-GigabitEthernet0/0/1]ip address 13.0.0.1 24
[r1-GigabitEthernet0/0/2]ip address 15.0.0.1 24
[r1-LoopBack0]ip address 1.1.1.1 32
[r1-LoopBack1]ip address 192.168.100.1 24
#
[r5-GigabitEthernet0/0/0]ip address 15.0.0.5 24
[r5-LoopBack0]ip address 192.168.10.1 24
[r5-LoopBack1]ip address 192.168.11.1 24
[r5-LoopBack2]ip address 192.168.12.1 24
测试
[r2]ping 24.0.0.4
PING 24.0.0.4: 56 data bytes, press CTRL_C to break
Reply from 24.0.0.4: bytes=56 Sequence=1 ttl=255 time=50 ms
Reply from 24.0.0.4: bytes=56 Sequence=2 ttl=255 time=10 ms
Reply from 24.0.0.4: bytes=56 Sequence=3 ttl=255 time=20 ms
Reply from 24.0.0.4: bytes=56 Sequence=4 ttl=255 time=20 ms
Reply from 24.0.0.4: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 24.0.0.4 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/24/50 ms
[r5]ping 15.0.0.1
PING 15.0.0.1: 56 data bytes, press CTRL_C to break
Reply from 15.0.0.1: bytes=56 Sequence=1 ttl=255 time=140 ms
Reply from 15.0.0.1: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 15.0.0.1: bytes=56 Sequence=3 ttl=255 time=20 ms
Reply from 15.0.0.1: bytes=56 Sequence=4 ttl=255 time=20 ms
Reply from 15.0.0.1: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 15.0.0.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/44/140 ms
BGP配置
[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
#
[r2]bgp 123
[r2-bgp]peer 1.1.1.1 as-number 123
[r2-bgp]peer 1.1.1.1 con l 0
[r2-bgp]peer 24.0.0.4 as-number 400
#
[r3]bgp 123
[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 con l 0
#
[r1]bgp 123
[r1-bgp]router-id 1.1.1.1
[r1-bgp]peer 2.2.2.2 as-number 123
[r1-bgp]peer 2.2.2.2 con l 0
[r1-bgp]peer 3.3.3.3 as-number 123
[r1-bgp]peer 3.3.3.3 con l 0
[r1-bgp]peer 15.0.0.5 as-number 500
#
[r5]bgp 500
[r5-bgp]router-id 5.5.5.5
[r5-bgp]peer 15.0.0.1 as-number 123
1、使用Preval策略,确保R4通过R2到达192.168.10.0/24
[r4]ip ip-prefix aa permit 192.168.10.0 24
[r4]route-policy aa permit node 10
[r4-route-policy]if-match ip-prefix aa
[r4-route-policy]apply preferred-value 100
[r4]route-policy aa permit node 20
[r4-bgp]peer 24.0.0.2 route-policy aa import
2、使用As_Path策略,确保R4通过R3到达192.168.11.0/24
[r4]ip ip-prefix bb permit 192.168.11.0 24
[r4]route-policy aa permit node 15
[r4-route-policy]if-match ip-prefix bb
[r4-route-policy]apply as-path 123 123 500 500 overwrite
3、配置MED策略,确保R4通过R3到达192.168.12.0/24
[r2]ip ip-prefix aa permit 192.168.12.0 24
[r2]route-policy aa permit node 10
[r2-route-policy]if-match ip-prefix aa
[r2-route-policy]apply cost 500
[r2]route-policy aa permit node 20
[r2-bgp]peer 24.0.0.4 route-policy aa export
#
[r3]ip ip-prefix aa permit 192.168.12.0 24
[r3]route-policy aa permit node 10
[r3-route-policy]if-match ip-prefix aa
[r3-route-policy]apply cost 100
[r3]route-policy aa permit node 20
[r3-bgp]peer 34.0.0.4 route-policy aa export
4、使用Local Preference策略,确保R1通过R2到达192.168.1.0/245、使用Local Preference策略,确保R1通过R3到达192.168.2.0/24
[r1]ip ip-prefix aa permit 192.168.1.0 24
[r1]route-policy aa permit node 10
[r1-route-policy]if-match ip-prefix aa
[r1-route-policy]apply local-preference 200
[r1]route-policy aa permit node 20
[r1-bgp]peer 2.2.2.2 route-policy aa import
#
[r1]ip ip-prefix bb permit 192.168.2.0 24
[r1]route-policy bb permit node 10
[r1-route-policy]if-match ip-prefix bb
[r1-route-policy]apply local-preference 200
[r1]route-policy bb permit node 20
[r1-bgp]peer 3.3.3.3 route-policy bb import
使用As策略,As 500不接受任何始发于As 123的路由
[r5]ip as-path-filter 1 deny ^123$
[r5]ip as-path-filter 1 permit .*
[r5-bgp]peer 15.0.0.1 as-path-filter 1 import
使用自定义community策略,确保192.168.3.0/24路由不会被发布到As 500
[r4]route-policy com permit node 10
[r4-route-policy]apply community 400:500
[r4-bgp]network 192.168.3.0 route-policy com
[r4-bgp]peer 24.0.0.2 advertise-community
[r4-bgp]peer 34.0.0.3 advertise-community
[r3-bgp]peer 1.1.1.1 advertise-community
[r1-bgp]peer 15.0.0.5 advertise-community
[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 com permit node 20
[r1-bgp]peer 15.0.0.5 route-policy com export
[r2-bgp]peer 1.1.1.1 advertise-community