BGP与ospf

BGP是一种外部网关协议,是一种动态路由协议,实际上它不产生路由,不发现路由,不计算路由其主要功能是完成最佳路由的选择并在BGP邻居之间进行最佳路由的传递,BGP选择了TCP作为其传输协议。

BGP支持无类域间路由CIDR,提供了丰富的路由属性,能够非常容易的实现路由策略,支持VPN,IPV6等特性。

BGP的邻居关系分为两种,EBGP(两台路由器属于不同的AS)IBGP(两台路由器属于同一AS)

BGP的local preference属性可以用来选择流量离开AS时的最佳路由,也就是控制流量从哪个出口离开AS,当BGP路与其通过不同的IBGP路由器对等体接收到目标网络相同但下一跳不同的多条路由时,将优先选择local preference值较高的路由。

BGP与ospf_第1张图片

上述拓扑图需要实现的功能如下:1.r4访问A时将r2作为出口,

2.访问服务器B时将r3作为出口

3.AS200内使用ospf通信

实验步骤如下:

1.各个设备的ip基础配置

2.ospf与bgp协议的基础配置

3.观察bgp路与信息的local preference属性

4.修改local preference默认值

5.使用route-policy 修改local preference值

6.测试

#R1:
system-view
[Huawei]un in en                   #关闭提示信息
[Huawei]sysname r1
[r1]interface g0/0/1
[r1-GigabitEthernet0/0/1]ip add 10.0.13.1 24
[r1-GigabitEthernet0/0/1]quit
[r1]interface g0/0/0
[r1-GigabitEthernet0/0/0]ip add 10.0.12.1 24
[r1-GigabitEthernet0/0/0]quit
[r1]interface g0/0/0
[r1-GigabitEthernet0/0/0]quit
[r1]interface LoopBack 0
[r1-LoopBack0]ip add 10.0.1.1 32
[r1-LoopBack0]quit
[r1]interface loopback 1
[r1-LoopBack1]ip add 10.0.100.2 32
[r1-LoopBack1]
ping 10.0.12.2
     0.00% packet loss
   
#配置bgp
[r1]bgp 100
[r1-bgp]router-id 10.0.1.1
[r1-bgp]peer 10.0.12.2 as-number 200
[r1-bgp]peer 10.0.13.3 as-number 200
[r1-bgp]network 10.0.1.1 32          #通告
[r1-bgp]network 10.0.100.2 32
[r1]display bgp peer
[r1]display bgp routing-table

R2:
system-view
[Huawei]sysname r2
[r2]un in en
[r2]interface g0/0/0
[r2-GigabitEthernet0/0/0]ip add 10.0.12.2 24
[r2-GigabitEthernet0/0/0]quit
[r2]interface g0/0/1
[r2-GigabitEthernet0/0/1]ip add 10.0.24.2 24
[r2-GigabitEthernet0/0/1]interface loopback0
[r2-LoopBack0]ip add 10.0.2.2 32
[r2]ospf 1 router-id 10.0.2.2
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 10.0.24.2 0.0.0.255
[r2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[r2]bgp 200
[r2-bgp]router-id 10.0.2.2
[r2-bgp]peer 10.0.12.1 as-number 100
[r2-bgp]peer 10.0.3.3 as-number 200
[r2-bgp]peer 10.0.3.3 connect-interface LoopBack 0 #ip绑定接口
[r2-bgp]peer 10.0.3.3 next-hop-local
[r2-bgp]peer 10.0.4.4 as-number 200
[r2-bgp]peer 10.0.4.4 connect-interface loopback 0	
[r2-bgp]peer 10.0.4.4 next-hop-local 
[r2]display bgp routing-table          
system-view
[r2]ip ip-prefix 1 permit 10.0.1.1 32      #创建ip前缀列表规则
[r2]route-policy 1 permit node 10          #创建路由策略10
[r2-route-policy]if-match ip-prefix 1      #创建if-match规则
[r2-route-policy]apply local-preference 500   #创建apply
[r2-route-policy]quit
[r2]route-policy 1 permit node 20
Info: New Sequence of this List.
[r2-route-policy]quit
[r2]bgp 200
[r2-bgp]peer 10.0.12.1 route-policy 1 import  #引入路由策略
[r2-bgp]quit
[r2]display bgp routing-table

R3:
system-view 
[Huawei]un in en
[Huawei]sysname r3
[r3]interface g0/0/1
[r3-GigabitEthernet0/0/1]ip add 10.0.13.3 24
[r3-GigabitEthernet0/0/1]interface g0/0/0
[r3-GigabitEthernet0/0/0]ip add 10.0.34.3 24
[r3-GigabitEthernet0/0/0]quit
[r3]interface loopback0
[r3-LoopBack0]ip add 10.0.3.3 32.
[r3]ospf 1 router-id 10.0.2.2
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0]network 10.0.34.0 0.0.0.255
[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
reset ospf 1 process
[r3]bgp 200
[r3-bgp]router-id 10.0.3.3
[r3-bgp]peer 10.0.13.1 as-number 100
[r3-bgp]peer 10.0.2.2 as-number 200
[r3-bgp]peer 10.0.2.2 connect-interface loopback 0	
[r3-bgp]peer 10.0.2.2 next-hop-local 
[r3-bgp]peer 10.0.4.4 as-number 200
[r3-bgp]peer 10.0.4.4 connect-interface loopback 0
[r3-bgp]peer 10.0.4.4 next-hop-local 
[r3]display default-parameter bgp     #查看bgp属性
 BGP version               : 4
 EBGP preference           : 255
 IBGP preference           : 255
 Local preference          : 255
 BGP connect-retry         : 32s
 BGP holdtime              : 180s
 BGP keepAlive             : 60s
 EBGP route-update-interval: 30s
 IBGP route-update-interval: 15s
 Default local-preference  : 100
 Default MED               : 0
 IPv4-family unicast       : enable
 EBGP-interface-sensitive  : enable
 Reflect between-clients   : enable
 Check-first-as            : enable
 Synchronization           : disable
 Nexthop-resolved rules    :
     IPv4-family           : unicast(ip)
                             label-route(ip)
                             multicast(ip)
                             -instance(tunnel)
                             v4(ip)
     IPv6-family           : unicast(ip)
                             -instance(tunnel)
[r3]bgp 200
 r3-bgp]default local-preference 200          #修改优先级

