静态路由联动静态BFD(Bidirectional Forwarding Detection)双向转发检测配置实例

科技   2025-01-30 18:50   河北  

如下图,路由器R1和R2之间有两条链路,路由器各接口以及回环接口已完成IP地址的配置:

R1各接口IP地址信息配置如下:

<R1>dis ip int b
*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                     12.1.1.1/24          up         up        
Ethernet0/0/1                     21.1.1.1/24          up         up        
GigabitEthernet0/0/0              unassigned           down       down      
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
GigabitEthernet0/0/3              unassigned           down       down      
LoopBack0                         1.1.1.1/24           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      
<R1>

R2各接口的IP地址信息配置如下:

<R2>dis ip int b
*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                     12.1.1.2/24          up         up        
Ethernet0/0/1                     21.1.1.2/24          up         up        
GigabitEthernet0/0/0              unassigned           down       down      
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
GigabitEthernet0/0/3              unassigned           down       down      
LoopBack0                         2.2.2.2/24           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>

现在优选链路上配置BFD检测:

1.在R1和R2上配置静态路由以及优先级

# R1路由器上配置

[R1]ip route-static 2.2.2.0 255.255.255.0 12.1.1.2 preference 50  # 将路由优先级改为50 设置为优选路径
[R1]
[R1]ip route-static 2.2.2.0 255.255.255.0 21.1.1.2
[R1]

# R2路由器上配置

[R2]ip route-static 1.1.1.0 255.255.255.0 12.1.1.1 preference 50
[R2]ip route-static 1.1.1.0 255.255.255.0 21.1.1.1
[R2]

2.配置静态bfd

# R1上配置:

[R1]bfd    # 全局使能bfd
[R1-bfd]quit
[R1]bfd mybfd01 bind peer-ip 12.1.1.2 source-ip 12.1.1.1
[R1-bfd-session-mybfd01]discriminator local 1  #本地标识 两台路由器的标识需要互为对称
[R1-bfd-session-mybfd01]discriminator remote 2
[R1-bfd-session-mybfd01]commit   # 确认提交配置
[R1-bfd-session-mybfd01]quit

[R1]ip route-static 2.2.2.0 255.255.255.0 12.1.1.2 preference 50 ?
  description  Add or delete description of unicast static route
  permanent    Specifies route permanent
  tag          Specifies route tag
  track        Specify track object
  <cr>         
# 关联需要心跳检测的路由
[R1]ip route-static 2.2.2.0 255.255.255.0 12.1.1.2 preference 50 track bfd-session mybfd01
Info: Succeeded in modifying route.
[R1]

# R2上配置:

[R2]bfd
[R2-bfd]quit
[R2]bfd mybfd02 bind peer-ip 12.1.1.1 source-ip 12.1.1.2
[R2-bfd-session-mybfd02]dis 
[R2-bfd-session-mybfd02]discriminator local 2
[R2-bfd-session-mybfd02]dis 
[R2-bfd-session-mybfd02]discriminator re 
[R2-bfd-session-mybfd02]discriminator remote 1
[R2-bfd-session-mybfd02]commit
[R2-bfd-session-mybfd02]quit
[R2]ip route-static 1.1.1.0 255.255.255.0 12.1.1.1 pre 
[R2]ip route-static 1.1.1.0 255.255.255.0 12.1.1.1 preference 50 track bfd-session mybfd02
Info: Succeeded in modifying route.
[R2]

3.调试命令的使用

分别在R1和R2上查看bfd会话:

<R1>dis bfd session static
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

