Route Distinguisher and Route Target
BGP VPN services use two values to keep the routes of different customers apart:
- The route distinguisher (RD) makes a customer prefix unique in BGP, so that customers can use the same address ranges.
- The route target (RT) decides which VRF or VPN instance imports a route.
RouterOS uses them in L3VPN (/routing/bgp/vpn),
EVPN (/routing/bgp/evpn) and
BGP VPLS (/routing/bgp/vpls):
| Menu | Route distinguisher | Route targets |
|---|---|---|
/routing/bgp/vpn | route-distinguisher | import.route-targets, export.route-targets |
/routing/bgp/evpn | rd | import.route-targets, export.route-targets |
/routing/bgp/vpls | rd | import-route-targets, export-route-targets |
Route distinguisher
A route distinguisher is a 64-bit (8-byte) value that is added in front of a customer prefix. The result is a VPN
route, for example a VPNv4 route. Two customers that use the same subnet export two different VPN routes when their
VRFs have different route distinguishers. RouterOS shows a VPN route as <prefix>&, for example
192.168.10.0/24&65000:1.
The route distinguisher only makes routes unique. It does not decide which VRF imports a route: route targets do. When two VRFs on one PE export the same prefix with the same route distinguisher, they produce the same VPN route, and BGP peers receive only one of them: the prefix of the other VRF is lost. Use a separate route distinguisher for each VRF on a PE.
An RD consists of three parts (RFC 4364):
- Type (2 bytes).
- Administrator subfield: an AS number or an IPv4 address.
- Assigned number subfield: a value chosen by the administrator.
Three RD types are defined:
| Type | Administrator | Assigned number | Written in RouterOS | Examples |
|---|---|---|---|---|
| 0 | 2-byte AS number | 4-byte number | <AS>:<number>, AS 0-65535 | 65000:1, 65000:70000 |
| 1 | IPv4 address | 2-byte number | <IPv4 address>:<number> | 192.0.2.1:5 |
| 2 | 4-byte AS number | 2-byte number | <AS>:<number>, AS above 65535, or <AS>L:<number> | 4200000001:1, 65000L:1 |
RouterOS chooses the type from the administrator subfield:
- An AS number up to 65535 gives a type 0 RD.
65000:1is type 0, and its assigned number has 4 bytes, so65000:70000is valid. - An AS number above 65535 gives a type 2 RD.
70000:1is type 2, and its assigned number has 2 bytes (0-65535), so70000:65536is not a valid RD. - To use a type 2 RD with an AS number up to 65535, add
Lto the AS number:65000L:1. RouterOS shows a received type 2 RD with such an AS number in the same form.65000:1and65000L:1are two different route distinguishers. - An IPv4 address gives a type 1 RD, with a 2-byte assigned number.
Route targets
A route target is a BGP extended community that controls the import and export of routing information between routing instances. A VRF or VPN instance adds its export route targets to the routes it exports. It imports the routes whose route target is in its import list, whatever their route distinguisher. An EVPN entry without route targets sets them automatically, see EVPN.
Route targets are written like route distinguishers, and the same rules decide the extended community type (RFC 4360, RFC 5668). The route target sub-type is 0x02 in all three:
| Written in RouterOS | Extended community | Examples |
|---|---|---|
<AS>:<number>, AS 0-65535 | 2-octet AS-specific, 4-byte number | 65000:100, 65000:70000 |
<IPv4 address>:<number> | IPv4-address-specific, 2-byte number | 192.0.2.1:100 |
<AS>:<number>, AS above 65535, or <AS>L:<number> | 4-octet AS-specific, 2-byte number | 4200000001:100, 65000L:100 |
An invalid route target, for example 70000:65536, is refused with the error
invalid prefix route distinguisher value.
The routing table shows the route targets of a route in bgp.ext-communities with the rt: prefix, for example
rt:65000:100. RouterOS keeps received VPN routes (afi=vpnv4) also when no VRF on the router imports their
route targets.
Example: two customers with the same subnet
PE1 connects two customers that both use 192.168.10.0/24: customer A on ether5 and customer B on ether6. Each
customer gets a VRF with its own route distinguisher and route target. PE1 already has the BGP instance bgp1
(AS 65000) and a VPNv4 session with PE2. See VRF for a complete L3VPN configuration, including MPLS.
On PE1, add the VRF of customer A:
/ip/vrf
add name=cust-a interfaces=ether5
/ip/address
add address=192.168.10.1/24 interface=ether5
/routing/bgp/vpn
add name=cust-a instance=bgp1 vrf=cust-a \
route-distinguisher=65000:1 label-allocation-policy=per-vrf \
.redistribute=connected .route-targets=65000:100 \
import.route-targets=65000:100
Then add the VRF of customer B, with the same subnet:
/ip/vrf
add name=cust-b interfaces=ether6
/ip/address
add address=192.168.10.1/24 interface=ether6
/routing/bgp/vpn
add name=cust-b instance=bgp1 vrf=cust-b \
route-distinguisher=65000:2 label-allocation-policy=per-vrf \
.redistribute=connected .route-targets=65000:200 \
import.route-targets=65000:200
PE2 receives two VPNv4 routes for the same subnet, one for each route distinguisher:
[admin@MikroTik] > /routing/route/print where afi=vpnv4
Flags: A - ACTIVE; b - BGP
Columns: DST-ADDRESS, GATEWAY, AFI, ROUTING-TABLE, DISTANCE, SCOPE,
TARGET-SCOPE, IMMEDIATE-GW
DST-ADDRESS GATEWAY AFI ROUT DIS SC TA IMMEDIATE-GW
Ab 192.168.10.0/24&65000:1 10.0.0.1 vpnv4 main 200 40 30 10.0.0.1%ether2
Ab 192.168.10.0/24&65000:2 10.0.0.1 vpnv4 main 200 40 30 10.0.0.1%ether2
The detail view shows the route target of each route in .ext-communities:
[admin@MikroTik] > /routing/route/print detail where afi=vpnv4
Flags: A - ACTIVE; b - BGP
Ab afi=vpnv4 contribution=active dst-address=192.168.10.0/24&65000:1
routing-table=main label=16 gateway=10.0.0.1 immediate-gw=10.0.0.1%ether2
distance=200 scope=40 target-scope=30 belongs-to="bgp-VPNv4-10.0.0.1"
bgp.session=to-pe1-1 .ext-communities=rt:65000:100 .local-pref=100
.origin=incomplete debug.fwp-ptr=0x20282300
Ab afi=vpnv4 contribution=active dst-address=192.168.10.0/24&65000:2
routing-table=main label=17 gateway=10.0.0.1 immediate-gw=10.0.0.1%ether2
distance=200 scope=40 target-scope=30 belongs-to="bgp-VPNv4-10.0.0.1"
bgp.session=to-pe1-1 .ext-communities=rt:65000:200 .local-pref=100
.origin=incomplete debug.fwp-ptr=0x20282300
If both VRFs on PE1 used the route distinguisher 65000:1, they would export the same VPN route, and PE2 would receive only one route for 192.168.10.0/24.
For a customer network connected to more than one PE, see Route distinguisher per site or per customer on the VRF page.