一,拓扑
二,要求
用BGP连接AS 100,200,300
三,配置
r1:配置IP:
[r1]interface GigabitEthernet 0/0/0
[r1-GigabitEthernet0/0/0]ip address 12.0.0.1 24
[r1]interface LoopBack 0
[r1-LoopBack0]ip address 1.1.1.1 32
[r1]interface LoopBack 1
[r1-LoopBack1]ip address 21.0.0.1 24BGP配置:
[r1]bgp 100--启动BGP协议
[r1-bgp]router-id 1.1.1.1 ---配置设备的RID数值
[r1-bgp]peer 12.0.0.2 as-number 200---配置BGP对等体信息,包含了对等体的IP地址以及对等体所在的AS号EBGP[r1-bgp]network 1.1.1.1 32---宣告环回
[r1-bgp]network 21.0.0.0 24
r2配置IP:
[r2]interface GigabitEthernet 0/0/0
[r2-GigabitEthernet0/0/0]ip address 12.0.0.2 24
[r2]interface GigabitEthernet 0/0/1
[r2-GigabitEthernet0/0/1]ip address 23.0.0.2 24
[r2]interface LoopBack 0
[r2-LoopBack0]ip address 2.2.2.2 32
[r2]interface LoopBack 1
[r2-LoopBack1]ip address 14.0.0.1 24OSPF配置:
[r2]ospf 1
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 23.0.0.2 0.0.0.0BGP配置:
[r2]bgp 200
[r2-bgp]router-id 2.2.2.2 ---配置设备的RID数值
[r2-bgp]peer 12.0.0.1 as-number 100--配置BGP对等体信息,包含了对等体的IP地址以及对等体所在的AS号EBGP
[r2-bgp]peer 3.3.3.3 as-number 200 ---配置BGP对等体信息 IBGP
[r2-bgp]peer 3.3.3.3 connect-interface LoopBack 0--修改数据包中的源IP,对等体双方均需要进行修改
[r2-bgp]peer 3.3.3.3 next-hop-local---R2在给3.3.3.3传递路由信息时,将下一跳属性修改为本地
[r2-bgp]peer 4.4.4.4 as-number 200---因为R2给R3传递R1的环回信息,则R3不能给其他IBGP传递该信息,故R2与R4建立IBGP,由R2直接传给R4
[r2-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[r2-bgp]peer 4.4.4.4 next-hop-local[r2-bgp]import-route ospf 1---将OSPF信息引入BGP
[r2-bgp]network 14.0.0.0 24
[r2-bgp]network 12.0.0.0 24---宣告R1,R2之间的路由
r3配置IP:
[r3]interface GigabitEthernet 0/0/0
[r3-GigabitEthernet0/0/0]ip address 23.0.0.3 24
[r3]interface GigabitEthernet 0/0/1
[r3-GigabitEthernet0/0/1]ip address 34.0.0.3 24
[r3]interface LoopBack 0
[r3-LoopBack0]ip address 3.3.3.3 32OSPF配置:
[r3]ospf 1
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 23.0.0.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 34.0.0.3 0.0.0.0BGP配置:
[r3]bgp 200
[r3-bgp]peer 2.2.2.2 as-number 200
[r3-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r3-bgp]peer 4.4.4.4 as-number 200
[r3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[r3-bgp]network 33.0.0.0 24----宣告新增环回接口1
r4配置IP:
[r4]interface GigabitEthernet 0/0/0
[r4-GigabitEthernet0/0/0]ip address 34.0.0.4 24
[r4]interface GigabitEthernet 0/0/1
[r4-GigabitEthernet0/0/1]ip address 45.0.0.4 24
[r4]interface LoopBack 0
[r4-LoopBack0]ip address 4.4.4.4 32OSPF配置:
[r4]ospf 1
[r4-ospf-1]area 0
[r4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[r4-ospf-1-area-0.0.0.0]network 34.0.0.4 0.0.0.0BGP配置:
[r4]bgp 200
[r4-bgp]peer 2.2.2.2 as-number 200
[r4-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r4-bgp]peer 2.2.2.2 next-hop-local
[r4-bgp]peer 3.3.3.3 as-number 200
[r4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[r4-bgp]peer 3.3.3.3 next-hop-local[r4]bgp 200
[r4-bgp]peer 5.5.5.5 as-number 300
[r4-bgp]peer 5.5.5.5 connect-interface LoopBack 0
[r4-bgp]peer 5.5.5.5 ebgp-max-hop 2---修改TTL数值:两边均需要修改---此时TCP会话会正常建立,转而建立BGP会话。但是,对设备而言,此时的对端IP检查会发现是通过静态路由或IGP路由才可实现网络可达。那么也就意味着此时需要通过多跳才能到达目的地,而数据包中的TTL=1,发现错误,故两端均会发送notification报文进行告警,并断开BGP和TCP会话。需要通过修改 TTL值来防止此问题。
因为是直连路由中,所以TTL值大于1即可
[r4-bgp]network 44.0.0.0 24
[r4-bgp]network 45.0.0.0 24
[r4-bgp]network 5.5.5.5 32
r5配置IP:
[r5]interface GigabitEthernet 0/0/0
[r5-GigabitEthernet0/0/0]ip address 45.0.0.5 24
[r5]interface LoopBack 0
[r5-LoopBack0]ip address 5.5.5.5 32
[r5]interface LoopBack 1
[r5-LoopBack1]ip address 10.0.0.1 24
[r5]interface LoopBack 2
[r5-LoopBack2]ip address 11.0.0.1 24BGP配置:
[r5]bgp 300
[r5-bgp]peer 4.4.4.4 as-number 200
[r5-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[r5-bgp]peer 4.4.4.4 ebgp-max-hop 2[r5-bgp]network 10.0.0.0 24
四,测试
R1的BGP路由表
测试: