文章 > NetWork > 华为设备BGP配置

华为设备BGP配置

泡杯长岛冰茶 · 2023-01-17 472 NetWork

a.华为交换机基础命令

b.华为设备DHCP中继

c.华为设备mstp+vrrp 配置

d.华为设备配置BDF链路冗余

e.300-500人网络规划与模拟配置

f.ospf &bgp&路由策略&策略路由

g.华为设备BGP配置




1.拓扑图

image-20220321164246517

2.BGP 路由策略

注意:私有AS号64512-65535,其它区域需要去申请。

1 丢弃下一跳不可达的路由
**2 优选Preference_Value值(首选值)最高的路由(私有,本地有效)
**3 优选本地优先级(Local_Pre)最高的路由
4 优选手动聚合>自动聚合>network>import>从对等体学到
**5 优选AS_Path短的路由
**6 起源类型Original : I>E>?
**7 对于来自同一AS的路由,优选MED值小的。
8 优选从EBGP学来的路由(EBGP>IBGP)
9 优选AS内部IGP的Metric最小的路由(到达下一跳的IGP 开销)
----可以开启负载分担----(bgp路由表不体现 路由会显示)
10 优选Cluster_List (RR反射器:RR的router id)最短的路由(经过RR的
数量少)
11 优选Orginator_ID (RR反射器:路由起源router id )最小的路由(路由
进入某AS时,起始路由器router id)
12 优选Router_ID最小的路由器发布的路由
13 优选具有较小IP地址的邻居学来的路由


3.刷新bgp更新

refresh bgp all import 

refresh bgp all export


4.地址配置

R1:

<R1>dis ip int b 

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              200.1.13.1/25        up         up        
GigabitEthernet0/0/1              10.2.16.1/25         up         up        
GigabitEthernet0/0/2              10.2.12.1/25         up         up        
LoopBack0                               10.2.1.1/24          up         up(s)  

R2:

<R2>dis ip int b 
Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              200.1.25.2/25        up         up        
GigabitEthernet0/0/1              10.2.26.2/25         up         up        
GigabitEthernet0/0/2              10.2.12.2/25         up         up        
LoopBack0                         10.2.2.2/24          up         up(s)    
NULL0                             unassigned           up         up(s)    

R3:

<R3>dis ip int b 
Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              200.1.13.3/25        up         up        
GigabitEthernet0/0/1              10.1.35.3/25         up         up        
GigabitEthernet0/0/2              10.1.34.3/25         up         up        
LoopBack0                         10.1.3.3/24          up         up(s)    
NULL0                             unassigned           up         up(s)  

R4:

<R4>dis ip int b 
Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.1.34.4/25         up         up        
GigabitEthernet0/0/1              10.1.45.4/25         up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         10.1.4.4/24          up         up(s)    
LoopBack1                         10.1.7.4/24          up         up(s)    
NULL0                             unassigned           up         up(s)    
-----------------------------------------------------------------------
[R4-LoopBack0]int loo 0
[R4-LoopBack0]dis this
interface LoopBack0
ip address 10.1.4.4 255.255.255.0
ospf network-type broadcast   #将本地环回Ip路由由32掩码改为24位

[R4-LoopBack0]int loo 1
interface LoopBack1
ip address 10.1.7.4 255.255.255.0
ospf network-type broadcast    #将本地环回Ip路由由32掩码改为24位

R5:

<R5>dis ip int b 
Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              200.1.25.5/25        up         up        
GigabitEthernet0/0/1              10.1.35.5/25         up         up        
GigabitEthernet0/0/2              10.1.45.5/25         up         up        
LoopBack0                         10.1.5.5/24          up         up(s)    
NULL0                             unassigned           up         up(s)    

R6:

<R6>dis ip int b 
Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.2.16.6/25         up         up        
GigabitEthernet0/0/1              10.2.26.6/25         up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         10.2.6.6/24          up         up(s)    
LoopBack1                         10.2.7.6/24          up         up(s)    
NULL0                             unassigned           up         up(s)    

5.IGP配置(ospf配置):

as 200

R1:

