组网需求
所有路由器都配置 BGP,R1 属于 AS 65008,R2、R3 属于 AS 65009。
R1 与 R2、R3 之间运行 EBGP,R2 与 R3 之间运行 IBGP。
R2、R3 发布 10.1.23.0/24 网段
配置思路
R1 与 R2、R3 之间配置 EBGP 连接,R2、R3 之间配置 IBGP 连接。
方案一:通过路由策略调大 R2 发给 R1 的 MED 值,使得 R1 选择 R3 作为出口。
方案二:通过路由策略调大 R1 接收 R2 的 MED 值,使得 R1 选择 R3 作为出口。
配置步骤
1、配置接口 IP 地址
2、配置 AS 65009 IGP
3、配置 BGP 连接
BGP local router ID : 1.1.1.1
Local AS number : 65008
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.12.2 (2.2.2.2)
Route Duration: 00h02m57s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.1.12.2
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 2 peers:
10.1.13.3
10.1.12.2
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.13.3 (3.3.3.3)
Route Duration: 00h02m57s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.1.13.3
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, pre 255, not preferred for router ID
Not advertised to any peer yet
4、配置 MED 属性
方案一:
==========R1==========
#
route-policy set_med_in permit node 10
apply cost 100
#
bgp 65008
#
ipv4-family unicast
peer 10.1.12.2 route-policy set_med_in import
#
BGP local router ID : 1.1.1.1
Local AS number : 65008
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.13.3 (3.3.3.3)
Route Duration: 01h20m40s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.1.13.3
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 2 peers:
10.1.13.3
10.1.12.2
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.12.2 (2.2.2.2)
Route Duration: 01h09m55s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.1.12.2
Qos information : 0x0
AS-path 65009, origin igp, MED 100, pref-val 0, valid, external, pre 255, not preferred for MED
Not advertised to any peer yet
方案二:
==========R2==========
#
route-policy set_med_out permit node 10
apply cost 200
#
bgp 65009
#
ipv4-family unicast
peer 10.1.12.1 route-policy set_med_out export
#
BGP local router ID : 1.1.1.1
Local AS number : 65008
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.13.3 (3.3.3.3)
Route Duration: 00h00m13s
Direct Out-interface: GigabitEthernet0/0/1
Original nexthop: 10.1.13.3
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 2 peers:
10.1.12.2
10.1.13.3
BGP routing table entry information of 10.1.23.0/24:
From: 10.1.12.2 (2.2.2.2)
Route Duration: 00h00m14s
Direct Out-interface: GigabitEthernet0/0/0
Original nexthop: 10.1.12.2
Qos information : 0x0
AS-path 65009, origin igp, MED 200, pref-val 0, valid, external, pre 255, not preferred for MED
Not advertised to any peer yet
配置文件
==========R1==========
#
sysname R1
#
interface GigabitEthernet0/0/0
ip address 10.1.12.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.1.13.1 255.255.255.0
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
bgp 65008
router-id 1.1.1.1
peer 10.1.12.2 as-number 65009
peer 10.1.13.3 as-number 65009
#
ipv4-family unicast
undo synchronization
peer 10.1.12.2 enable
peer 10.1.13.3 enable
#
route-policy set_med_in permit node 10
apply cost 100
#
==========R2==========
#
sysname R2
#
interface GigabitEthernet0/0/0
ip address 10.1.12.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.1.23.2 255.255.255.0
#
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
bgp 65009
router-id 2.2.2.2
peer 3.3.3.3 as-number 65009
peer 3.3.3.3 connect-interface LoopBack0
peer 10.1.12.1 as-number 65008
#
ipv4-family unicast
undo synchronization
network 10.1.23.0 255.255.255.0
peer 3.3.3.3 enable
peer 10.1.12.1 enable
peer 10.1.12.1 route-policy set_med_out export
#
ospf 110 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 10.1.23.0 0.0.0.255
#
route-policy set_med_out permit node 10
apply cost 200
#
==========R3==========
#
sysname R3
#
interface GigabitEthernet0/0/0
ip address 10.1.13.3 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.1.23.3 255.255.255.0
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.255
#
bgp 65009
router-id 3.3.3.3
peer 2.2.2.2 as-number 65009
peer 2.2.2.2 connect-interface LoopBack0
peer 10.1.13.1 as-number 65008
#
ipv4-family unicast
undo synchronization
network 10.1.23.0 255.255.255.0
peer 2.2.2.2 enable
peer 10.1.13.1 enable
#
ospf 110 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 10.1.23.0 0.0.0.255
#