R4:
system-view
[Huawei]un in en
[Huawei]sysname r4
[r4]interface g0/0/01
[r4-GigabitEthernet0/0/1]ip add 10.0.24.4 24
[r4-GigabitEthernet0/0/1]quit
[r4]interface g0/0/0
[r4-GigabitEthernet0/0/0]ip add 10.0.34.4 24
[r4-GigabitEthernet0/0/0]quit
[r4]interface loopback0
[r4-LoopBack0]ip add 10.0.4.4 32
[r4-LoopBack0]quit
[r4]interface loopback1
[r4-LoopBack1]ip add 10.0.100.4 32
[r4-LoopBack1]
[r4]ospf 1 router-id 10.0.4.4
[r4-ospf-1]area 0
[r4-ospf-1-area-0.0.0.0]network 10.0.24.0 0.0.0.255
[r4-ospf-1-area-0.0.0.0]network 10.0.34.0 0.0.0.255
[r4-ospf-1-area-0.0.0.0]network 10.0.4.4 0.0.0.0
[r4-ospf-1-area-0.0.0.0]quit
[r4-ospf-1]quit
[r4]display ospf peer brief

	 OSPF Process 1 with Router ID 10.0.4.4
		  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/1             10.0.2.2         Full        
 0.0.0.0          GigabitEthernet0/0/0             10.0.13.3        Full        
 ----------------------------------------------------------------------------
[r4]display ospf peer brief

	 OSPF Process 1 with Router ID 10.0.4.4
		  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/1             10.0.2.2         Full        
 0.0.0.0          GigabitEthernet0/0/0             10.0.3.3         Full        
 ----------------------------------------------------------------------------
[r4]display ospf peer 

	 OSPF Process 1 with Router ID 10.0.4.4
		 Neighbors 

 Area 0.0.0.0 interface 10.0.24.4(GigabitEthernet0/0/1)'s neighbors
 Router ID: 10.0.2.2         Address: 10.0.24.2       
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: 10.0.24.2  BDR: 10.0.24.4  MTU: 0    
   Dead timer due in 38  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:04:24     
   Authentication Sequence: [ 0 ] 

		 Neighbors 

 Area 0.0.0.0 interface 10.0.34.4(GigabitEthernet0/0/0)'s neighbors
 Router ID: 10.0.3.3         Address: 10.0.34.3       
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: 10.0.34.4  BDR: 10.0.34.3  MTU: 0    
   Dead timer due in 37  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:00:29     
   Authentication Sequence: [ 0 ] 

[r4]
[r4]bgp 200
[r4-bgp]router-id 10.0.4.4
[r4-bgp]peer 10.0.2.2 as-number 200
[r4-bgp]peer 10.0.2.2 connect-interface loopback 0
[r4-bgp]peer 10.0.3.3 as-number 200
[r4-bgp]peer 10.0.3.3 connect-interface loopback 0
[r4-bgp]network 10.0.100.4 32
[r4-bgp]quit
[r4]display bgp routing-table
[r4]display bgp routing-table

tracert -a 10.0.100.4 10.0.1.1
 traceroute to  10.0.1.1(10.0.1.1), max hops: 30 ,packet length: 40,press CTRL_C
 to break 
 1 10.0.34.3 20 ms  20 ms  20 ms 
 2 10.0.13.1 20 ms  10 ms  30 ms 
[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: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
 *>i  10.0.1.1/32        10.0.2.2        0          500        0      100i
 *>i  10.0.100.2/32      10.0.3.3        0          200        0      100i
 *>   10.0.100.4/32      0.0.0.0         0                     0      i
ping  -a 10.0.100.4 10.0.1.1
  PING 10.0.1.1: 56  data bytes, press CTRL_C to break
    Reply from 10.0.1.1: bytes=56 Sequence=1 ttl=254 time=30 ms
    Reply from 10.0.1.1: bytes=56 Sequence=2 ttl=254 time=40 ms
    Reply from 10.0.1.1: bytes=56 Sequence=3 ttl=254 time=30 ms
    Reply from 10.0.1.1: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 10.0.1.1: bytes=56 Sequence=5 ttl=254 time=30 ms

  --- 10.0.1.1 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 30/32/40 ms



 

你可能感兴趣的:(network,bgp,ospf,网络)