# BGP Load Balancing

![](https://1953625668-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFMJhMiVjTLWfbfC-S4%2F-MVuKfrOzYGoYG6mkYoF%2F-MVusVe4czcsdTUQ3NHD%2Fimage.png?alt=media\&token=e39fc442-8e25-43d3-b3eb-3e281bdfd112)

## Equal Bandwidth Load Balancing

Как пример, будет удобнее настроить Load Balancing для AS8000 для входа в AS9000 для маршрута 40.0.0.0, который AS9000 и анонсирует с RT.MSK.M34 и RT.MSK.M8, так как для этих маршрутов метрика одинкаова:

```
root@AS8000# run show route 40.0.0.0                                      

inet.0: 18 destinations, 30 routes (18 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

40.0.0.0/24        *[BGP/170] 00:53:39, localpref 100
                      AS path: 9000 500 I, validation-state: unverified
                    > to 8.0.0.3 via ge-0/0/1.0
                    [BGP/170] 00:53:39, localpref 100
                      AS path: 9000 500 I, validation-state: unverified
                    > to 8.0.0.1 via ge-0/0/4.0
                    [BGP/170] 00:56:12, localpref 100
                      AS path: 8001 9001 9000 500 I, validation-state: unverified
                    > to 8.1.1.0 via ge-0/0/2.0

root@AS8000# show | compare 
[edit routing-options]
+   forwarding-table {
+       export LoadBalancing;
+   }
[edit protocols bgp group eBGP]
+     multipath;
[edit policy-options]
+   policy-statement LoadBalancing {
+       from {
+           route-filter 40.0.0.0/24 exact;
+       }
+       then {
+           load-balance per-packet;
+       }
+   }
```

Теперь в разные моменты времени мы видим разную трассировку:

```
root@AS8000# run traceroute 40.0.0.1 
traceroute to 40.0.0.1 (40.0.0.1), 30 hops max, 40 byte packets
 1  8.0.0.3 (8.0.0.3)  9.077 ms 8.0.0.1 (8.0.0.1)  11.668 ms  0.704 ms
 2  10.1.1.3 (10.1.1.3)  4.539 ms  1.479 ms 10.1.1.5 (10.1.1.5)  2.975 ms
 3  10.0.0.3 (10.0.0.3)  9.956 ms  1.783 ms  1.706 ms
 4  10.0.0.9 (10.0.0.9)  9.057 ms  2.718 ms  4.660 ms
 5  10.2.2.1 (10.2.2.1)  17.752 ms  3.032 ms  2.612 ms
 6  10.2.2.8 (10.2.2.8)  15.267 ms  4.258 ms  3.409 ms
 7  40.0.0.1 (40.0.0.1)  9.470 ms  4.415 ms  4.156 ms

[edit]
root@AS8000# run traceroute 40.0.0.1    
traceroute to 40.0.0.1 (40.0.0.1), 30 hops max, 40 byte packets
 1  8.0.0.1 (8.0.0.1)  1.244 ms 8.0.0.3 (8.0.0.3)  1.238 ms  0.886 ms
 2  10.1.1.5 (10.1.1.5)  1.243 ms  1.405 ms 10.1.1.3 (10.1.1.3)  1.060 ms
 3  10.0.0.3 (10.0.0.3)  1.782 ms  2.007 ms  1.978 ms
 4  10.0.0.9 (10.0.0.9)  2.374 ms  2.531 ms  2.728 ms
 5  10.2.2.1 (10.2.2.1)  2.777 ms  3.274 ms  2.439 ms
 6  10.2.2.8 (10.2.2.8)  3.500 ms  3.828 ms  3.570 ms
 7  40.0.0.1 (40.0.0.1)  4.156 ms  4.037 ms  4.300 ms
```

А у нашего маршрута добавился ещё один nex-hop:

```
root@AS8000# run show route 40.0.0.0 active-path 

inet.0: 18 destinations, 30 routes (18 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

40.0.0.0/24        *[BGP/170] 00:57:12, localpref 100
                      AS path: 9000 500 I, validation-state: unverified
                    > to 8.0.0.3 via ge-0/0/1.0
                      to 8.0.0.1 via ge-0/0/4.0
```

В принципе, данная настройка делается обычно для iBGP-пиров, что мы и сделаем. На AS8000 её также можно оставить.

Пример конфигурации для iBGP-пиров и OSPF:

```
root@RT.MSK.M34# show | compare 
[edit routing-options]
+   forwarding-table {
+       export LoadBalancing;
+   }
[edit protocols bgp group intra-Sub-AS]
+     multipath;
[edit policy-options]
+   policy-statement LoadBalancing {
+       from protocol [ bgp ospf ];
+       then {
+           load-balance per-packet;
+       }
+   }
```

{% hint style="warning" %}
Можно не конфигурировать в policy-statement LoadBalancing поле from, тогда балансировка будет работать для всех протоколов, вообще.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://netlabs.gitbook.io/juniper/5-bgp/bgp-load-balancing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
