边界网关协议——BGP

记录每日所学

一、边界网关协议(BGP)

  • 是运行于 TCP 上的一种自治系统的路由协议。
  • BGP 是唯一一个用来处理像因特网大小的网络的协议,也是唯一能够妥善处理好不相关路由域间的多路连接的协议。

1、BGP的特征

  • 传输协议:tcp 端口号179
  • BGP是外部路由协议,用来在AS之间传递数据
  • 是一种增强的路径矢量路由协议
  • 拥有可靠的路由更新机制
  • 无路由环路设计
  • 为路由条目覆带属性思想
  • 支持CIDR(无类别域间路由)
  • 丰富的路由过度和路由策略
  • 无需周期性更新
  • 路由更新时发送增量路由
  • 周期性发送KeepAlive报文以保持TCP直通性

2、BGP报文

  • Open报文:用来与相邻路由器建立关系
  • Update报文:用来发送路由的信息,以及列出要撤销的多条路由
  • Notification报文:用来发送检测到的差错,并中断连接
  • Route-Fresh报文:用来要求对等体重新发送指定地址族的路由信息
  • Keep Alive报文:用来确认open报文,和周期性的证实邻站关系

3、BGP状态机

在这里插入图片描述

  • ldle (空闲)状态
    BGP总以ldle状态为起点,该状态拒绝所有入站的连接。只有在BGP起动之后,BGP进程将初始化所有BGP资源,初始化去往邻居的TCP连接,监听来自邻居的TCP初始化消息,并更改为连接状态。启动事件一般是配置BGP进程。
  • Connect(连接)状态
    进入Connect状态后,BGP进程将一直等待TCP连接的完成(三次握手),当TCP连接建立成功,BGP将会向邻居发送Open消息,并进入OpenSent(打开发送)状态。如果TCP会话没有建立,BGP将继续监听邻居初始化的连接,开启连接重试定时器,迁移到Active(激活)状态。Connect→→OpenSent(TCP连接建立);Connect→→Active(TCP连接暂未建立)。
  • Active(激活)状态
    该状态下,BGP进程继续尝试和邻居建立TCP连接,如果TCP连接建立成功,BGP进程清除连接重试定时器,完成初始化过程,并向邻居发送Open报文,迁移到OpenSent(打开发送)状态。
    如果连接重试定时器到期BGP进程依然处在激活状态,进程将返回连接状态,监听邻居发起的TCP会话,这个过程将反复循环,直到监听到由邻居发起的TCP会话。
  • OpenSent(打开发送)状态
    进入了该状态,已经发送了Open消息,BGP将一直等待来自邻居的Open消息。一旦接收到Open消息后,将检查该消息的每一个字段,如果有差错,将会发送Notification消息迁入Idle状态。
    如果接收到的Open消息没错,就会发送Keepalive消息并商讨Keepalive定时器和Keepalive发送的时间。 并迁移到OpenConfirm(打开确认)状态。
  • OpenConfirm(打开确认)状态
    进入了这个状态下,BGP进程将等待邻居确认的Keepalive或Notification消息。如果接收到的是Keepalive消息则迁移到Established(建立)状态,如果是Notification消息那么就将迁移到Idle状态。
  • Established(建立)状态
    进入了这个状态就说明了BGP的对等连接正式建立了,对等体之间交互Update,Keepalive和Notification消息,如果接受到的是Update或Keepalive消息,则重启保持定时器,如果接受到一个Notification消息,则会迁移到Idle状

4、对等体交互原则

  • 从IBGP对等体获得的BGP路由,BGP设备只传递给他的EBGP对等体
  • 从EBGP对等体获得的BGP路由,BGP设备传递给它所有的EBGP和IBGP对等体(对等体是IBGP只能传1跳,对等体是EBGP则不受限制)
  • 当存在多条到达同一地址的有效路由时,BGP设备只将最优路由发布给对等体
  • 路由更新时,BGP设备只发送更新的BGP路由
  • 所有对等体发送的路由,BGP设备都会接收
  • 所有EBGP对等体在传递过程中下一跳改变
  • 所有IBGP对等体在传递过程中下一跳不变
  • 默认EBGP传递时,TTL值为1
  • 默认IBGP传递时,TTL值为255

5、建立邻居注意点

- 直连建立邻居需要注意的点
在这里插入图片描述

  • 建立IBGP邻居时要让下一跳可达,处于边界的IBGP邻居需要将下一跳指向自己,这样才能建立IBGP邻居

