目录
第三章 BGP协议特性与配置
实验 3-1 IBGP与EBGP
学习目的
·掌握区域内部BGP的配置方法
·掌握多区域BGP的配置方法
·观察BGP的邻居表和数据库
·掌握BGP更新源的配置方法
·掌握EBGP多跳的配置方法
·观察IBGP和EBGP中路由的下一跳的变化
·掌握IBGP中下一跳的配置
·掌握BGP的Network命令的配置方法
拓扑图
图3-1 IBGP与EBGP
场景
你是公司的网络管理员。公司的网络采用了BGP协议作为路由协议。公司的网络由多个自治系统组成,不同的分支机构使用了不同的AS号,现在你需要完成公司网络的搭建工作。在公司总部使用了OSPF作为IGP,公司内部不同分支机构使用的是私有的BGP AS号。在完成网络搭建以后,你还需要观察BGP路由信息的传递。
学习任务
步骤一.基础配置与IP编址
给所有路由器配置IP地址和掩码,其中R4和R5的loopback 1接口掩码为24位,模拟用户网络。
<R1>system-view
Enter system view, return user view with Ctrl+Z.
[R1]interface Serial 1/0/0
[R1-Serial1/0/0]ip address 10.0.12.1 24
[R1-Serial1/0/0]quit
[R1]interface Serial 3/0/0
[R1-Serial3/0/0]ip address 10.0.14.1 24
[R1-Serial3/0/0]quit
[R1]interface LoopBack 0
[R1-LoopBack0]ip address 10.0.1.1 32
[R1-LoopBack0]quit
<R2>system-view
Enter system view, return user view with Ctrl+Z.
[R2]interface Serial 1/0/0
[R2-Serial1/0/0]ip address 10.0.12.2 24
[R2-Serial1/0/0]quit
[R2]interface Serial 2/0/0
[R2-Serial2/0/0]ip address 10.0.23.2 24
[R2-Serial2/0/0]quit
[R2]interface LoopBack 0
[R2-LoopBack0]ip address 10.0.2.2 32
<R3>system-view
Enter system view, return user view with Ctrl+Z.
[R3]interface Serial 2/0/0
[R3-Serial2/0/0]ip address 10.0.23.3 24
[R3-Serial2/0/0]quit
[R3]interface Serial 3/0/0
[R3-Serial3/0/0]ip address 10.0.35.3 24
[R3-Serial3/0/0]quit
[R3]interface LoopBack 0
[R3-LoopBack0]ip address 10.0.3.3 32
<R4>system-view
Enter system view, return user view with Ctrl+Z.
[R4]interface Serial 1/0/0
[R4-Serial1/0/0]ip address 10.0.14.4 24
[R4-Serial1/0/0]quit
[R3]interface LoopBack 0
[R4-LoopBack0]ip address 10.0.4.4 32
<R5>system-view
Enter system view, return user view with Ctrl+Z.
[R5]interface Serial 1/0/0
[R5-Serial1/0/0]ip address 10.0.35.5 24
[R5-Serial1/0/0]quit
[R3]interface LoopBack 0
[R5-LoopBack0]ip address 10.0.5.5 32
测试各直连链路的连通性。
<R1>ping -c 1 10.0.12.2
PING 10.0.12.2: 56 data bytes, press CTRL_C to break
Reply from 10.0.12.2: bytes=56 Sequence=1 ttl=255 time=34 ms
--- 10.0.12.2 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 34/34/34 ms
<R1>ping -c 1 10.0.14.4
PING 10.0.14.4: 56 data bytes, press CTRL_C to break
Reply from 10.0.14.4: bytes=56 Sequence=1 ttl=255 time=40 ms
--- 10.0.14.4 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 40/40/40 ms
<R3>ping -c 1 10.0.23.2
PING 10.0.23.2: 56 data bytes, press CTRL_C to break
Reply from 10.0.23.2: bytes=56 Sequence=1 ttl=255 time=33 ms
--- 10.0.23.2 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 33/33/33 ms
<R3>ping -c 1 10.0.35.5
PING 10.0.35.5: 56 data bytes, press CTRL_C to break
Reply from 10.0.35.5: bytes=56 Sequence=1 ttl=255 time=35 ms
--- 10.0.35.5 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 35/35/35 ms
显示直连联络连通性正常。
步骤二.配置区域内IGP
在AS 64512中使用OSPF作为IGP,将Loopback 0连接的网段发布进OSPF。R1的S1/0/0连接的网段运行OSPF。
[R1]router id 10.0.1.1
[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 10.0.12.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 10.0.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]quit
[R1-ospf-1]quit
R2的S1/0/0和S2/0/0连接的网段运行OSPF。
[R2]router id 10.0.2.2
[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.12.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.23.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]quit
[R2-ospf-1]quit
R3的S2/0/0连接的网段运行OSPF。
[R3]router id 10.0.3.3
[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.23.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]quit
[R3-ospf-1]quit
注意在使用network命令时,通配符掩码使用0.0.0.0。
配置完成后察看OSPF的邻居关系是否建立。
[R2]display ospf peer
OSPF Process 1 with Router ID 10.0.2.2
Neighbors
Area 0.0.0.0 interface 10.0.12.2(Serial1/0/0)'s neighbors
Router ID: 10.0.1.1 Address: 10.0.12.1
State: Full Mode:Nbr is Slave Priority: 1
DR: None BDR: None MTU: 0
Dead timer due in 37 sec
Retrans timer interval: 5
Neighbor is up for 00:01:05
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 10.0.23.2(Serial2/0/0)'s neighbors
Router ID: 10.0.3.3 Address: 10.0.23.3
State: Full Mode:Nbr is Master Priority: 1
DR: None BDR: None MTU: 0
Dead timer due in 33 sec
Retrans timer interval: 5
Neighbor is up for 00:00:19
Authentication Sequence: [ 0 ]
查看所有路由器的路由表。检查是否学习到对端设备Loopback接口网段的路由。
[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 15
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial1/0/0
10.0.3.3/32 OSPF 10 3124 D 10.0.12.2 Serial1/0/0
10.0.12.0/24 Direct 0 0 D 10.0.12.1 Serial1/0/0
10.0.12.1/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.12.2/32 Direct 0 0 D 10.0.12.2 Serial1/0/0
10.0.12.255/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.14.0/24 Direct 0 0 D 10.0.14.1 Serial3/0/0
10.0.14.1/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.14.4/32 Direct 0 0 D 10.0.14.4 Serial3/0/0
10.0.14.255/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.23.0/24 OSPF 10 3124 D 10.0.12.2 Serial1/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/3 Direct 0 0 D 127.0.0.1 InLoopBack0
[R2]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 15
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 OSPF 10 1562 D 10.0.12.1 Serial1/0/0
10.0.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.3.3/32 OSPF 10 1562 D 10.0.23.3 Serial2/0/0
10.0.12.0/24 Direct 0 0 D 10.0.12.2 Serial1/0/0
10.0.12.1/32 Direct 0 0 D 10.0.12.1 Serial1/0/0
10.0.12.2/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.12.255/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.23.0/24 Direct 0 0 D 10.0.23.2 Serial2/0/0
10.0.23.2/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.23.3/32 Direct 0 0 D 10.0.23.3 Serial2/0/0
10.0.23.255/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[R3]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 16 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.2.2/32 OSPF 10 1562 D 10.0.23.2 Serial2/0/0
10.0.3.3/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.12.0/24 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.23.0/24 Direct 0 0 D 10.0.23.3 Serial2/0/0
10.0.23.2/32 Direct 0 0 D 10.0.23.2 Serial2/0/0
10.0.23.3/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.23.255/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.35.0/24 Direct 0 0 D 10.0.35.3 Serial3/0/0
10.0.35.3/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.35.5/32 Direct 0 0 D 10.0.35.5 Serial3/0/0
10.0.35.255/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32Direct 0 0 D 127.0.0.1 InLoopBack0
从R1,R2,R3的路由表中,可以看到学习每一台路由器都能够学到其他2台路由器的loopback 0接口连接的网段的路由。
步骤三.建立IBGP对等体
在R1、R2、R3上配置IBGP全互联。使用Loopback0地址作为更新源。
[R1]bgp 64512
[R1-bgp]peer 10.0.2.2 as-number 64512
[R1-bgp]peer 10.0.2.2 connect-interface LoopBack 0
[R1-bgp]peer 10.0.3.3 as-number 64512
[R1-bgp]peer 10.0.3.3 connect-interface LoopBack 0
[R1-bgp]quit
[R2]bgp 64512
[R2-bgp]peer 10.0.1.1 as-number 64512
[R2-bgp]peer 10.0.1.1 connect-interface loopback 0
[R2-bgp]peer 10.0.3.3 as-number 64512
[R2-bgp]peer 10.0.3.3 connect-interface LoopBack 0
[R2-bgp]quit
[R3]bgp 64512
[R3-bgp]peer 10.0.1.1 as-number 64512
[R3-bgp]peer 10.0.1.1 connect-interface loopback 0
[R3-bgp]peer 10.0.2.2 as-number 64512
[R3-bgp]peer 10.0.2.2 connect-interface LoopBack 0
[R3-bgp]quit
使用display tcp status查看TCP端口连接状态。
[R2]display tcp status
TCPCB Tid/Soid Local Add:port Foreign Add:port VPNID State
37a32f14 76 /1 0.0.0.0:80 0.0.0.0:0 23553 Listening
37a33b34 239/2 0.0.0.0:179 10.0.1.1:0 0 Listening
39052914 239/6 0.0.0.0:179 10.0.3.3:0 0 Listening
37a3321c 76 /3 0.0.0.0:443 0.0.0.0:0 23553 Listening
39052c1c 239/11 10.0.2.2:179 10.0.3.3:54086 0 Established
3905260c 239/5 10.0.2.2:61635 10.0.1.1:179 0 Established
从表项中我们可以观察到Local Add为10.0.2.2(即为R2的Loopback0接口地址),端口号为179(BGP协议的TCP端口号)。与10.0.3.3和10.0.1.1的状态已经为Established,说明R2和R1,R3的TCP连接已建立。
使用display bgp peer察看各路由器BGP邻居关系状态。
[R1]display bgp peer
BGP local router ID : 10.0.1.1
Local AS number : 64512
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
10.0.2.2 4 64512 273 277 0 02:15:53 Established 0
10.0.3.3 4 64512 276 276 0 02:15:53 Established 0
[R2]display bgp peer
BGP local router ID : 10.0.2.2
Local AS number : 64512
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
10.0.1.1 4 64512 38 38 0 00:18:02 Established 0
10.0.3.3 4 64512 1000 1000 0 16:38:38 Established 0
[R3]display bgp peer
BGP local router ID : 10.0.3.3
Local AS number : 64512
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
10.0.1.1 4 64512 39 39 0 00:18:35 Established 0
10.0.2.2 4 64512 1001 1001 0 16:39:11 Established 0
可以看到3台路由器之间的BGP邻居关系处于Established状态,说明邻居关系已建立。
在R1上在BGP进程下使用timer修改BGP的keep alive时间为30秒,hold时间为90秒。观察R1与R2的对等体关系建立是否有问题,使用display bgp peer verbose命令观察建立以后协商的间隔时间是多少。
[R1-bgp] bgp 64512
[R1-bgp] timer keepalive 30 hold 90
Warning: Changing the parameter in this command resets the peer session. Continue?[Y/N]:y
[R1-bgp]quit
注意:修改此参数将引起bgp邻居重启。
[R2]display bgp peer verbose
BGP Peer is 10.0.1.1, remote AS 64512
Type: IBGP link
BGP version 4, Remote router ID 10.0.1.1
Update-group ID: 1
BGP current state: Established, Up for 00h07m19s
BGP current event: KATimerExpired
BGP last state: OpenConfirm
BGP Peer Up count: 2
Received total routes: 0
Received active routes total: 0
Advertised total routes: 0
Port: Local - 50117 Remote - 179
Configured: Connect-retry Time: 32 sec
Configured: Active Hold Time: 180 sec Keepalive Time:60 sec
Received : Active Hold Time: 90 sec
Negotiated: Active Hold Time: 90 sec Keepalive Time:30 sec
Peer optional capabilities:
Peer supports bgp multi-protocol extension
Peer supports bgp route refresh capability
Peer supports bgp 4-byte-as capability
Address family IPv4 Unicast: advertised and received
Received: Total 16 messages
Update messages 0
Open messages 1
KeepAlive messages 15
Notification messages 0
Refresh messages 0
Sent: Total 16 messages
Update messages 0
Open messages 1
KeepAlive messages 15
Notification messages 0
Refresh messages 0
Authentication type configured: None
Last keepalive received: 2011/12/07 08:33:52
Minimum route advertisement interval is 15 seconds
Optional capabilities:
Route refresh capability has been enabled
4-byte-as capability has been enabled
Connect-interface has been configured
Peer Preferred Value: 0
Routing policy configured:
No routing policy is configured
BGP Peer is 10.0.3.3, remote AS 64512
Type: IBGP link
BGP version 4, Remote router ID 10.0.3.3
Update-group ID: 1
BGP current state: Established, Up for 16h28m14s
BGP current event: RecvKeepalive
BGP last state: OpenConfirm
BGP Peer Up count: 1
Received total routes: 0
Received active routes total: 0
Advertised total routes: 0
Port: Local - 179 Remote - 49663
Configured: Connect-retry Time: 32 sec
Configured: Active Hold Time: 180 sec Keepalive Time:60 sec
Received : Active Hold Time: 180 sec
Negotiated: Active Hold Time: 180 sec Keepalive Time:60 sec
Peer optional capabilities:
Peer supports bgp multi-protocol extension
Peer supports bgp route refresh capability
Peer supports bgp 4-byte-as capability
Address family IPv4 Unicast: advertised and received
Received: Total 990 messages
Update messages 0
Open messages 1
KeepAlive messages 989
Notification messages 0
Refresh messages 0
Sent: Total 990 messages
Update messages 0
Open messages 1
KeepAlive messages 989
Notification messages 0
Refresh messages 0
Authentication type configured: None
Last keepalive received: 2011/12/07 08:34:17
Minimum route advertisement interval is 15 seconds
Optional capabilities:
Route refresh capability has been enabled
4-byte-as capability has been enabled
Connect-interface has been configured
Peer Preferred Value: 0
Routing policy configured:
No routing policy is configured
可以看到在R2上默认的配置参数Active Hold Time为180s,Keepalive Time为60s。
当R1的参数修改之后,R2收到数据包的Active Hold Time为90s。协商的参数取值数值小的参数,所以R2与R1的协商的结果Active Hold Time为90s,keepalive Time为30s,而R3的参数仍然为默认参数。
R2和R3一样,所以协商的结果配置参数和协商参数一致,Active Hold Time为180s,Keepalive Time为60s。
步骤四.配置EBGP对等体
在R4上配置BGP,本地AS号为64513,与R1建立EBGP对等体关系。在建立对等体关系时,指定更新源为Loopback 0接口的地址,并指定ebgp-max-hop为2。添加到对端Loopback 0接口地址的32位的静态路由,使之能正常建立对等体关系。
[R1]ip route-static 10.0.4.4 32 10.0.14.4
[R4]ip route-static 10.0.1.1 32 10.0.14.1
[R1]bgp 64512
[R1-bgp]peer 10.0.4.4 as-number 64513
[R1-bgp]peer 10.0.4.4 ebgp-max-hop 2
[R1-bgp]peer 10.0.4.4 connect-interface LoopBack0
[R1-bgp]quit
[R4]router id 10.0.4.4
[R4]bgp 64513
[R4-bgp]peer 10.0.1.1 as-number 64512
[R4-bgp]peer 10.0.1.1 ebgp-max-hop 2
[R4-bgp]peer 10.0.1.1 connect-interface LoopBack0
[R4-bgp]quit
对等体关系建立完成后,使用display bgp peer检查对等体关系状态。
[R4]display bgp peer
BGP local router ID : 10.0.4.4
Local AS number : 64513
Total number of peers : 1 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
10.0.1.1 4 64512 4 5 0 00:01:18 Established 0
在R4上使用debugging ip packet verbose查看keepalive报文的TTL值。
<R4>terminal monitor
<R4>terminal debugging
<R4>debugging ip packet
<R4>
Oct 31 2016 17:22:44.900.2+00:00 R4 IP/7/debug_case:
Receiving, interface = Serial1/0/0, version = 4, headlen = 20, tos = 192,
pktlen = 40, pktid = 429, offset = 0, ttl = 2, protocol = 6,
checksum = 40287, s = 10.0.1.1, d = 10.0.4.4
prompt: IP Process By Board Begin!
45 c0 00 28 01 ad 00 00 02 06 9d 5f 0a 00 01 01
0a 00 04 04
Oct 31 2016 17:22:44.900.3+00:00 R4 IP/7/debug_case:
Receiving, interface = Serial1/0/0, version = 4, headlen = 20, tos = 192,
pktlen = 40, pktid = 429, offset = 0, ttl = 2, protocol = 6,
checksum = 40287, s = 10.0.1.1, d = 10.0.4.4
prompt: Before search fib per flow in IP Forward.
可以看到收到的报文中TTL都为2。
在R3和R5之间也建立EBGP对等体关系。直接使用物理接口地址建立连接。
[R3]bgp 64512
[R3-bgp]peer 10.0.35.5 as-number 64514
[R3-bgp]quit
[R5]router id 10.0.5.5
[R5]bgp 64514
[R5-bgp]peer 10.0.35.3 as-number 64512
[R5-bgp]quit
[R5]display bgp peer
BGP local router ID : 10.0.5.5
Local AS number : 64514
Total number of peers : 1 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
10.0.35.3 4 64512 2 3 0 00:00:46 Established 0
步骤五.使用Network命令发布路由信息
在R4上配置Loopback1,地址为10.1.4.4/24。使用network命令将该网段发布进BGP。
[R4]interface LoopBack 1
[R4-LoopBack1]ip address 10.1.4.4 24
[R4-LoopBack1]quit
[R4]bgp 64513
[R4-bgp]network 10.1.4.4 24
[R4-bgp]quit
在R1和R3上全局路由表分别查看该路由是否存在。
查看R3上BGP路由表,分析该路由的下一跳信息。
[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 18 Routes : 18
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial1/0/0
10.0.3.3/32 OSPF 10 3124 D 10.0.12.2 Serial1/0/0
10.0.4.4/32 Static 60 0 RD 10.0.14.4 Serial3/0/0
10.0.12.0/24 Direct 0 0 D 10.0.12.1 Serial1/0/0
10.0.12.1/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.12.2/32 Direct 0 0 D 10.0.12.2 Serial1/0/0
10.0.12.255/32 Direct 0 0 D 127.0.0.1 Serial1/0/0
10.0.14.0/24 Direct 0 0 D 10.0.14.1 Serial3/0/0
10.0.14.1/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.14.4/32 Direct 0 0 D 10.0.14.4 Serial3/0/0
10.0.14.255/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.23.0/24 OSPF 10 3124 D 10.0.12.2 Serial1/0/0
10.1.4.0/24 EBGP 255 0 RD 10.0.4.4 Serial3/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/3 Direct 0 0 D 127.0.0.1 InLoopBack0
可以看到在R1上已经学到10.1.4.0/24的EBGP路由。
在R3上查看是否有到达网络10.1.4.0/24的路由。
[R3]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 16 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.2.2/32 OSPF 0 1562 D 10.0.23.2 Serial2/0/0
10.0.3.3/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.12.0/24 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.23.0/24 Direct 0 0 D 10.0.23.3 Serial2/0/0
10.0.23.2/32 Direct 0 0 D 10.0.23.2 Serial2/0/0
10.0.23.3/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.23.255/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.35.0/24 Direct 0 0 D 10.0.35.3 Serial3/0/0
10.0.35.3/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.35.5/32 Direct 0 0 D 10.0.35.5 Serial3/0/0
10.0.35.255/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/3 Direct 0 0 D 127.0.0.1 InLoopBack0
在R3上并没有10.1.4.4的bgp路由。
查看R3的BGP表。
[R3]display bgp routing-table
BGP Local router ID is 10.0.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: 1
Network NextHop MED LocPrf PrefVal Path/Ogn
i 10.1.4.0/24 10.0.4.4 0 100 0 64513i
可以在R3的BGP路由表中看到,但是这条BGP路由没有*号标识,说明这条路由并没有被优选。因为这条路由的NextHop为10.0.4.4,而R3上并没有到达地址10.0.4.4的路由。根据BGP选路原则,当BGP路由的下一跳不可达时,忽略此路由。
在R1上配置next-hop-local,再次在R3上查看该路由表。
[R1]bgp 64512
[R1-bgp]peer 10.0.3.3 next-hop-local
[R1-bgp]peer 10.0.2.2 next-hop-local
[R1-bgp]quit
[R3]display bgp routing-table
BGP Local router ID is 10.0.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: 1
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 10.1.4.0/24 10.0.1.1 0 100 0 64513i
可以看到BGP路由10.1.4.0/24的下一跳为10.0.1.1,同时具有*号和>号,说明这条路由是正确并且最优的。
查看R3的路由表。
[R3]display ip routing-table
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 17
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.1/32 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.2.2/32 OSPF 10 1562 D 10.0.23.2 Serial2/0/0
10.0.3.3/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.0.12.0/24 OSPF 10 3124 D 10.0.23.2 Serial2/0/0
10.0.23.0/24 Direct 0 0 D 10.0.23.3 Serial2/0/0
10.0.23.2/32 Direct 0 0 D 10.0.23.2 Serial2/0/0
10.0.23.3/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.23.255/32 Direct 0 0 D 127.0.0.1 Serial2/0/0
10.0.35.0/24 Direct 0 0 D 10.0.35.3 Serial3/0/0
10.0.35.3/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.0.35.5/32 Direct 0 0 D 10.0.35.5 Serial3/0/0
10.0.35.255/32 Direct 0 0 D 127.0.0.1 Serial3/0/0
10.1.4.0/24 IBGP 255 0 RD 10.0.1.1 Serial2/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/3 Direct 0 0 D 127.0.0.1 InLoopBack0
路由表出现路由10.1.4.0/24。
在R5上创建Loopback1,地址为10.1.5.5/24,发布进BGP, 在R3上配置next-hop-local。
[R5]interface LoopBack 1
[R5-LoopBack1]ip address 10.1.5.5 24
[R5-LoopBack1]quit
[R5]bgp 64514
[R5-bgp]network 10.1.5.0 24
[R3]bgp 64512
[R3-bgp]peer 10.0.1.1 next-hop-local
[R3-bgp]peer 10.0.2.2 next-hop-local
在R4上查看是否学习到R5的Loopback 1连接网络的路由。分析display bgp routing-table的输出。
[R4]display bgp routing-table
BGP Local router ID is 10.0.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: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.4.0/24 0.0.0.0 0 0 i
*> 10.1.5.0/24 10.0.1.1 0 64512 64514i
在R5上使用带源地址ping测试到R4的Loopback1地址的连通性。
[R5]ping -c 1 -a 10.1.5.5 10.1.4.4
PING 10.1.4.4: 56 data bytes, press CTRL_C to break
Reply from 10.1.4.4: bytes=56 Sequence=1 ttl=252 time=125 ms
--- 10.1.4.4 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 125/125/125 ms
附加实验: 思考并验证
什么情况下用物理地址直接建立EBGP邻居关系比较恰当?
为何默认发给EBGP邻居报文的TTL值为1? 运行peer group_name ebgp-max-hop [ hop-count ]的默认值是多少?
最终设备配置
[R1]display current-configuration
[V200R007C00SPC600]
#
sysname R1
#
router id 10.0.1.1
#
interface Serial1/0/0
link-protocol ppp
ip address 10.0.12.1 255.255.255.0
#
interface Serial3/0/0
link-protocol ppp
ip address 10.0.14.1 255.255.255.0
#
interface LoopBack0
ip address 10.0.1.1 255.255.255.255
#
bgp 64512
timer keepalive 30 hold 90
peer 10.0.2.2 as-number 64512
peer 10.0.2.2 connect-interface LoopBack0
peer 10.0.3.3 as-number 64512
peer 10.0.3.3 connect-interface LoopBack0
peer 10.0.4.4 as-number 64513
peer 10.0.4.4 ebgp-max-hop 2
peer 10.0.4.4 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
peer 10.0.2.2 enable
peer 10.0.2.2 next-hop-local
peer 10.0.3.3 enable
peer 10.0.3.3 next-hop-local
peer 10.0.4.4 enable
#
ospf 1
area 0.0.0.0
network 10.0.12.0 0.0.0.255
network 10.0.1.1 0.0.0.0
#
ip route-static 10.0.4.4 255.255.255.255 10.0.14.4
return
[R2]display current-configuration
[V200R007C00SPC600]
#
sysname R2
#
router id 10.0.2.2
#
interface Serial1/0/0
link-protocol ppp
ip address 10.0.12.2 255.255.255.0
#
interface Serial2/0/0
link-protocol ppp
ip address 10.0.23.2 255.255.255.0
#
interface LoopBack0
ip address 10.0.2.2 255.255.255.255
#
bgp 64512
peer 10.0.1.1 as-number 64512
peer 10.0.1.1 connect-interface LoopBack0
peer 10.0.3.3 as-number 64512
peer 10.0.3.3 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
peer 10.0.1.1 enable
peer 10.0.3.3 enable
#
ospf 1
area 0.0.0.0
network 10.0.12.0 0.0.0.255
network 10.0.23.0 0.0.0.255
network 10.0.2.2 0.0.0.0
return
[R3]display current-configuration
[V200R007C00SPC600]
#
sysname R3
#
router id 10.0.3.3
#
interface Serial2/0/0
link-protocol ppp
ip address 10.0.23.3 255.255.255.0
#
interface Serial3/0/0
link-protocol ppp
ip address 10.0.35.3 255.255.255.0
#
interface LoopBack0
ip address 10.0.3.3 255.255.255.255
#
bgp 64512
peer 10.0.1.1 as-number 64512
peer 10.0.1.1 connect-interface LoopBack0
peer 10.0.2.2 as-number 64512
peer 10.0.2.2 connect-interface LoopBack0
peer 10.0.35.5 as-number 64514
#
ipv4-family unicast
undo synchronization
peer 10.0.1.1 enable
peer 10.0.1.1 next-hop-local
peer 10.0.2.2 enable
peer 10.0.2.2 next-hop-local
peer 10.0.35.5 enable
#
ospf 1
area 0.0.0.0
network 10.0.23.0 0.0.0.255
network 10.0.3.3 0.0.0.0
return
[R4]display current-configuration
[V200R007C00SPC600]
#
sysname R4
#
router id 10.0.4.4
#
interface Serial1/0/0
link-protocol ppp
ip address 10.0.14.4 255.255.255.0
#
interface LoopBack0
ip address 10.0.4.4 255.255.255.255
#
interface LoopBack1
ip address 10.1.4.4 255.255.255.0
#
bgp 64513
peer 10.0.1.1 as-number 64512
peer 10.0.1.1 ebgp-max-hop 2
peer 10.0.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 10.0.4.0 255.255.255.0
network 10.1.4.0 255.255.255.0
peer 10.0.1.1 enable
#
ip route-static 10.0.1.1 255.255.255.255 10.0.14.1
return
[R5]display current-configuration
[V200R007C00SPC600]
#
sysname R5
#
router id 10.0.5.5
#
interface Serial1/0/0
link-protocol ppp
ip address 10.0.35.5 255.255.255.0
#
interface LoopBack0
ip address 10.0.5.5 255.255.255.255
#
interface LoopBack1
ip address 10.1.5.5 255.255.255.0
#
bgp 64514
peer 10.0.35.3 as-number 64512
#
ipv4-family unicast
undo synchronization
network 10.1.5.0 255.255.255.0
peer 10.0.35.3 enable
return