Example for Configuring MED Attributes to Control BGP Route Selection
Networking Requirements
As shown in Figure 9-31, BGP is configured on all routers; Router A resides in AS 65008; Router B and Router C reside in AS 65009. EBGP connections are established between Router A and Router B, and between Router A and Router C. An IBGP connection is established between Router B and Router C. After a period, traffic from AS 65008 to AS 65009 needs to first pass through RouterC.
Configuration Roadmap
The configuration roadmap is as follows:
- Establish EBGP connections between Router A and Router B and between Router A and Router C, and establish an IBGP connection between Router B and Router C.
- Apply a routing policy to increase the MED value of the route sent by Router B to Router A so that Router A will send traffic to AS 65009 through Router C.
Procedure
- Configure an IP address for each interface.
# Configure IP addresses for all interfaces of RouterA.
<Huawei> system-view [Huawei] sysname RouterA [RouterA] interface gigabitethernet 1/0/0 [RouterA-GigabitEthernet1/0/0] ip address 200.1.1.2 255.255.255.0 [RouterA-GigabitEthernet1/0/0] quit [RouterA] interface gigabitethernet 2/0/0 [RouterA-GigabitEthernet2/0/0] ip address 200.1.2.2 255.255.255.0 [RouterA-GigabitEthernet2/0/0] quit
The configurations of RouterB and RouterC are similar to the configuration of RouterA, and are not mentioned here.
- Establish BGP connections.
# Configure Router A.
[RouterA] bgp 65008
[RouterA-bgp] router-id 1.1.1.1
[RouterA-bgp] peer 200.1.1.1 as-number 65009
[RouterA-bgp] peer 200.1.2.1 as-number 65009
[RouterA-bgp] quit
# Configure Router B.
[RouterB] bgp 65009
[RouterB-bgp] router-id 2.2.2.2
[RouterB-bgp] peer 200.1.1.2 as-number 65008
[RouterB-bgp] peer 9.1.1.2 as-number 65009
[RouterB-bgp] ipv4-family unicast
[RouterB-bgp-af-ipv4] network 9.1.1.0 255.255.255.0
[RouterB-bgp-af-ipv4] quit
[RouterB-bgp] quit
# Configure Router C.
[RouterC] bgp 65009
[RouterC-bgp] router-id 3.3.3.3
[RouterC-bgp] peer 200.1.2.2 as-number 65008
[RouterC-bgp] peer 9.1.1.1 as-number 65009
[RouterC-bgp] ipv4-family unicast
[RouterC-bgp-af-ipv4] network 9.1.1.0 255.255.255.0
[RouterC-bgp-af-ipv4] quit
[RouterC-bgp] quit
# View the routing table of Router A.
[RouterA] display bgp routing-table 9.1.1.0 24 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 9.1.1.0/24: From: 200.1.1.1 (2.2.2.2) Route Duration: 00h00m56s Direct Out-interface: GigabitEthernet1/0/0 Original nexthop: 200.1.1.1 Qos information : 0x0 AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, pre 255 Advertised to such 2 peers: 200.1.1.1 200.1.2.1 BGP routing table entry information of 9.1.1.0/24: From: 200.1.2.1 (3.3.3.3) Route Duration: 00h00m06s Direct Out-interface: GigabitEthernet2/0/0 Original nexthop: 200.1.2.1 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
The preceding command output shows that there are two valid routes to destination 9.1.1.0/24. The route with the next-hop address of 200.1.1.1 is the optimal route because the router ID of Router is smaller.
- Set MED attributes for routes.
# Apply a routing policy to set an MED value for the route advertised by Router B to Router A (the default MED value of a route is 0).
[RouterB] route-policy policy10 permit node 10
[RouterB-route-policy] apply cost 100
[RouterB-route-policy] quit
[RouterB] bgp 65009
[RouterB-bgp] peer 200.1.1.2 route-policy policy10 export
# View the routing table of Router A.
[RouterA] display bgp routing-table 9.1.1.0 24 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 9.1.1.0/24: From: 200.1.2.1 (3.3.3.3) Route Duration: 00h07m45s Direct Out-interface: GigabitEthernet2/0/0 Original nexthop: 200.1.2.1 Qos information : 0x0 AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, pre 255 Advertised to such 2 peers: 200.1.1.1 200.1.2.1 BGP routing table entry information of 9.1.1.0/24: From: 200.1.1.1 (2.2.2.2) Route Duration: 00h00m08s Direct Out-interface: GigabitEthernet1/0/0 Original nexthop: 200.1.1.1 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
The preceding command output shows that the MED value of the route with the next-hop address of 200.1.1.1 (Router B) is 100 and the MED value of the route with the next-hop address of 200.1.2.1 is 0. The route with the smaller MED value is selected.
Configuration Files
Configuration file of Router A
#
sysname Router A
#
interface GigabitEthernet1/0/0
ip address 200.1.1.2 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 200.1.2.2 255.255.255.0
#
bgp 65008
router-id 1.1.1.1
peer 200.1.1.1 as-number 65009
peer 200.1.2.1 as-number 65009
#
ipv4-family unicast
undo synchronization
peer 200.1.1.1 enable
peer 200.1.2.1 enable
#
return
Configuration file of Router B
#
sysname Router B
#
interface GigabitEthernet1/0/0
ip address 9.1.1.1 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 200.1.1.1 255.255.255.0
#
bgp 65009
router-id 2.2.2.2
peer 9.1.1.2 as-number 65009
peer 200.1.1.2 as-number 65008
#
ipv4-family unicast
undo synchronization
network 9.1.1.0 255.255.255.0
peer 9.1.1.2 enable
peer 200.1.1.2 enable
peer 200.1.1.2 route-policy policy10 export
#
route-policy policy10 permit node 10
apply cost 100
#
return
Configuration file of Router C
#
sysname Router C
#
interface GigabitEthernet1/0/0
ip address 9.1.1.2 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 200.1.2.1 255.255.255.0
#
bgp 65009
router-id 3.3.3.3
peer 9.1.1.1 as-number 65009
peer 200.1.2.2 as-number 65008
#
ipv4-family unicast
undo synchronization
network 9.1.1.0 255.255.255.0
peer 9.1.1.1 enable
peer 200.1.2.2 enable
#
return