-用环回口建立邻居需要注意的点
在这里插入图片描述

  • 需要修改更新源,默认更新源是物理口,你需要修改成环回口。建立IBGP邻居时要保障下一跳可达,处于边界的IBGP邻居需要将下一跳指向自己,这样才能建立IBGP邻居
  • 建立EBGP邻居时因为EBGP只能传一跳,因而,在建立EBGP邻居时,需要修改EBGP多跳的跳数为2以上(自己环回到对端环回是两跳,默认一跳)

6、关于为什么要用环回口建邻居

  • 原因是环回口稳定,只要路由器启动着,环回口就不DOWN,而物理链路可能会受线路或者接口等因素的影响导致邻居关系有问题,因而一般BGP建立邻居都是环回口来建

7、BGP选路规则

  • 若去往目的网络的路由下一跳不可达,则可以忽略此路由
  • Preferred-Value优先级以数值高的路由优先
  • Local-Preference优先级以数值高的路由优先 默认100
  • 聚合路由优先级高于非聚合路由
  • 本地手动聚合路由的优先级高于本地自动聚合的路由
  • 本地通过Network命令了入的路由的优先级高于本地通过Import-route命令的入的路由
  • AS路径长度最短(最少个数)的路径优先级高
  • 比较origin属性,IGP优先级高于EGP,EGP优先级高于Incomplete
  • 选择MED优先级较小的路由 默认是0
  • EBGP路由优先级高于IBGP路由
  • BGP优先级选择到BGP下一跳的IGP度量最高的路径
  • 当以上全部相同,则为等价路由,可以负载分担(AS-PATH必须一致),当负载分担时,以下3条原则无效
  • 比较Cluster-List长度,短者优先
  • 比较Originator_ID,如果没有,则比较Router-ID,选择数值较小的路径
  • 比较对等体的IP地址,选择IP地址数值最小的路径

二、实验

1、要求
在这里插入图片描述
AR2:配置
dis current-configuration
[V200R003C00]

sysname AR2

snmp-agent local-engineid 800007DB03000000000000
snmp-agent

clock timezone China-Standard-Time minus 08:00:00

portal local-server load flash:/portalpage.zip

drop illegal-mac alarm

wlan ac-global carrier id other ac id 0

set cpu-usage threshold 80 restore 75

aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher % % K8m.Nt84DZ}e#<0`8bmE3Uw}% %
local-user admin service-type http

firewall zone Local
priority 15

interface GigabitEthernet0/0/0
ip address 12.1.1.1 255.255.255.0

interface GigabitEthernet0/0/1
ip address 45.1.1.1 255.255.255.0

interface GigabitEthernet0/0/2

interface NULL0

interface LoopBack0
ip address 1.1.1.1 255.255.255.255

bgp 100
peer 2.2.2.2 as-number 200
peer 2.2.2.2 ebgp-max-hop 255
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 200
peer 3.3.3.3 ebgp-max-hop 255
peer 3.3.3.3 connect-interface LoopBack0

ipv4-family unicast
undo synchronization
network 1.1.1.1 255.255.255.255
network 12.1.1.0 255.255.255.0
network 45.1.1.0 255.255.255.0
peer 2.2.2.2 enable
peer 3.3.3.3 enable

ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 45.1.1.2

user-interface con 0
authentication-mode password
idle-timeout 0 0
user-interface vty 0 4
user-interface vty 16 20

wlan ac

return

AR1:配置
dis current-configuration
[V200R003C00]

sysname AR1

snmp-agent local-engineid 800007DB03000000000000
snmp-agent

clock timezone China-Standard-Time minus 08:00:00

portal local-server load flash:/portalpage.zip

drop illegal-mac alarm

wlan ac-global carrier id other ac id 0

set cpu-usage threshold 80 restore 75

acl number 2000
rule 5 permit source 1.1.1.1 0

aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher % % K8m.Nt84DZ}e#<0`8bmE3Uw}% %
local-user admin service-type http

firewall zone Local
priority 15

interface GigabitEthernet0/0/0
ip address 12.1.1.2 255.255.255.0

interface GigabitEthernet0/0/1
ip address 23.1.1.1 255.255.255.0

interface GigabitEthernet0/0/2

interface NULL0

interface LoopBack0
ip address 2.2.2.2 255.255.255.255

bgp 200
peer 1.1.1.1 as-number 100
peer 1.1.1.1 ebgp-max-hop 255
peer 1.1.1.1 connect-interface LoopBack0
peer 3.3.3.3 as-number 200
peer 3.3.3.3 connect-interface LoopBack0
peer 4.4.4.4 as-number 200
peer 4.4.4.4 connect-interface LoopBack0

