BGP小實驗——選路不困難,只要有方法
- 前言
- 一、需求
- 二、命令
- 1、先配置基礎命令,完成全網通
- R1
- R2
- R3
- R4
- R5
- 2、查看BGP路由表
- R1
- R4
- 3、擇路(我們用兩種方式)
- R1
- R3
- 4、重繪下BGP,再次查看擇路結果
- R1
- R4
- 5、結論
前言

一、需求
- 全網通
- R1到R4走R3
- R4到R1走R3
二、命令
1、先配置基礎命令,完成全網通
R1
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 13.0.0.1 24
[Huawei-GigabitEthernet0/0/1]int loop 0
[Huawei-LoopBack0]ip add 1.1.1.1 32
[Huawei-LoopBack0]q
[Huawei]ip route-static 2.2.2.2 32 12.0.0.2
[Huawei]ip route-static 3.3.3.3 32 13.0.0.3
[Huawei]bgp 100
[Huawei-bgp]router-id 1.1.1.1
[Huawei-bgp]peer 2.2.2.2 as-number 200
[Huawei-bgp]peer 3.3.3.3 as-number 200
[Huawei-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[Huawei-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[Huawei-bgp]peer 2.2.2.2 ebgp-max-hop 2
[Huawei-bgp]peer 3.3.3.3 ebgp-max-hop 2
[Huawei-bgp]net 1.1.1.1 32
[Huawei-bgp]net 2.2.2.2 32
[Huawei-bgp]net 3.3.3.3 32
[Huawei-bgp]q
[Huawei]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=30 ms
Reply from 5.5.5.5: bytes=56 Sequence=2 ttl=253 time=20 ms
Reply from 5.5.5.5: bytes=56 Sequence=3 ttl=253 time=30 ms
Reply from 5.5.5.5: bytes=56 Sequence=4 ttl=253 time=40 ms
Reply from 5.5.5.5: bytes=56 Sequence=5 ttl=253 time=30 ms
--- 5.5.5.5 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/30/40 ms
R2
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 24.0.0.2 24
[Huawei-GigabitEthernet0/0/1]int loop0
[Huawei-LoopBack0]ip add 2.2.2.2 32
[Huawei-LoopBack0]q
[Huawei]ip route-static 1.1.1.1 32 12.0.0.1
[Huawei]ospf
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]net 2.2.2.2 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]net 24.0.0.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]q
[Huawei-ospf-1]q
[Huawei]bgp 200
[Huawei-bgp]router-id 2.2.2.2
[Huawei-bgp]peer 1.1.1.1 as-number 100
[Huawei-bgp]peer 4.4.4.4 as-number 200
[Huawei-bgp]peer 3.3.3.3 as-number 200
[Huawei-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[Huawei-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[Huawei-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[Huawei-bgp]peer 1.1.1.1 ebgp-max-hop 2
[Huawei-bgp]peer 3.3.3.3 next-hop-local
[Huawei-bgp]peer 4.4.4.4 next-hop-local
[Huawei-bgp]net 1.1.1.1 32
[Huawei-bgp]net 2.2.2.2 32
[Huawei-bgp]net 3.3.3.3 32
[Huawei-bgp]net 4.4.4.4 32
R3
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 13.0.0.3 24
[Huawei-GigabitEthernet0/0/1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 34.0.0.3 24
[Huawei-GigabitEthernet0/0/0]int loop0
[Huawei-LoopBack0]ip add 3.3.3.3 32
[Huawei-LoopBack0]q
[Huawei]ip route-static 1.1.1.1 32 13.0.0.1
[Huawei]ospf
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]net 3.3.3.3 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]net 34.0.0.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]q
[Huawei-ospf-1]q
[Huawei]bgp 200
[Huawei-bgp]router-id 3.3.3.3
[Huawei-bgp]peer 1.1.1.1 as-number 100
[Huawei-bgp]peer 4.4.4.4 as-number 200
[Huawei-bgp]peer 2.2.2.2 as-number 200
[Huawei-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[Huawei-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[Huawei-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[Huawei-bgp]peer 1.1.1.1 ebgp-max-hop 2
[Huawei-bgp]peer 4.4.4.4 next-hop-local
[Huawei-bgp]peer 2.2.2.2 next-hop-local
[Huawei-bgp]net 1.1.1.1 32
[Huawei-bgp]net 2.2.2.2 32
[Huawei-bgp]net 3.3.3.3 32
[Huawei-bgp]net 4.4.4.4 32
R4
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 34.0.0.4 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 24.0.0.4 24
[Huawei-GigabitEthernet0/0/1]int g0/0/2
[Huawei-GigabitEthernet0/0/2]ip add 45.0.0.4 24
[Huawei-GigabitEthernet0/0/2]int loop0
[Huawei-LoopBack0]ip add 4.4.4.4 32
[Huawei-LoopBack0]q
[Huawei]ip route-static 5.5.5.5 32 45.0.0.5
[Huawei]ospf
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]net 4.4.4.4 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]net 34.0.0.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]net 24.0.0.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]q
[Huawei-ospf-1]q
[Huawei]bgp 200
[Huawei-bgp]router-id 4.4.4.4
[Huawei-bgp]peer 2.2.2.2 as-number 200
[Huawei-bgp]peer 3.3.3.3 as-number 200
[Huawei-bgp]peer 5.5.5.5 as-number 300
[Huawei-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[Huawei-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[Huawei-bgp]peer 5.5.5.5 connect-interface LoopBack 0
[Huawei-bgp]peer 2.2.2.2 next-hop-local
[Huawei-bgp]peer 3.3.3.3 next-hop-local
[Huawei-bgp]peer 5.5.5.5 ebgp-max-hop 2
[Huawei-bgp]net 2.2.2.2 32
[Huawei-bgp]net 3.3.3.3 32
[Huawei-bgp]net 4.4.4.4 32
[Huawei-bgp]net 5.5.5.5 32
R5
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g 0/0/2
[Huawei-GigabitEthernet0/0/2]ip add 45.0.0.5 24
[Huawei-GigabitEthernet0/0/2]int loop0
[Huawei-LoopBack0]ip add 5.5.5.5 32
[Huawei-LoopBack0]q
[Huawei]ip route-static 4.4.4.4 32 45.0.0.4
[Huawei]bgp 300
[Huawei-bgp]router-id 5.5.5.5
[Huawei-bgp]peer 4.4.4.4 as-number 200
[Huawei-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[Huawei-bgp]peer 4.4.4.4 ebgp-max-hop 2
[Huawei-bgp]net 4.4.4.4 32
[Huawei-bgp]net 5.5.5.5 32
2、查看BGP路由表
R1
[Huawei]dis bgp routing-table
BGP Local router ID is 1.1.1.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: 13
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 0.0.0.0 0 0 i
* 2.2.2.2 0 0 200i
* 3.3.3.3 0 0 200i
*> 2.2.2.2/32 0.0.0.0 0 0 i
* 3.3.3.3 2 0 200i
2.2.2.2 0 0 200i
*> 3.3.3.3/32 0.0.0.0 0 0 i
* 2.2.2.2 2 0 200i
3.3.3.3 0 0 200i
*> 4.4.4.4/32 2.2.2.2 1 0 200i
* 3.3.3.3 1 0 200i
*> 5.5.5.5/32 2.2.2.2 0 200i
* 3.3.3.3 0 200i
R4
[Huawei]dis bgp routing-table
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 14
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 2.2.2.2 0 100 0 i
* i 3.3.3.3 0 100 0 i
*> 2.2.2.2/32 0.0.0.0 1 0 i
* i 3.3.3.3 2 100 0 i
i 2.2.2.2 0 100 0 i
*> 3.3.3.3/32 0.0.0.0 1 0 i
* i 2.2.2.2 2 100 0 i
i 3.3.3.3 0 100 0 i
*> 4.4.4.4/32 0.0.0.0 0 0 i
* i 2.2.2.2 1 100 0 i
* i 3.3.3.3 1 100 0 i
* 5.5.5.5 0 0 300i
*> 5.5.5.5/32 0.0.0.0 0 0 i
5.5.5.5 0 0 300i
這時候,我們可以看到,從R1到R4走的是R2,R4到R1走的也是R2,我們需要擇路,
3、擇路(我們用兩種方式)
R1
[Huawei]route-policy as permit node 10
Info: New Sequence of this List.
[Huawei-route-policy]apply as-path 123 123 additive
[Huawei-route-policy]q
[Huawei]bgp 100
[Huawei-bgp]peer 2.2.2.2 route-policy as import
[Huawei-bgp]q
[Huawei]q
<Huawei>refresh bgp all import
R3
[Huawei]route-policy lop permit node 10
Info: New Sequence of this List.
[Huawei-route-policy]apply local-preference 222
[Huawei-route-policy]q
[Huawei]bgp 200
[Huawei-bgp]peer 4.4.4.4 route-policy lop export
[Huawei-bgp]q
[Huawei]q
<Huawei>refresh bgp all export
4、重繪下BGP,再次查看擇路結果
R1
<Huawei>dis bgp routing-table
BGP Local router ID is 1.1.1.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: 13
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 0.0.0.0 0 0 i
* 3.3.3.3 0 0 200i
* 2.2.2.2 0 0 123 123 20
0i
*> 2.2.2.2/32 0.0.0.0 0 0 i
* 3.3.3.3 2 0 200i
2.2.2.2 0 0 123 123 20
0i
*> 3.3.3.3/32 0.0.0.0 0 0 i
* 2.2.2.2 2 0 123 123 20
0i
3.3.3.3 0 0 200i
*> 4.4.4.4/32 3.3.3.3 1 0 200i
* 2.2.2.2 1 0 123 123 20
0i
*> 5.5.5.5/32 3.3.3.3 0 200i
* 2.2.2.2 0 123 123 20
0i
R4
[Huawei]dis bgp routing-table
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 14
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 222 0 i
* i 2.2.2.2 0 100 0 i
*>i 2.2.2.2/32 3.3.3.3 2 222 0 i
* 0.0.0.0 1 0 i
i 2.2.2.2 0 100 0 i
*> 3.3.3.3/32 0.0.0.0 1 0 i
* i 2.2.2.2 2 100 0 i
i 3.3.3.3 0 222 0 i
*>i 4.4.4.4/32 3.3.3.3 1 222 0 i
* 0.0.0.0 0 0 i
* i 2.2.2.2 1 100 0 i
* 5.5.5.5 0 0 300i
*> 5.5.5.5/32 0.0.0.0 0 0 i
5.5.5.5 0 0 300i
5、結論
- 我們可以看到,我們改變了R3的local-preference為222之后,優先級大于R2,然后對D4執行了出站export策略,所以R4到R1的時候選擇了R3,
- 我們在R1對R2執行了入站import策略,對R2已有的AS-path基礎上追加了123和123,使得優先級低于R3,這樣,從R1到R4是,自然而然的選擇了R2這條線,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/250148.html
標籤:其他
上一篇:shutdown命令使用
