| 分类: ~~~ BGP ~~~ |
Unlike the weight attribute, which is relevant only to the local router, local preference is an attribute that is exchanged among routers in the same AS.
Local preference is set via the bgp default local-preference command or with route maps, as illustrated in the following example:
The bgp default local-preference command will set the local preference on the updates out of the router going to peers in the same AS. In the above diagram, AS256 is receiving updates about 170.10.0.0 from two different sides of the organization. Local preference will help us determine which way to exit AS256 in order to reach that network. Let us assume that Router D (RTD) is the preferred exit point. The following configuration sets the local preference for updates coming from AS300 to 200, and those coming from AS100 to 150.
RTC#
router bgp 256
neighbor 1.1.1.1 remote-as 100
neighbor 128.213.11.2 remote-as 256
bgp default local-preference 150RTD#
router bgp 256
neighbor 3.3.3.4 remote-as 300
neighbor 128.213.11.1 remote-as 256
bgp default local-preference 200
In the above configuration, RTC sets the local preference of all updates to 150. RTD sets the local preference of all updates to 200. Because local preference is exchanged within AS256, both RTC and RTD will realize that network 170.10.0.0 has a higher local preference when coming from AS300 rather than when coming from AS100. All traffic in AS256 addressed to that network is sent to RTD as an exit point.
More flexibility is provided by using route maps. In the above example, all updates received by RTD are tagged with local preference 200 when they reach RTD. This means that updates coming from AS34 will also be tagged with the local preference of 200. This might not be needed. This is why we can use route maps to specify what specific updates need to be tagged with a specific local preference, as shown below:
RTD#
router bgp 256 neighbor 3.3.3.4 remote-as 300 neighbor 3.3.3.4 route-map setlocalin in neighbor 128.213.11.1 remote-as 256 .... ip as-path access-list 7 permit ^300$ ...route-map setlocalin permit 10 match as-path 7 set local-preference 200route-map setlocalin permit 20 set local-preference 150With this configuration, any update coming from AS300 will be set with a local preference of 200. Any other updates such as those coming from AS34 will be set with a value of 150.

加载中…