<R1>dis ospf peer b
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/1             10.2.6.6         Full        
0.0.0.0          GigabitEthernet0/0/2             10.2.2.2         Full        
----------------------------------------------------------------------------
[R1]ospf 1
[R1-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.2.1.1 0.0.0.0
 network 10.2.12.1 0.0.0.0
 network 10.2.16.1 0.0.0.0

R2:

<R2>dis ospf peer b
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/2             10.2.1.1         Full        
0.0.0.0          GigabitEthernet0/0/1             10.2.6.6         Full        
----------------------------------------------------------------------------
[R2-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.2.2.2 0.0.0.0
 network 10.2.12.2 0.0.0.0
 network 10.2.26.2 0.0.0.0

R6:

<R6>dis ospf peer b
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/0             10.2.1.1         Full        
0.0.0.0          GigabitEthernet0/0/1             10.2.2.2         Full        
----------------------------------------------------------------------------
[R6-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.2.6.6 0.0.0.0
 network 10.2.7.6 0.0.0.0
 network 10.2.16.6 0.0.0.0
 network 10.2.26.6 0.0.0.0

as 100

R3:

<R3>dis ospf peer b 
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/2             10.1.4.4         Full        
0.0.0.0          GigabitEthernet0/0/1             10.1.5.5         Full        
----------------------------------------------------------------------------
[R3-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.1.3.3 0.0.0.0
 network 10.1.34.3 0.0.0.0
 network 10.1.35.3 0.0.0.0

R4:

<R4>dis ospf peer b
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/0             10.1.3.3         Full        
0.0.0.0          GigabitEthernet0/0/1             10.1.5.5         Full        
----------------------------------------------------------------------------
[R4-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.1.4.4 0.0.0.0
 network 10.1.7.4 0.0.0.0
 network 10.1.34.4 0.0.0.0
 network 10.1.45.4 0.0.0.0

R5:

<R5>dis ospf peer b 
----------------------------------------------------------------------------
Area Id          Interface                        Neighbor id      State    
0.0.0.0          GigabitEthernet0/0/1             10.1.3.3         Full        
0.0.0.0          GigabitEthernet0/0/2             10.1.4.4         Full        
----------------------------------------------------------------------------
[R5-ospf-1]dis this
ospf 1
area 0.0.0.0
 network 10.1.5.5 0.0.0.0
 network 10.1.35.5 0.0.0.0
 network 10.1.45.5 0.0.0.0

6.bgp 邻居建立

as 200

R1:

[R1]bgp 200
[R1-bgp]dis this
bgp 200
peer 10.2.2.2 as-number 200
peer 10.2.2.2 connect-interface LoopBack0
peer 10.2.6.6 as-number 200
peer 10.2.6.6 connect-interface LoopBack0
peer 200.1.13.3 as-number 100
#
ipv4-family unicast
 undo synchronization
 peer 10.2.2.2 enable
 peer 10.2.2.2 next-hop-local
 peer 10.2.6.6 enable
 peer 10.2.6.6 next-hop-local
 peer 200.1.13.3 enable
------------------------------------------------------------------------------------  
 [R1-bgp]dis bgp peer
BGP local router ID : 10.2.1.1
Local AS number : 200
Total number of peers : 3    Peers in established state : 3
 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv
 10.2.2.2        4         200      104      106     0 01:42:26 Established    0  
 10.2.6.6        4         200      105      105     0 01:43:38 Established    0  
 200.1.13.3      4         100      110      110     0 01:48:22 Established    0
 

R2:

[R2]bgp 200
[R2-bgp]dis this
bgp 200
peer 10.2.1.1 as-number 200
peer 10.2.1.1 connect-interface LoopBack0
peer 10.2.6.6 as-number 200
peer 10.2.6.6 connect-interface LoopBack0
peer 200.1.25.5 as-number 100
#
ipv4-family unicast
 undo synchronization
 peer 10.2.1.1 enable
 peer 10.2.1.1 next-hop-local
 peer 10.2.6.6 enable
 peer 10.2.6.6 next-hop-local
 peer 200.1.25.5 enable
 ------------------------------------------------------------------------------------  
 [R2-bgp]dis bgp peer
BGP local router ID : 10.2.2.2
Local AS number : 200
Total number of peers : 3    Peers in established state : 3

 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv
 10.2.1.1        4         200      105      105     0 01:43:35 Established    0
 10.2.6.6        4         200      105      105     0 01:43:41 Established    0
 200.1.25.5      4         100      109      109     0 01:47:10 Established    0

R6:

[R6]bgp 200
[R6-bgp]dis this
bgp 200
peer 10.2.1.1 as-number 200
peer 10.2.1.1 connect-interface LoopBack0
peer 10.2.2.2 as-number 200
peer 10.2.2.2 connect-interface LoopBack0
#
ipv4-family unicast
 undo synchronization
 peer 10.2.1.1 enable
 peer 10.2.2.2 enable
------------------------------------------------------------------------------------  
 [R6-bgp]dis bgp peer
BGP local router ID : 10.2.6.6
Local AS number : 200
Total number of peers : 2    Peers in established state : 2

 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv

 10.2.1.1        4         200      107      108     0 01:45:33 Established    0
 10.2.2.2        4         200      106      107     0 01:44:26 Established    0

as 100

R3:

[R3]bgp 100
[R3-bgp]dis this
bgp 100
peer 10.1.4.4 as-number 100
peer 10.1.4.4 connect-interface LoopBack0
peer 10.1.5.5 as-number 100
peer 10.1.5.5 connect-interface LoopBack0
peer 200.1.13.1 as-number 200
#
ipv4-family unicast
 undo synchronization
 peer 10.1.4.4 enable
 peer 10.1.4.4 next-hop-local
 peer 10.1.5.5 enable
 peer 10.1.5.5 next-hop-local
 peer 200.1.13.1 enable
 ------------------------------------------------------------------------------------  
 [R3-bgp]dis bgp peer

BGP local router ID : 10.1.3.3
Local AS number : 100
Total number of peers : 3    Peers in established state : 3
 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv

 10.1.4.4        4         100      124      124     0 02:02:41 Established    0
 10.1.5.5        4         100      123      124     0 02:01:07 Established    0
 200.1.13.1      4         200      114      115     0 01:52:48 Established    0
 

R4:

[R4]bgp 100
[R4-bgp]dis this
bgp 100
peer 10.1.3.3 as-number 100
peer 10.1.3.3 connect-interface LoopBack0
peer 10.1.5.5 as-number 100
peer 10.1.5.5 connect-interface LoopBack0
#
ipv4-family unicast
 undo synchronization
 peer 10.1.3.3 enable
 peer 10.1.5.5 enable
 ------------------------------------------------------------------------------------
<R4>dis bgp peer
BGP local router ID : 10.1.4.4
Local AS number : 100
Total number of peers : 2    Peers in established state : 2
 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv

 10.1.3.3        4         100      125      128     0 02:03:40 Established    0
 10.1.5.5        4         100      123      124     0 02:02:00 Established    0

R5:

[R5]bgp 100
[R5-bgp]dis this
bgp 100
peer 10.1.3.3 as-number 100
peer 10.1.3.3 connect-interface LoopBack0
peer 10.1.4.4 as-number 100
peer 10.1.4.4 connect-interface LoopBack0
peer 200.1.25.2 as-number 200
#
ipv4-family unicast
 undo synchronization
 peer 10.1.3.3 enable
 peer 10.1.3.3 next-hop-local
 peer 10.1.4.4 enable
 peer 10.1.4.4 next-hop-local
 peer 200.1.25.2 enable
#
 ------------------------------------------------------------------------------------
<R5>dis bgp peer
BGP local router ID : 10.1.5.5
Local AS number : 100
Total number of peers : 3    Peers in established state : 3
 Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State PrefRcv

 10.1.3.3        4         100      125      125     0 02:03:40 Established    0
 10.1.4.4        4         100      125      125     0 02:03:34 Established    0
 200.1.25.2      4         200      114      115     0 01:52:59 Established    0

7.路由聚合

R3:

ip route-static 10.1.0.0 255.255.0.0 NULL0

[R3-bgp]network 10.1.0.0 16

R5:

ip route-static 10.1.0.0 255.255.0.0 NULL0

[R3-bgp]network 10.1.0.0 16


8.BGP 宣告

R3:

[R3-bgp]net 10.1.4.0 24
[R3-bgp]net 10.1.7.0 24
[R3-bgp]network 10.1.0.0 16
[R3]dis bgp routing-table

BGP Local router ID is 10.1.3.3
Status codes: * - valid, > - best, d - damped,
              h - history,  i - internal, s - suppressed, S - Stale
              Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 6
     Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.1.0.0/16        0.0.0.0         0                     0      i
* i                     10.1.5.5        0          100        0      i
*>   10.1.4.0/24        0.0.0.0         1                     0      i
* i                     10.1.5.5        1          100        0      i
*>   10.1.7.0/24        0.0.0.0         1                     0      i
* i  

R4:

[R3-bgp]net 10.1.4.0 24
[R3-bgp]net 10.1.7.0 24
[R3-bgp]network 10.1.0.0 16
[R5-bgp]dis bgp routing-table

BGP Local router ID is 10.1.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: 6
     Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>   10.1.0.0/16        0.0.0.0         0                     0      i
* i                     10.1.3.3        0          100        0      i
*>   10.1.4.0/24        0.0.0.0         1                     0      i
* i                     10.1.3.3        1          100        0      i
*>   10.1.7.0/24        0.0.0.0         1                     0      i
* i  

9.路由策略

R3/R5
ip ip-prefix Bangong_server  permit 10.1.4.0 24 greater-equal 24 less-equal 24
ip ip-prefix Yewu_server  permit 10.1.7.0 24 greater-equal 24 less-equal 24
ip ip-prefix Other_server  permit 10.1.0.0 16 greater-equal 16 less-equal 16

ip ip-prefix Yewu_dishi1  permit 10.2.7.0 24 greater-equal 24 less-equal 24
ip ip-prefix Bangong_dishi1  permit 10.2.6.0 24  greater-equal 24 less-equal 24
ip ip-prefix Other_dishi1  permit 10.2.0.0 16   greater-equal 16 less-equal 16

R3:

[R3]route-policy MED permit node 10
[R3-route-policy]dis this
route-policy MED permit node 10
if-match ip-prefix Bangong_server
apply cost 180
#
route-policy MED permit node 20
if-match ip-prefix Other_server
apply cost 180
#
route-policy MED permit node 100
#
bgp 100
[R3-bgp]peer 200.1.13.1 route-policy MED export
-----------------------------------------------------------------------------
route-policy AS_Path permit node 10
if-match ip-prefix Bangong_dishi1
apply as-path 200 200 additive
 #
 bgp 100
 peer 200.1.13.1 route-policy AS_Path import

R5:

[R5-route-policy]dis this
#
route-policy MED permit node 10
if-match ip-prefix Yewu_server
apply cost 180
#
route-policy MED permit node 1000
#
 bgp 100
 peer 200.1.25.2 route-policy MED export
------------------------------------------------------------------------


route-policy AS_Path permit node 10
if-match ip-prefix Yewu_dishi1
apply as-path 200 200 additive
#
bgp 100
peer 200.1.25.2 route-policy AS_Path import

R1/R2:  # 修改环回接口为24位俺码#路由宣告

ip route-static 10.2.0.0 255.255.0.0 NULL0
int loo 0
ospf network-type broadcast
int loo 1
ospf network-type broadcast
#
bgp 200
 network 10.2.0.0 255.255.0.0
 network 10.2.6.0 255.255.255.0
 network 10.2.7.0 255.255.255.0

R1:

<R1>dis bgp routing-table 
BGP Local router ID is 10.2.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: 6
     Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
*>i  10.1.0.0/16        10.2.2.2        0          100        0      100i
*                       200.1.13.3      180                   0      100i
*>i  10.1.4.0/24        10.2.2.2        1          100        0      100i
*                       200.1.13.3      180                   0      100i
*>   10.1.7.0/24        200.1.13.3      1                     0      100i
* i                     10.2.2.2        1          100        0      100i

R6:

<R6>tracert -a 10.2.6.6 10.1.4.4
traceroute to  10.1.4.4(10.1.4.4), max hops: 30 ,packet length: 40,press CTRL_C
to break
1 10.2.26.2 30 ms  20 ms  20 ms
2 200.1.25.5 20 ms  20 ms  30 ms
3 10.1.45.4 < AS=100 > 40 ms  30 ms  10 ms

终止EBGP 邻居

[R1-bgp]peer 200.1.13.3 ignore


10.OSPF 路由引入(方法二)

image-20220322174638300

R1/R2/R3/R4  配置osof import bgp type 1, R4/R6不配置BGP

R1/R2/R3/R4 宣告相关路由

 import-route bgp type 1



点击加载更多