Example for Configuring the BGP Community Attribute
Networking Requirements
As shown in Figure 9-35, EBGP connections are established between Router B and Router A, and between Router B and Router C. It is required that AS 20 not advertise the routes advertised by AS 10 to AS 30.
Configuration Roadmap
The configuration roadmap is as follows:
Configure a route-policy on RouterA to advertise the No_Export attribute so that AS 20 does not advertise the routes advertised by AS 10 to AS 30.
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 9.1.1.1 255.255.255.0 [RouterA-GigabitEthernet1/0/0] quit [RouterA] interface gigabitethernet 2/0/0 [RouterA-GigabitEthernet2/0/0] ip address 200.1.2.1 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 EBGP connections.
# Configure Router A.
[RouterA] bgp 10
[RouterA-bgp] router-id 1.1.1.1
[RouterA-bgp] peer 200.1.2.2 as-number 20
[RouterA-bgp] ipv4-family unicast
[RouterA-bgp-af-ipv4] network 9.1.1.0 255.255.255.0
[RouterA-bgp-af-ipv4] quit
[RouterA-bgp] quit
# Configure Router B.
[RouterB] bgp 20
[RouterB-bgp] router-id 2.2.2.2
[RouterB-bgp] peer 200.1.2.1 as-number 10
[RouterB-bgp] peer 200.1.3.2 as-number 30
[RouterB-bgp] quit
# Configure Router C.
[RouterC] bgp 30
[RouterC-bgp] router-id 3.3.3.3
[RouterC-bgp] peer 200.1.3.1 as-number 20
[RouterC-bgp] quit
# On Router B, view detailed information about route 9.1.1.0/24.
[RouterB] display bgp routing-table 9.1.1.0
BGP local router ID : 2.2.2.2 Local AS number : 20 Paths: 1 available, 1 best, 1 select BGP routing table entry information of 9.1.1.0/24: From: 200.1.2.1 (1.1.1.1) Route Duration: 00h00m42s Direct Out-interface: GigabitEthernet2/0/0 Original nexthop: 200.1.2.1 Qos information : 0x0 AS-path 10, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 200.1.2.1 200.1.3.2
The preceding command output shows that Router B advertises the received BGP route to Router C in AS 30.
# View the BGP routing table of Router C.
[RouterC] display bgp routing-table
BGP Local router ID is 3.3.3.3 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 1 Network NextHop MED LocPrf PrefVal Path/Ogn *> 9.1.1.0/24 200.1.3.1 0 20 10i
The preceding command output shows that Router C has learned route 9.1.1.0/24 from Router B.
- Configure a BGP community attribute.
# Configure a routing policy on Router A to prevent BGP routes to be advertised by Router A to Router B from being advertised to any other AS.
[RouterA] route-policy comm_policy permit node 10
[RouterA-route-policy] apply community no-export
[RouterA-route-policy] quit
# Apply the routing policy.
[RouterA] bgp 10
[RouterA-bgp] ipv4-family unicast
[RouterA-bgp-af-ipv4] peer 200.1.2.2 route-policy comm_policy export
[RouterA-bgp-af-ipv4] peer 200.1.2.2 advertise-community
# On Router B, view detailed information about route 9.1.1.0/24.
[RouterB] display bgp routing-table 9.1.1.0
BGP local router ID : 2.2.2.2 Local AS number : 20 Paths: 1 available, 1 best, 1 select BGP routing table entry information of 9.1.1.0/24: From: 200.1.2.1 (1.1.1.1) Route Duration: 00h00m09s Direct Out-interface: GigabitEthernet2/0/0 Original nexthop: 200.1.2.1 Qos information : 0x0 Community:no-export AS-path 10, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255 Not advertised to any peer yet
The preceding command output shows that route 9.1.1.0/24 carries the configured community attribute and Router B does not advertise this route to any other AS.
Configuration Files
Configuration file of Router A
#
sysname RouterA
#
interface GigabitEthernet1/0/0
ip address 9.1.1.1 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 200.1.2.1 255.255.255.0
#
bgp 10
router-id 1.1.1.1
peer 200.1.2.2 as-number 20
#
ipv4-family unicast
undo synchronization
network 9.1.1.0 255.255.255.0
peer 200.1.2.2 enable
peer 200.1.2.2 route-policy comm_policy export
peer 200.1.2.2 advertise-community
#
route-policy comm_policy permit node 10
apply community no-export
#
return
Configuration file of Router B
#
sysname RouterB
#
interface GigabitEthernet1/0/0
ip address 200.1.3.1 255.255.255.0
#
interface GigabitEthernet2/0/0
ip address 200.1.2.2 255.255.255.0
#
bgp 20
router-id 2.2.2.2
peer 200.1.2.1 as-number 10
peer 200.1.3.2 as-number 30
#
ipv4-family unicast
undo synchronization
peer 200.1.2.1 enable
peer 200.1.3.2 enable
#
return
Configuration file of Router C
#
sysname RouterC
#
interface GigabitEthernet1/0/0
ip address 200.1.3.2 255.255.255.0
#
bgp 30
router-id 3.3.3.3
peer 200.1.3.1 as-number 20
#
ipv4-family unicast
undo synchronization
peer 200.1.3.1 enable
#
return