1     2          12.1.1.2        Up        S_IP_PEER         -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0
<R1>dis bfd session static ver 
<R1>dis bfd session static verbose 
--------------------------------------------------------------------------------
Session MIndex : 256       (Multi Hop) State : Up        Name : mybfd01        
--------------------------------------------------------------------------------
  Local Discriminator    : 1                Remote Discriminator   : 2         
  Session Detect Mode    : Asynchronous Mode Without Echo Function             
  BFD Bind Type          : Peer IP Address                                     
  Bind Session Type      : Static                                              
  Bind Peer IP Address   : 12.1.1.2                                            
  Bind Interface         : -                                                   
  Track Interface        : -                                                   
  Bind Source IP Address : 12.1.1.1                                            
  FSM Board Id           : 0                TOS-EXP                : 7 (报文优先级为7,优先传输)        
  Min Tx Interval (ms)   : 1000             Min Rx Interval (ms)   : 1000      
  Actual Tx Interval (ms): 1000             Actual Rx Interval (ms): 1000      
  Local Detect Multi     : 3                Detect Interval (ms)   : 3000      
  Echo Passive           : Disable          Acl Number             : -         
  Destination Port       : 3784             TTL                    : 254       
  Proc Interface Status  : Disable          Process PST            : Disable   
  WTR Interval (ms)      : -                Local Demand Mode      : Disable   
  Active Multi           : 3                                                   
  Last Local Diagnostic  : No Diagnostic                                       
  Bind Application       : No Application Bind
  Session TX TmrID       : 1035             Session Detect TmrID   : 1036      
  Session Init TmrID     : -                Session WTR TmrID      : -         
  Session Echo Tx TmrID  : -                                                   
  PDT Index              : FSM-0 | RCV-0 | IF-0 | TOKEN-0                      
  Session Description    : -                                                   
--------------------------------------------------------------------------------

     Total UP/DOWN Session Number : 1/0
<R1>
<R1>
<R1>
<R2>dis bfd session static
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

2     1          12.1.1.1        Up        S_IP_PEER         -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0
<R2>dis bfd session static verbose
--------------------------------------------------------------------------------
Session MIndex : 256       (Multi Hop) State : Up        Name : mybfd02        
--------------------------------------------------------------------------------
  Local Discriminator    : 2                Remote Discriminator   : 1         
  Session Detect Mode    : Asynchronous Mode Without Echo Function             
  BFD Bind Type          : Peer IP Address                                     
  Bind Session Type      : Static                                              
  Bind Peer IP Address   : 12.1.1.1                                            
  Bind Interface         : -                                                   
  Track Interface        : -                                                   
  Bind Source IP Address : 12.1.1.2                                            
  FSM Board Id           : 0                TOS-EXP                : 7         
  Min Tx Interval (ms)   : 1000             Min Rx Interval (ms)   : 1000      
  Actual Tx Interval (ms): 1000             Actual Rx Interval (ms): 1000      
  Local Detect Multi     : 3                Detect Interval (ms)   : 3000      
  Echo Passive           : Disable          Acl Number             : -         
  Destination Port       : 3784             TTL                    : 254       
  Proc Interface Status  : Disable          Process PST            : Disable   
  WTR Interval (ms)      : -                Local Demand Mode      : Disable   
  Active Multi           : 3                                                   
  Last Local Diagnostic  : No Diagnostic                                       
  Bind Application       : No Application Bind
  Session TX TmrID       : 1040             Session Detect TmrID   : 1041      
  Session Init TmrID     : -                Session WTR TmrID      : -         
  Session Echo Tx TmrID  : -                                                   
  PDT Index              : FSM-0 | RCV-0 | IF-0 | TOKEN-0                      
  Session Description    : -                                                   
--------------------------------------------------------------------------------

     Total UP/DOWN Session Number : 1/0
<R2>

注:TOS-EXP : 7 (报文优先级为7,优先传输)

然后在R1上抓包,可以看到BFD心跳报文信息:

由上图看出,BFD的端口号是UDP 3784,发送时间是1000ms,也就是1s,检测时间是3s。

4.测试

断开优选链路,进行测试,过程略。


Python运维实践
Python运维实践,专注于互联网技术的总结与交流,内容涉及Python自动化运维、Django框架、园区网络技术、linux云计算、系统架构及网络空间安全等知识的实践与分享。
 最新文章