八、实验二
1、实验拓扑:
2.实验目的:如图所示,A和B,C和D建立的邻居关系,如果A给D发数据包,先发到B,再发给C,然后到D,所以我们验证,A先发给C是不是更好。
3、实验配置
(1)基本配置IP地址
(2)建立BGP关系
l R2的配置
R2(config)#router bgp 2
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 12.1.1.1 remote-as 1
l R1的配置
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 12.1.1.2 remote-as 2
(3)R1和R3建立IGP用ripv2,
l R1的配置:
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#network 1.0.0.0
R1(config-router)#network 134.1.0.0
l R3的配置:
R3(config)#router rip
R3(config-router)#version 2
R3(config-router)#no auto-summary
R3(config-router)#network 3.0.0.0
R3(config-router)#network 134.1.0.0
(4)R1、R3、R4建立IBGP关系
l R1的配置:
R1(config)#router bgp 1
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source loopback 0
R1(config-router)#neighbor 3.3.3.3 next-hop-self (为了能让路由变优)
l R3的配置:
R3(config)#router bgp 1
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source loopback 0
R3(config-router)#neighbor 134.1.1.4 remote-as 4
l R4的配置:
R4(config)#router bgp 4
R4(config-router)# bgp router-id 4.4.4.4
R4(config-router)#neighbor 134.1.1.3 remote-as 1
(5)在R2上通告路由:
R2(config)#router bgp 2
R2(config-router)#network 2.2.2.0 mask 255.255.255.0
4、实验结论:当R4收到R2宣告的路由,下一条指向是134.1.1.1, 应该是134.1.1.3,所有在MA网络中,ICMP是开启的,ICMP的作用是,如果我从这个接口收到的数据包,还从这个接口发出去,这时候R3就像源端R4发一个ICMP重定向的包,报文内容是你R4发包下一条不用指向我R3了,直接把网管指向R1的134.1.1.1
l Show ip interface e0 可以看到ICMP是开启的
l Debug ip bgpupdate 查看建立邻居关系
l Clear ip bgp * 清楚BGP邻居,硬清,这样重建TCP连接
l Clear ip bgp * soft 软清,不断开TCP连接。重新发一些update报文
l 通告debug看是R3判断出来的
5、BGP States(BGP 的状态)
(1)Idle:(空闲状态)刚配了一条路由,正在查找,这个阶段就是Idle
(2)Connect:本台路由器已经找到了那个邻居的路由,而且也完成了三次握手
(3)Open sent:发送Open报文建邻居,如果都匹配,进入下一个阶段
(4)Open confirm:确认两边收到的Open报文的匹配的,正常就进入下一阶段
(5)Established:建立完成(用show ip bgp summary可以查看学习到的路由)
6、不正常的情况会出现下列几种状态
(1)Idle:本地不能发现邻居的路由(例如没有运行IGP)
(2)Active:
l 邻居没有我本端的路由表
l Neighbor 对端的地址错误的时候
l 邻居没有配置neighbor本端的命令
l AS号配置错了
7、BGP Neighbor authentication(BGP 邻居的认证)
(1)配置命令
l R3(config-router)#neighbor 1.1.1.1 password 123456
8、show ip bgp rib-failure:查看bgp的路由信息库(routing information base)
(1)如果查看到路由条目前打的是r,说明这条路由即从IGP学到,又从BGP学到,但IGP的AD比BGP的小,最终导致IGP的路由进入路由表,而BGP路由没有进入,她就会在BGP表中标识一个r。
(2)标识r的路由:
l 不放进路由表,
l 会给其他BGP邻居传,是优的路由
9、查看收发给邻居的路由
(1)show ip bgp neighbors 12.1.1.1 advertised-router:查看我想邻居12.1.1.1发送了那些路由
(2)show ip bgp neighbors 12.1.1.2 received-routes (默认是看不到的,必须先配置如下命令)
l R1(config-router)#neighbor 12.1.1.2 soft-reconfiguration inbound(这个命令作用就是看我通过自己一些内存保留这个12.1.1.2邻居给我发了那些路由)
10、auto-summary和no auto-summary的区别和作用
(1)no auto-summary:在BGP里的这条命令是用作重发布的时候,当任何一种协议重发布进入BGP中的时候,不会发生自动汇总。而且携带下一条和metric值
(2)Auto-summary:一种协议重发布到BGP中,执行的操作是不携带原有的下一条和metric值,而且会发生自动汇总
九、CIDR and Aggregate Addresses
(1)手工写一条静态路由NULL0,network汇总路由
l 例如:在上面拓扑的R2上有4条明细路由分别为:200.1.16.0/24、200.1.17.0/24、200.1.18.0/24、200.1.19.0/24、
l 配置如下:
R2(config)#ip route 200.1.16.0 255.255.252.0 null0
R2(config)#router bgp 2
R2(config-router)#network 200.1.16.0 mask 255.255.252.0
(2)聚合地址
l 宣告明细路由
R2(config-router)#network 200.1.16.0
R2(config-router)#network 200.1.17.0
R2(config-router)#network 200.1.18.0
R2(config-router)#network 200.1.19.0
l Aggregate-address
R2(config-router)#aggregate-address 200.1.16.0 255.255.252.0 summary-only
(summary-only的意思是仅仅传聚合路由,这样做BGP路由表里会出现s开头的路由,代表被抑制掉的路由)
(3) 如上,如果想抑制掉16和17,想学习聚合的和18、19的。配置如下:
R2(config-router)#aggregate-address 200.1.16.0 255.255.252.0 suppress-map SUP
(SUP 是route-map的名字)
R2(config)#ip prefix-list 1 permit 200.1.16.0/23 ge 24 le 24
R2(config)#route-map SUP
R2(config-route-map)#match ip address prefix-list 1
(4) as-set:当明细路由和聚合路由不在一个路由器上的时候,还原明细路由的属性,把明细路由的属性添加到聚合路由上。让聚合路由也携带这个属性。
l 例如:在R2上宣告明细路由,在R1的配置如下:
R1(config-router)#aggregate-address 200.1.16.0 255.255.252.0 summary-only as-set
十、BGP Path Attributes(BGP 路径属性)
1、识别
2、遵守和自行决定
(1)AS path *:防环
(2)Next-hop *:为了路由能达到最优
(3)Origin *:(起源属性)
l I:通过network通告进BGP都是打i
l ?:重发布过来的路由
l E:从EGP重发布到BGP中
修改属性会从路由看到E,在R1配置如下:
Ip prefix-list 2 permit 2.2.2.2/24
Route-map TEST permit 10
Match ip address prefix-list 2
Set origin egp 2 设置起源属性值
Router bgp 1
Neighbor 12.1.1.2 route-map TEST in
3、传播范围
4、添加其他类型
十一、选路原则
1、 前提是我的同步都关掉,我的下一条是否可达到情况下去选路,保证路由都达到优化
(1) 比最大的weight值
(2) 比本地优先级
(3) 优先于起源于本地的路由
(4) 经过的AS path越短越好
(5) 起源值越小越好(IGP<EGP<incomplete)
(6) Metric值越小越好(MED=metric)
(7) EBGP是由于IBGP的
(8) 优选于最近的IGP邻居(就是metric最小)
(9) 如果前面都相等,我会比较最小BGP邻居的router-id
2、 实验
(1) 实验拓扑图
(2) 实验目的:验证上面属性对选路的影响
(3) Weight值
l 基本配置以完成,R1、R3和R4运行IGP协议ospf,
l 在R2上通告路由
R2(config)#network 2.2.2.0 mask 255.255.255.0
R2(config)#network 9.9.9.0 mask 255.255.255.0
l 默认2.2.2.0和9.9.9.0网段都从R4走,如果想让这两个网段都从R1走,修改weight值,如果在我本台路由器上通告的路由,默认weight值是32768,在R3上修改weight值,配置如下:
R3(config)#router bgp1
R3(config-router)#neighbor 1.1.1.1 weight 1(R3的in方向,意思是所有1.1.1.1发过来的路由我把weight值都调成1,如果没有变,用clear ip bgp * soft清一下)
l 到R3访问2网段从R1走,访问9网段从R4走,配置如下:
R3(config)#ip prefix-list 2 permit 2.2.2.0/24(抓2网段的路由)
R3(config)#router-map W
R3(config-router-map)#match ip address prefix-list 2 (匹配列表2)
R3(config-router-map)#set weight 3 (设置weight值为3)
R3(config)#router-map W permit 20 (写一句空的是为了其他路由能通过)
R3(config)#router bgp1
R3(config-router)#neighbor 1.1.1.1 router-map W in(在R3的in方向调用W)
(4) 本地优先级(local preference Attribute)
l 传播范围:只能在一个AS内部
l 默认值是100
l 越大越优
l 让R3访问这两个网段从R1走,在R1配置如下:
R1(config)#router bgp1
R1(config-router)#bgp default local-preference 111
l bgp default local-preference 111 这条命令对下面的是否起效
1、 network 对自己的network的路由是否起效
2、 对EBGP传过来的路由是否起效
3、 对IBGP路由传过来的路由是否起效
4、 对聚合的路由是否起效
l 让2网段走R1,配置如下:
R1(config)#access-list 2 permit 2.2.2.0(抓2网段的路由)
R1(config)#router-map L
R1(config-router-map)#match ip address 2 (匹配列表2)
R1(config-router-map)#set local-preference 123
R1(config)#router-map L permit 20
R1(config)#router bgp1
R1(config-router)#neighbor 3.3.3.3 router-map L out
(5) 比short 的AS path
l R3访问2网段走R1,在R2配置如下:
R2(config)#ip prefix-list 2 permit 2.2.2.0/24(抓2网段的路由)
R2(config)#router-map AS
R2(config-router-map)#match ip address prefix-list 2 (匹配列表2)
R2(config-router-map)#set as-path prepend 6 7 8 (设置as的长短)
R2(config)#router-map AS permit 20
R2(config)#router bgp 2
R2(config-router)#neighbor 24.1.1.4 router-map AS out(在R2的out方向)
l R3访问2网段走R1,在R4配置如下
R4(config)#ip prefix-list 2 permit 2.2.2.0/24(抓2网段的路由)
R4(config)#router-map AS
R4(config-router-map)#match ip address prefix-list 2 (匹配列表2)
R4(config-router-map)#set as-path prepend 7 8 9 (设置as的长短)
R4(config)#router-map AS permit 20
R4(config)#router bgp 1
R4(config-router)#neighbor 24.1.1.2 router-map AS in
(6) lower origin code(IGP<EGP<Incomplete)
l IGP:network出来的
l 把EGP重分布到BGP中
l Incomplete(?):把IGP或者静态路由重分布到BGP中
(7) lower MED(MED相当于IGP的metric值)
l 传播范围
l 默认值是0
l 越小越好
l 实验:在R3上建立一个环回口并通告出来,配置如下:
R3(config)#interface loopback 8
R3(config-if)#ip address 8.8.8.8 255.255.255.0
R3(config)#router bgp 1
R3(config-router)#network 8.8.8.0 255.255.255.0
l 默认R2访问R3的8网段上从R1走,如果想从R4走,配置如下:
R1(config)#router-map MED
R1(config-router-map)#set metric 8
R1(config)#router bgp1
R1(config-router)#neighbor 12.1.1.2 route-map MED out
用扩展ping可以检验配置的效果,最常用的是Local perference(本地优先级)MED