系列文章目录
ccnp
BGP实战拓扑
BGP基本配置
BGP(Border Gatreway Protcol)边界网关路由协议
BGP
实验目的
通过对外部BGP邻居的建立的两种情况的实验,从而学习到BGP外部邻居建立所需要关注的知识点。同时还将对如何将路由插入到BGP表中对BGP表和对BGP表的查看进行实验验证。
实验拓扑
本次实验拓扑由两台路由器搭建,R1和R2之间连接有两条以太网线缆。其中e0/0口采用12.0/24网段,而e0/1接口采用21.0/24网段。并且R1和R2上都存在地址为X.X.X.X/24的环回口。
实验步骤
- 首先配置好R1和R2各个接口的IP地址,保证直连接口可达。
- 开启R1和R2之间的E0/0接口,然后R1和R2之间通过该接口建立外部BGP邻居关系,并且R1的AS号为1,R2的AS号为2。
R1#conf t
R1(config)#int e0/0
R1(config-if)#ip add 10.10.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int e0/1
R1(config-if)#ip add 10.10.21.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int loo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#router bgp 1 //指明自己所属的AS号
R1(config-router)#neighbor 10.10.12.2 remote-as 2 //对端邻居路由器的IP地址和AS号
R1(config-router)#exit
R2#conf t
R2(config)#int e0/0
R2(config-if)#ip add 10.10.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int e0/1
R2(config-if)#ip add 10.10.21.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int loo0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#router bgp 2
R2(config-router)#neighbor 10.10.12.1 remote-as 1
R2(config-router)#exit
注意上述配置命令中,R1和R2之间的AS号码必须相互对照。则R1所指定的邻居的AS号码和R2本地配置的BGP的AS号码一致,反之亦然。等待一段时间,则发现路由器产生BGP日志,则表示邻居建立成功。
*Mar 1 00:26:37.175: %BGP-5-ADJCHANGE: neighbor 10.10.12.1 Up
此处总结一下建立外部BGP邻居所需要注意的:
- 两端路由器的AS号码必须相互对照一致
- BGP路由器的RID必须唯一
- 如果配置了认证,那么MD5认证必须一致
- BGP所需要建立的TCP连接必须能够正常建立
由于上面的配置并没有对BGP路由器的RID进行手工配置,所以按照选取RID的顺序,两台路由器的RID分别为环回口地址 1.1.1.1 和 2.2.2.2。
R1#
R1#show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 1
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.10.12.2 4 2 28 28 1 0 0 00:25:02 0
R2#show ip bgp summary
BGP router identifier 2.2.2.2, local AS number 2
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.10.12.1 4 1 28 28 1 0 0 00:25:24 0
但是为了RID的可预测性,推荐在BGP进程下手工指定RID。
R1#conf t
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#exit
R2#conf t
R2(config)#router bgp 2
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#exit
同时我们还可以在R1和R2之间对BGP邻居关系配置MD5认证。
R1(config)#router bgp 1
R1(config-router)#neighbor 10.10.12.2 password cisco
R1(config-router)#exit
R2(config)#router bgp 2
R2(config-router)#neighbor 10.10.12.1 password cisco
R2(config-router)#exit
最后,由于BGP是建立在TCP连接之上的。因此要能够正确的建立BGP邻居关系,TCP连接正常是先决条件。
默认BGP建立TCP连接的方式是:
- 和目的地址为neighbor X.X.X.X命令中的X.X.X.X命令中的X.X.X.X尝试建立TCP连接
- 源地址为出接口的IP地址
因此,必须保证两端TCP的源目的的IP地址的相互一致性。
- 删除对BGP邻居配置的命令,然后开启R1和R2之间的E0/1接口。
现在R1和R2之间存在冗余链路,如果R1和R2之间需要建立外部BGP邻居的话,应该如何建立呢?- 第一种方案是,在每条链路上都建立一个邻居关系,从而形成两个邻居关系。
- 第二种方案是,R1和R2上分别以环回口建立邻居关系,而底层可以采用静态路由使得去往各自的环回口的路由负载均衡。
很显然,使用第二种方案更加合理。因为每建立一个BGP连接都会消耗一定的系统资源,因此减少BGP邻居关系数量将有利于路由器的资源最大化利用。
我们用R1和R2的环回口相互建立邻居关系,但首先保证环回口可达性。
在R1和R2上配置静态路由,并且使之负载均衡。
R1(config)#ip route 2.2.2.0 255.255.255.0 10.10.12.2
R1(config)#ip route 2.2.2.0 255.255.255.0 10.10.21.2
R2(config)#ip route 1.1.1.0 255.255.255.0 10.10.12.1
R2(config)#ip route 1.1.1.0 255.255.255.0 10.10.21.1
接着进入BGP进程中,利用环回口建立邻居关系。
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 2.2.2.2 remote-as 2
R1(config-router)#exit
R2(config)#router bgp 2
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 1.1.1.1 remote-as 1
R2(config-router)#exit
但是在完成上述配置之后,并没有发现邻居成功建立。
这是因为默认外部BGP邻居之间所发送的所有数据包的TTL值,都为1。
由于此时我们利用环回口建立邻居,所以跳数大于1,因此必须修改TTL值。
R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 ebgp-multihop 2 //将TTL值修改为2
R1(config-router)#exit
R2(config)#router bgp 2
R2(config-router)#neighbor 1.1.1.1 ebgp-multihop 2
R2(config-router)#exit
然后等待一段时间,依然发现BGP邻居无法建立,结合上个步骤中总结的BGP邻居建立的注意点,我们发现,应该是TCP连接建立的IP地址无法对应。
R1尝试和2.2.2.2建立TCP,源IP为10.10.12.1 或者 10.10.21.1
R2尝试和1.1.1.1建立TCP,源IP为10.10.12.2 或者 10.10.21.2
因此,必须修改建立TCP的源地址。
R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 update-source loo0
R1(config-router)#exit
R2(config)#router bgp 2
R2(config-router)#neighbor 1.1.1.1 update-source loo0
R2(config-router)#exit
终于,R1和R2之间的BGP邻居关系正常。
*Mar 1 02:35:05.535: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up
这种冗余物理链路的BGP邻居关系,我们可以采用建立环回口的方式,这是一条逻辑的邻居关系,下层位IGP。因此如果冗余的话需要由IGP来决定。
下面给出R1和R2之间的所有邻居配置:
R1(config)#router bgp 1
R1(config-router)#no synchronization
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#bgp log-neighbor-changes
R1(config-router)#neighbor 2.2.2.2 remote-as 2
R1(config-router)#neighbor 2.2.2.2 ebgp-multihop 2
R1(config-router)#neighbor 2.2.2.2 update-source loo0
R1(config-router)#no auto-summary
R2(config)#router bgp 2
R2(config-router)#no synchronization
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#bgp log-neighbor-changes
R2(config-router)#neighbor 1.1.1.1 remote-as 1
R2(config-router)#neighbor 1.1.1.1 ebgp-multihop 2
R2(config-router)#neighbor 1.1.1.1 update-source loo0
R2(config-router)#no auto-summary
- 验证BGP邻居关系。
BGP邻居建立要经历以下几个状态:
ldle:BGP被管理性down或者在尝试下一次建立
Connect:BGP进程在等待down或者尝试下一次建立。这个状态无法判断TCP连接是否建立成功。
Active:TCP连接正在建立,同时BGP还未发出BGP数据包。
Opensent:TCP连接建立完成,同时BGP发出BGP数据包。
Openconfirm:收到了邻居的Open数据包,接着BGP只需要发送keeplive数据包保活。
Established:BGP邻居连接建立完成。
查看BGP邻居关系的命令如下:
上述命令可以获知本地RID和AS,以及邻居的AS,建立时间已及状态。
注意,状态一栏,如果是数字的话,代表已经完成BGP邻居的建立。
R1#show ip bgp neighbor 2.2.2.2
BGP neighbor is 2.2.2.2, remote AS 2, external link
BGP version 4, remote router ID 2.2.2.2
BGP state = Established, up for 02:07:04
Last read 00:00:04, last write 00:00:04, hold time is 180, keepalive interval is 60 seconds
Neighbor capabilities:
Route refresh: advertised and received(old & new)
Address family IPv4 Unicast: advertised and received
Message statistics:
InQ depth is 0
OutQ depth is 0
Sent Rcvd
Opens: 1 1
Notifications: 0 0
Updates: 0 0
Keepalives: 130 130
Route Refresh: 0 0
Total: 131 131
Default minimum time between advertisement runs is 30 seconds
For address family: IPv4 Unicast
BGP table version 1, neighbor version 1/0
Output queue size : 0
Index 1, Offset 0, Mask 0x2
1 update-group member
Sent Rcvd
Prefix activity: ---- ----
Prefixes Current: 0 0
Prefixes Total: 0 0
Implicit Withdraw: 0 0
Explicit Withdraw: 0 0
Used as bestpath: n/a 0
Used as multipath: n/a 0
Outbound Inbound
Local Policy Denied Prefixes: -------- -------
Total: 0 0
Number of NLRIs in the update sent: max 0, min 0
Connections established 1; dropped 0
Last reset never
External BGP neighbor may be up to 2 hops away.
Connection state is ESTAB, I/O status: 1, unread input bytes: 0
Connection is ECN Disabled, Mininum incoming TTL 0, Outgoing TTL 2
Local host: 1.1.1.1, Local port: 38606
Foreign host: 2.2.2.2, Foreign port: 179
Enqueued packets for retransmit: 0, input: 0 mis-ordered: 0 (0 bytes)
Event Timers (current time is 0x102A524):
Timer Starts Wakeups Next
Retrans 132 2 0x0
TimeWait 0 0 0x0
AckHold 129 44 0x0
SendWnd 0 0 0x0
KeepAlive 0 0 0x0
GiveUp 0 0 0x0
PmtuAger 0 0 0x0
DeadWait 0 0 0x0
iss: 128684281 snduna: 128686797 sndnxt: 128686797 sndwnd: 16061
irs: 3715000363 rcvnxt: 3715002879 rcvwnd: 16061 delrcvwnd: 323
SRTT: 300 ms, RTTO: 303 ms, RTV: 3 ms, KRTT: 0 ms
minRTT: 20 ms, maxRTT: 300 ms, ACK hold: 200 ms
Flags: active open, nagle
IP Precedence value : 6
Datagrams (max data segment is 536 bytes):
Rcvd: 233 (out of order: 0), with data: 130, total data bytes: 2534
Sent: 183 (retransmit: 2, fastretransmit: 0, partialack: 0, Second Congestion: 0), with data: 131, total data bytes: 2534
R1#
show ip bgp neighbor //命令显示了关于邻居更加详细的信息。
- 能够对BGP邻居关系进行管理性关闭。
R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 shutdown
R1(config-router)#
*Mar 1 04:53:41.510: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Down Admin. shutdown
R1(config-router)#exit
如果需要重新开启邻居,则配置如下命令:
R1(config)#router bgp 1
R1(config-router)#no neighbor 2.2.2.2 shutdown
R1(config-router)#
*Mar 1 04:58:07.570: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up
R1(config-router)#exit
- 可以采用两种方式将路由插入到BGP表中。
| 使用network命令
| 使用重分布
在R1上建立3个环回口,loopback 1,loopback 2 和 loopback 3,地址分别为 192.168.1.1/24,192.168.2.1/24,192.168.3.1/24。
将1.1/24使用network插入BGP表,直连接口使用重分布,并且使用route-map只允许发布2.1/24.
R1(config)#int loo1
R1(config-if)#ip add 192.168.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#int loo2
R1(config-if)#ip add 192.168.2.1 255.255.255.0
R1(config-if)#exit
R1(config)#int loo3
R1(config-if)#ip add 192.168.3.1 255.255.255.0
R1(config-if)#exit
R1(config)#router bgp 1
R1(config-router)#network 192.168.1.0 mask 255.255.255.0
R1(config-router)#exit
注意,如果使用network命令,该命令的含义为宣告某个网络.该网络必须已经存在本地路由表中。
如果不如mask的话,宣告的网络必须为主类。
当存在主类网络,不管是否配置了auto-aummary,主类网络都加入BGP表中不存在主类网络,而有明细之网的话,配置auto-summary,将会把子网汇总成为主类在加了BGP表中。
如果加入mask的话,那么掩码长度必须严格匹配。
R1(config)#ip prefix-list BGP per 192.168.2.1/24 建立一条前缀列表,只允许192.168.2.1 路由
R1(config)#route-map bgp per 10
R1(config-route-map)#match ip add prefix-list BGP
R1(config-route-map)#exit
R1(config)#router bgp 1
R1(config-router)#redistribute connected route-map bgp
R1(config-router)#exit
- 查看R2的BGP表项,验证上面配置的命令。
R2#show ip bgp
BGP table version is 10, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
r 1.1.1.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
r 10.10.12.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
r 10.10.21.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
* 192.168.1.0 10.10.12.1 0 0 1 i
*> 1.1.1.1 0 0 1 i
* 192.168.2.0 10.10.12.1 0 0 1 ?
*> 1.1.1.1 0 0 1 ?
* 192.168.3.0 10.10.12.1 0 0 1 ?
*> 1.1.1.1 0 0 1 ?
R2#
通过上面的输出,我们要注意BGP表的格式。
例如,192.168.1.0表项,之前存在符号*,代表可用,如果缺失,往往是下一跳不可达或者存在更优路由。>符号表明为最佳路由,并且将插入路由表中。
同时还给出了下一跳属性,MED值,本地优先级,权重,AS-PATH属性和源起属性。
可以发现,我们所要求的都已经完成。
对于show ip bgp 命令,存在以下重要的选项:
show ip bgp 0.0.0.0 0.0.0.0 查看默认路由
show ip bgp prefix{sbnet-mast}基于具体前缀进行查看
show ip bgp neighbor ip-address received-routes 查看从某个邻居收到的路由,显示结果为入站过滤之前
show ip bgp neighbor ip-address routes 查看从某个邻居收到的路由,显示结果为入站过滤之后
show ip bgp neighbor ip-address advertised-routes 查看通告给某个邻居的路由,显示结果为出站过滤之后
- 最后,在R1上为192.168.1.0/24和192.168.2.0/24进行汇总,通告给R2.。
R1(config)#router bgp 1
R1(config-router)#aggregate-address 192.168.0.0 255.255.252.0 summary-only
注意上述命令中关键字 summary-only,如果不加,则会使得除了汇总路由,明细路由都将会被通告给邻居。
在R2上查看汇总结果。
R2#show ip bgp
BGP table version is 17, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
r 1.1.1.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
r 10.10.12.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
r 10.10.21.0/24 10.10.12.1 0 0 1 ?
r> 1.1.1.1 0 0 1 ?
* 192.168.0.0/22 10.10.12.1 0 0 1 i
*> 1.1.1.1 0 0 1 i
R2#
明细路由消失,取而待之的是汇总路由。