ipv4-family unicast
undo synchronization
network 1.1.1.1 255.255.255.255
network 2.2.2.2 255.255.255.255
network 3.3.3.3 255.255.255.255
network 4.4.4.4 255.255.255.255
network 12.1.1.0 255.255.255.0
network 23.1.1.0 255.255.255.0
peer 1.1.1.1 enable
peer 3.3.3.3 enable
peer 3.3.3.3 next-hop-local
peer 4.4.4.4 enable
peer 4.4.4.4 route-policy as export
peer 4.4.4.4 next-hop-local

ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 23.1.1.0 0.0.0.255

route-policy as permit node 10
if-match acl 2000
apply as-path 111 222 333 444 additive

route-policy as permit node 20

ip route-static 1.1.1.1 255.255.255.255 12.1.1.1

user-interface con 0
authentication-mode password
idle-timeout 0 0
user-interface vty 0 4
user-interface vty 16 20

wlan ac

return

AR3:配置
dis current-configuration
[V200R003C00]

sysname AR3

snmp-agent local-engineid 800007DB03000000000000
snmp-agent

clock timezone China-Standard-Time minus 08:00:00

portal local-server load flash:/portalpage.zip

drop illegal-mac alarm

wlan ac-global carrier id other ac id 0

set cpu-usage threshold 80 restore 75

acl number 2000
rule 5 permit source 4.4.4.4 0

aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher % % K8m.Nt84DZ}e#<0`8bmE3Uw}% %
local-user admin service-type http

firewall zone Local
priority 15

interface GigabitEthernet0/0/0
ip address 34.1.1.1 255.255.255.0

interface GigabitEthernet0/0/1
ip address 45.1.1.2 255.255.255.0

interface GigabitEthernet0/0/2

interface NULL0

interface LoopBack0
ip address 3.3.3.3 255.255.255.255

bgp 200
peer 1.1.1.1 as-number 100
peer 1.1.1.1 ebgp-max-hop 255
peer 1.1.1.1 connect-interface LoopBack0
peer 2.2.2.2 as-number 200
peer 2.2.2.2 connect-interface LoopBack0
peer 4.4.4.4 as-number 200
peer 4.4.4.4 connect-interface LoopBack0

ipv4-family unicast
undo synchronization
network 1.1.1.1 255.255.255.255
network 2.2.2.2 255.255.255.255
network 3.3.3.3 255.255.255.255
network 4.4.4.4 255.255.255.255
network 34.1.1.0 255.255.255.0
network 45.1.1.0 255.255.255.0
peer 1.1.1.1 enable
peer 1.1.1.1 route-policy med export
peer 2.2.2.2 enable
peer 2.2.2.2 next-hop-local
peer 4.4.4.4 enable
peer 4.4.4.4 next-hop-local

ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 34.1.1.0 0.0.0.255

route-policy med permit node 10
if-match acl 2000
apply cost + 50

route-policy med permit node 20

ip route-static 1.1.1.1 255.255.255.255 45.1.1.1

user-interface con 0
authentication-mode password
idle-timeout 0 0
user-interface vty 0 4
user-interface vty 16 20

wlan ac

return

AR4:配置
dis current-configuration
[V200R003C00]

sysname AR4

snmp-agent local-engineid 800007DB03000000000000
snmp-agent

clock timezone China-Standard-Time minus 08:00:00

portal local-server load flash:/portalpage.zip

drop illegal-mac alarm

wlan ac-global carrier id other ac id 0

set cpu-usage threshold 80 restore 75

aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher % % K8m.Nt84DZ}e#<0`8bmE3Uw}% %
local-user admin service-type http

firewall zone Local
priority 15

interface GigabitEthernet0/0/0
ip address 34.1.1.2 255.255.255.0

interface GigabitEthernet0/0/1
ip address 23.1.1.2 255.255.255.0

interface GigabitEthernet0/0/2

interface NULL0

interface LoopBack0
ip address 4.4.4.4 255.255.255.255

bgp 200
peer 2.2.2.2 as-number 200
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 200
peer 3.3.3.3 connect-interface LoopBack0

ipv4-family unicast
undo synchronization
network 4.4.4.4 255.255.255.255
network 23.1.1.0 255.255.255.0
network 34.1.1.0 255.255.255.0
peer 2.2.2.2 enable
peer 3.3.3.3 enable

ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 4.4.4.4 0.0.0.0
network 23.1.1.0 0.0.0.255
network 34.1.1.0 0.0.0.255

user-interface con 0
authentication-mode password
idle-timeout 0 0
user-interface vty 0 4
user-interface vty 16 20

wlan ac

return

2、测试:
在这里插入图片描述
在这里插入图片描述