实验案例:使用BG属性控制选路(AS200内运行OSPF协议)

实验环境
某运营商网络,其中AS200内运行OSPF协议,要求实现1.1.1.1可以访问5.5.5.5.
需求描述
要求实现1.1.1.1访问5.5.5.5的路径为R1-R2-R4-R5-R4-R3-R1。禁止通过在所有路由器运行相同的IGP协议实现全网互通,请通过BGP实现互通。
在这里插入图片描述
配置IP地址和LoopBack接口
[R1]display ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 8
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 8

Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 12.1.1.1/24 up up
GigabitEthernet0/0/1 13.1.1.1/24 up up
GigabitEthernet0/0/2 unassigned down down
GigabitEthernet0/0/3 unassigned down down
LoopBack0 1.1.1.1/32 up up(s)
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
[R2]display ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 8
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 8

Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 12.1.1.2/24 up up
GigabitEthernet0/0/1 24.1.1.2/24 up up
GigabitEthernet0/0/2 unassigned down down
GigabitEthernet0/0/3 unassigned down down
LoopBack0 2.2.2.2/32 up up(s)
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
[R3]display ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 8
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 8

Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 34.1.1.3/24 up up
GigabitEthernet0/0/1 13.1.1.3/24 up up
GigabitEthernet0/0/2 unassigned down down
GigabitEthernet0/0/3 unassigned down down
LoopBack0 3.3.3.3/32 up up(s)
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
[R4]display ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 7
The number of interface that is UP in Protocol is 5
The number of interface that is DOWN in Protocol is 7

Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 34.1.1.4/24 up up
GigabitEthernet0/0/1 24.1.1.4/24 up up
GigabitEthernet0/0/2 45.1.1.4/24 up up
GigabitEthernet0/0/3 unassigned down down
LoopBack0 4.4.4.4/32 up up(s)
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
[R5]display ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 9
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 9

Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 unassigned down down
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 45.1.1.5/24 up up
GigabitEthernet0/0/3 unassigned down down
LoopBack0 5.5.5.5/32 up up(s)
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
配置OSPF
[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 24.1.1.0 0.0.0.255
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3
[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 34.1.1.0 0.0.0.255
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 24.1.1.0 0.0.0.255
配置EBGP
[R1]bgp 100
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 12.1.1.2 as-number 200
[R1-bgp]peer 13.1.1.3 as-number 200
[R2]bgp 200
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 12.1.1.1 as-number 100
[R3]bgp 200
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 13.1.1.1 as-number 100
[R4]bgp 200
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 45.1.1.5 as-number 300
[R5]bgp 300
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 45.1.1.4 as-number 200
配置IBGP
[R2]bgp 200
[R2-bgp]router-id 2.2.2.2
[R2-bgp]group 20 internal
[R2-bgp]peer 4.4.4.4 group 20
[R2-bgp]peer 20 connect-interface LoopBack 0
[R2-bgp]peer 20 next-hop-local
[R3]bgp 200
[R3-bgp]router-id 3.3.3.3
[R3-bgp]group 30 internal
[R3-bgp]peer 4.4.4.4 group 30
[R3-bgp]peer 30
[R3-bgp]peer 30 connect-interface LoopBack 0
[R3-bgp]peer 30 next-hop-local
[R4]bgp 200
[R4-bgp]router-id 4.4.4.4
[R4-bgp]group 40 internal
[R4-bgp]peer 2.2.2.2
[R4-bgp]peer 2.2.2.2 group 40
[R4-bgp]peer 3.3.3.3 group 40
[R4-bgp]peer 40 connect-interface LoopBack 0
[R4-bgp]peer 40 next-hop-local
配置路由重分发
[R2]bgp 200
[R2-bgp]import-route direct
[R2-bgp]import-route ospf 1
[R3]bgp 200
[R3-bgp]import-route direct
[R3-bgp]import-route ospf 1
[R4]bgp 200
[R4-bgp]import-route direct
[R4-bgp]import-route ospf 1
通告1.1.1.1/32和5.5.5.5/32
[R1]bgp 100
[R1-bgp]net
[R1-bgp]network 1.1.1.1 32
[R1-bgp]
Sep 3 2019 16:46:32-08:00 R1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 10, the c
hange loop count is 0, and the maximum number of records is 4095.
[R1-bgp]
[R1-bgp]q
[R1]ping -a 1.1.1.1 5.5.5.5
PING 5.5.5.5: 56 data bytes, press CTRL_C to break
Reply from 5.5.5.5: bytes=56 Sequence=1 ttl=253 time=80 ms
Reply from 5.5.5.5: bytes=56 Sequence=2 ttl=253 time=100 ms
Reply from 5.5.5.5: bytes=56 Sequence=3 ttl=253 time=80 ms
Reply from 5.5.5.5: bytes=56 Sequence=4 ttl=253 time=90 ms
Reply from 5.5.5.5: bytes=56 Sequence=5 ttl=253 time=90 ms

— 5.5.5.5 ping statistics —
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 80/88/100 ms
[R5]bgp 300
[R5-bgp]ne
[R5-bgp]network 5.5.5.5 32
[R5-bgp]q
[R5]dis
[R5]display
Sep 3 2019 16:47:05-08:00 R5 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 8, the ch
ange loop count is 0, and the maximum number of records is 4095.
^
Error:Incomplete command found at ‘^’ position.
[R5]dsi
[R5]dis
[R5]display bg
[R5]display bg
[R5]display bgp r
[R5]display bgp routing-table

BGP Local router ID is 5.5.5.5
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 10
Network NextHop MED LocPrf PrefVal Path/Ogn

*> 1.1.1.1/32 45.1.1.4 0 200 100i
*> 2.2.2.2/32 45.1.1.4 1 0 200?
*> 3.3.3.3/32 45.1.1.4 1 0 200?
*> 4.4.4.4/32 45.1.1.4 0 0 200?
*> 5.5.5.5/32 0.0.0.0 0 0 i
*> 12.1.1.0/24 45.1.1.4 0 200?
*> 13.1.1.0/24 45.1.1.4 0 200?
*> 24.1.1.0/24 45.1.1.4 0 0 200?
*> 34.1.1.0/24 45.1.1.4 0 0 200?
45.1.1.0/24 45.1.1.4 0 0 200?
通过MED属性控制使R1去往R5改走R2
[R3]route-policy med permit node 10
Info: New Sequence of this List.
[R3-route-policy]apply cost + 500
[R3]bgp 200
[R3-bgp]pe
[R3-bgp]peer 13.1.1.1 route-policy med export
在这里插入图片描述