目录
HICP之BGP的基本配置
例题
实验ip地址基本配置
R1IP地址
R2IP地址
R3IP地址
R4IP地址
R5IP地址
AS2中ospf区域基本配置
R2配置
R3配置
R4配置
测试:
AS1与AS2建立EBGP直连建邻
R1配置
R2配置
测试
R2,R3建立IBGP非直连建邻
R2基本配置
R3基本配置
测试:
R3、R4建立IBGP非直连建邻
R3基本配置
R4基本配置
测试
R4、R5建立EBGP非直连建邻
解决路由可达 --- 写静态路由
测试
BGP的基本配置
1.BGP建邻的基本配置
1.EBGP对等体关系直连建邻
2.IBGP对等体关系之间的非直连建邻 --- 环回建邻
存在问题: Active :表示建邻失败
原因:
解决办法:
3.EBGP对等体关系之间的非直连建邻
2.发布路由
1.network
2.重发布
HICP之BGP的基本配置
例题
解析:
R1为AS1,R2、R3、R4为AS2,内部为IGP协议中的ospf,R5为AS3
实验ip地址基本配置
R1IP地址
[R1]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 12.0.0.1/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 1.1.1.1/24 up up(s)
NULL0 unassigned up up(s)
R2IP地址
[R2]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 12.0.0.2/24 up up
GigabitEthernet0/0/1 23.0.0.1/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 2.2.2.2/24 up up(s)
NULL0 unassigned up up(s)
R3IP地址
[R3]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 23.0.0.2/24 up up
GigabitEthernet0/0/1 34.0.0.1/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 3.3.3.3/24 up up(s)
NULL0 unassigned up up(s)
R4IP地址
[R4]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 34.0.0.2/24 up up
GigabitEthernet0/0/1 45.0.0.1/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 4.4.4.4/24 up up(s)
NULL0 unassigned up up(s)
R5IP地址
[R5]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 45.0.0.2/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 5.5.5.5/24 up up(s)
NULL0 unassigned up up(s)
AS2中ospf区域基本配置
R2配置
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 23.0.0.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
R3配置
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 34.0.0.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 23.0.0.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
R4配置
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 34.0.0.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
测试:
R2
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status : <Active>
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
3.3.3.3/32 OSPF 10 1 D 23.0.0.2 GigabitEthernet
0/0/1
4.4.4.4/32 OSPF 10 2 D 23.0.0.2 GigabitEthernet
0/0/1
34.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
R3
[R3]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 2 Routes : 2
OSPF routing table status : <Active>
Destinations : 2 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 OSPF 10 1 D 23.0.0.1 GigabitEthernet
0/0/0
4.4.4.4/32 OSPF 10 1 D 34.0.0.2 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
R4
[R4]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status : <Active>
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 OSPF 10 2 D 34.0.0.1 GigabitEthernet
0/0/0
3.3.3.3/32 OSPF 10 1 D 34.0.0.1 GigabitEthernet
0/0/0
23.0.0.0/24 OSPF 10 2 D 34.0.0.1 GigabitEthernet
0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
AS1与AS2建立EBGP直连建邻
R1配置
[R1]bgp
[R1]bgp 1
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 12.0.0.2 as
[R1-bgp]peer 12.0.0.2 as-number 2
R2配置
[R2-bgp]route-select
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 12.0.0.1 as-number 1
测试
[R1-bgp]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 Direct 0 0 D 1.1.1.1 LoopBack0
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
1.1.1.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet
0/0/0
12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/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
R2,R3建立IBGP非直连建邻
R2基本配置
[R2-bgp]peer 3.3.3.3 as-number 2
R3基本配置
[R3]bg
[R3]bgp 2
[R3-bgp]ro
[R3-bgp]route-select
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 2.2.2.2 as-number 2
测试:
[R2]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
2.2.2.0/24 Direct 0 0 D 2.2.2.2 LoopBack0
2.2.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.3/32 OSPF 10 1 D 23.0.0.2 GigabitEthernet
0/0/1
4.4.4.4/32 OSPF 10 2 D 23.0.0.2 GigabitEthernet
0/0/1
12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet
0/0/0
12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
23.0.0.0/24 Direct 0 0 D 23.0.0.1 GigabitEthernet
0/0/1
23.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
23.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
34.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet
0/0/1
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
R2
[R2]display bgp peer
BGP local router ID : 2.2.2.2
Local AS number : 2
Total number of peers : 2 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
3.3.3.3 4 2 0 0 0 00:10:25 Active
0
12.0.0.1 4 1 32 32 0 00:30:25 Established
0
R3
[R3]display bgp peer
BGP local router ID : 3.3.3.3
Local AS number : 2
Total number of peers : 1 Peers in established state : 0
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
2.2.2.2 4 2 0 0 0 00:05:42 Active
0
Active :表示建邻失败
原因:
手工建立邻居关系时所指定的建邻的ip底子必须和收到数据包中的源ip地址相同才能正常建立邻居关系。否则邻居关系建立失败
解决办法:
[R2-bgp]peer 3.3.3.3 connect-interface LoopBack 0
R3、R4建立IBGP非直连建邻
R3基本配置
[R3-bgp]peer 4.4.4.4 as-number 2
[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
R4基本配置
[R4]bg
[R4]bgp 2
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 3.3.3.3 as-number 2
[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
测试
[R3-bgp]display bgp peer
BGP local router ID : 3.3.3.3
Local AS number : 2
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
2.2.2.2 4 2 15 15 0 00:13:59 Established
0
4.4.4.4 4 2 2 4 0 00:00:08 Established
0
R4、R5建立EBGP非直连建邻
解决路由可达 --- 写静态路由
R4
[R4]ip route-static 5.5.5.0 24 45.0.0.2
R5
[R5]ip route-static 4.4.4.0 24 45.0.0.1
测试
[R5]ping -a 5.5.5.5 4.4.4.4
PING 4.4.4.4: 56 data bytes, press CTRL_C to break
Reply from 4.4.4.4: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 4.4.4.4: bytes=56 Sequence=2 ttl=255 time=10 ms
Reply from 4.4.4.4: bytes=56 Sequence=3 ttl=255 time=10 ms
Reply from 4.4.4.4: bytes=56 Sequence=4 ttl=255 time=10 ms
Reply from 4.4.4.4: bytes=56 Sequence=5 ttl=255 time=40 ms
--- 4.4.4.4 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/28/70 ms
配置建邻
R4
[R4]bgp 2
[R4-bgp]peer 5.5.5.5 as-number 3
[R4-bgp]peer 5.5.5.5 connect-interface LoopBack 0
[R4-bgp]
R5
[R5]bgp 3
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 4.4.4.4 as-number 2
[R5-bgp]peer 4.4.4.4 connect-interface LoopBack 0
测试
[R4-bgp]display bgp peer
BGP local router ID : 4.4.4.4
Local AS number : 2
Total number of peers : 2 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
3.3.3.3 4 2 31 31 0 00:29:24 Established
0
5.5.5.5 4 3 1 0 0 00:00:22 Idle
0
失败原因:
因为EBGP对等体之间一般是直连建邻,所以数据包中TTL值设置为1
解决办法:
遇到EBGP对等体之间需要进行非直连建邻,需要手工修改TTL值。
[R4-bgp]peer 5.5.5.5 ebgp-max-hop 2
测试:
[R5-bgp]display bgp peer
BGP local router ID : 5.5.5.5
Local AS number : 3
Total number of peers : 1 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
4.4.4.4 4 2 3 3 0 00:01:11 Established
0
BGP的基本配置
1.BGP建邻的基本配置
1.EBGP对等体关系直连建邻
1.启动 bgp进程
[R1]bgp
[R1]bgp 1 --- 1 表示AS号
[R1-bgp]
注意:
后面的1不是进程号,而是配置路由区域所在AS的AS号
2.配置router-id
[R1-bgp]router-id 1.1.1.1
3.建立邻居关系
[R1-bgp]peer 12.0.0.2 as-number 2 --- 手工指定对等体关系
peer --- 建立对等体的路由的端口iP地址,as-number
查看bgp邻居表的命令 --- display bgp peer
[R1-bgp]display bgp peer
BGP local router ID : 1.1.1.1
Local AS number : 1
Total number of peers : 1 Peers in established state : 1
Peer V AS MsgRcvd MsgSent OutQ Up/Down State PrefRcv
12.0.0.2 4 2 5 6 0 00:03:12 Established 0
2.IBGP对等体关系之间的非直连建邻 --- 环回建邻
注意:
由于IBGP邻居处于同一个AS中,一般情况下,一个AS中存在大量的备份路径,若使用物理接口建立邻居关系,将浪费这些备份或者负载均衡资源,故建议使用环回接口来进行IBGP对等体关系的建立
[R2]bgp 2
[R2-bgp]peer 3.3.3.3 as-number 2
存在问题: Active :表示建邻失败
原因:
手工建立邻居关系时所指定的建邻的ip底子必须和收到数据包中的源ip地址相同才能正常建立邻居关系。否则邻居关系建立失败
解决办法:
[R2-bgp]peer 3.3.3.3 connect-interface LoopBack 0 --- 指定在给3.3.3.3发包时使用源IP地址为换回接口0的IP地址
connect-interface --- 修改发送接口
注意:
在使用换回接口建立对等体关系时,一定要修改发送接口
3.EBGP对等体关系之间的非直连建邻
注意:
在EBGP对等体关系之间,一般是不具备非直连建邻的路由基础,所以,必须先保证地址可达才行。
[R4]bgp 2
[R4-bgp]peer 5.5.5.5 as-number 3
[R4-bgp]peer 5.5.5.5 connect-interface LoopBack 0
[R4-bgp]
存在问题:建邻失败
原因:EBGP对等体之间一般是直连建邻,所以数据包中TTL值设置为1
解决办法:
[R4-bgp]peer 5.5.5.5 ebgp-max-hop 2
注意:
因为EBGP对等体之间一般是直连建邻,所以,数据包中的TTL值为1,想要非直连建邻,则需要将这个值改大
[R4-bgp]peer 5.5.5.5 ebgp-max-hop --- 后面不跟参数,则代表将TTL值修改为最大值255
2.发布路由
1.network
在BGP中只能发布路由条目信息
注意:
只要是路由表中存在的路由条目信息,BGP都可以通过Network来进行发送
[R1-bgp]network 1.1.1.0 24 --- 目标网段信息及掩码必须和路由表中的完全一致才行
[R1-bgp]display bgp routing-table --- 查找bgp路由表
[R1-bgp]display bgp routing-table
BGP Local router ID is 1.1.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: 1
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.0/24 0.0.0.0 0 0 i
Network --- 目标网段信息
NextHop --- BGP的一个路径属性 --- 谁发的路由信息,吓一跳就是谁,若果自己发的则下一跳为0.0.0.0
状态码
* --- 代表可用 --- 设备每收到一跳路由信息,都会检查其吓一跳的可达性。即根据下一跳在路由表中递归查询,只要可达,则改路由信息可用。
> --- 代表优选 --- 当收到到达相同网段存在多条路由信息时,我们BGP将在其中根据属性优选出一条加载到路由表中。这条优选路由将会赋予这个标记。
i --- 代表BGP路由信息是从自己IBGP对等体处学到的
注意:
只有一条路由条目是可用且优选的,他才能够被加到路由表中,也才能够被传递给其他的BGP对等体
[R2]display bgp routing-table
BGP Local router ID is 2.2.2.2
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
*> 1.1.1.0/24 12.0.0.1 0 0 1i
1.1.1.0/24 EBGP 255 ---- 通过EBGP对等体学到的BGP路由信息,标记为EBGP默认的优先级为255
[R3]display bgp routing-table
BGP Local router ID is 3.3.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 1.1.1.0/24 12.0.0.1 0 100 0 1i
[R3]
i 1.1.1.0/24 12.0.0.1 --- 因为在AS内部存在AS-BY-AS规则,所以,默认情况下传递的属性信息是一致的,因为这下一跳也属于路径属性之一,默认情况下也不会传递,则将可能导致路由可用性效验失败
[R2-bgp]peer 3.3.3.3 next-hop-local
[R2-bgp]peer 3.3.3.3 next-hop-local --- 在给3.3.3.3传递路由信息时将下一跳字段属性改为本地
[R3]display bgp routing-table
BGP Local router ID is 3.3.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 1.1.1.0/24 2.2.2.2 0 100 0 1i
[R3]
1.1.1.0/24 IBGP 255 ---- 通过IBGP对等体学到的BGP路由信息,标记为EBGP默认的优先级为255
路由表中的NextHop直接使用的是BGP属性中的下一跳,因为之前进行过可用性效验,所以,可以保证能够递归查找找到这个下一跳
2.重发布
[R2-bgp]import-route ospf 1 --- 将ospf的路由信息导入到BGP当中。
[R2-bgp]display bgp routing-table
BGP Local router ID is 2.2.2.2
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
*> 1.1.1.0/24 12.0.0.1 0 0 1i
*> 2.2.2.0/24 0.0.0.0 0 0 ?
*> 3.3.3.3/32 0.0.0.0 1 0 ?
*> 4.4.4.4/32 0.0.0.0 2 0 ?
*> 23.0.0.0/24 0.0.0.0 0 0 ?
*> 34.0.0.0/24 0.0.0.0 2 0 ?
[R2-bgp]
OGN --- 起源码 --- I ,e,?--- 用来标识路由条目的起源
I --- 代表该路由信息起源于IGP协议(不局限于IGP协议,包括静态,直连),代表该路由条目起源于AS内部 --- 通过network发不出来的路由信息其起源码为I
E --- 代表该路由信息起源于EGP协议 --- EGP指的是BGP之前使用的外部网关协议
?--- 通过除了以上两种学习到的路由 --- 涌发布的起源码都是 ?