Example for Configuring the Local Preference and Community Attribute in a BGP Route-policy
Networking Requirements
BGP runs on RouterA and RouterB. RouterA imports two static blackhole routes. RouterB needs to change the local preference and add the community attribute of routes of 192.168.10.0/24.
Procedure
- Configure RouterA.
# sysname RouterA # interface GigabitEthernet1/0/0 ip address 192.168.0.1 255.255.255.0 # interface LoopBack0 ip address 1.1.1.1 255.255.255.255 # bgp 10 router-id 1.1.1.1 //Set the router ID. You are advised to set the IP address of Loopback 0 as the router ID. peer 192.168.0.2 as-number 10 //Configure an IP address and an AS number for a peer. # ipv4-family unicast undo synchronization import-route static //Configure the router to import static routes. peer 192.168.0.2 enable # ip route-static 192.168.10.0 255.255.255.0 NULL0 //Configure static blackhole routes. ip route-static 192.168.20.0 255.255.255.0 NULL0 #
- Configure RouterB.
# sysname RouterB # acl number 2001 rule 2 permit source 192.168.10.0 0.0.0.255 //Add a rule in ACL 2001 to permit the packets from 192.168.10.0/24 to pass through. # interface GigabitEthernet1/0/0 ip address 192.168.0.2 255.255.255.0 # interface LoopBack0 ip address 2.2.2.2 255.255.255.255 # bgp 10 router-id 2.2.2.2 peer 192.168.0.1 as-number 10 # ipv4-family unicast undo synchronization peer 192.168.0.1 enable peer 192.168.0.1 route-policy admin import //Configure a route-policy admin to filter the routes of peers. # route-policy admin permit node 10 //Configure a route-policy admin and set the index of the node in the route-policy to 10 and the matching mode to permit. if-match acl 2001 //Configure a matching rule based on ACL 2001. apply local-preference 120 //Set the local preference of BGP routes to 120. apply community 10:1 //Set the BGP community attribute of BGP routes to 10:1. # route-policy admin permit node 20 //Configure a route-policy admin and set the index of the node in the route-policy to 20 and the matching mode to permit. #
- Verify the configuration.
# Run the display bgp routing-table command on RouterB to view the BGP routing table. The routing table contains routes of 192.168.10.0/24 and 192.168.20.0/24. Run the display bgp routing-table 192.168.10.0 24 command on RouterB. You can view detailed information about routes of 192.168.10.0/24, including the local preference 120 and community attribute 10:1.
Configuration Notes
- By default, IGP-BGP synchronization is disabled.
- By default, peers are automatically enabled in the BGP-IPv4 unicast address family view.
- A permit node without contents must be appended to a route-policy so that the routes that do not match the previous nodes can be added to the BGP routing table.
- The local preference is only used for route selection within an AS and is not advertised outside the AS. Therefore, the apply local-preference command does not take effect when a route-policy is configured for an EBGP peer.