-->![Weight Weight](http://networklessons.com/wp-content/uploads/2013/02/bgp-as-path-prepend-lab.png)
BGP: Weight and Local-Preference. These two routers are BGP neighbors of R1. The carot “” indicates the routes given to us by R3 (10.1.13.2) have been placed in the routing table. The first two attributes that are checked when two redundant paths are found are weight and local preference, which we’ll discuss soon. The weight attribute is a Cisco proprietary technology and considered as first attribute in BGP. The default value of weight is 0 and the range is from 0 to 65535. If we change the weight value of one router that change will not propagate to other router and the route with maximum weight value will be considered as the best route.
This article walks you through the steps to enable BGP on a cross-premises Site-to-Site (S2S) VPN connection and a VNet-to-VNet connection using the Resource Manager deployment model and PowerShell.
Note
This article has been updated to use the new Azure PowerShell Azmodule. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020.To learn more about the new Az module and AzureRM compatibility, seeIntroducing the new Azure PowerShell Az module. ForAz module installation instructions, see Install Azure PowerShell.
About BGP
BGP is the standard routing protocol commonly used in the Internet to exchange routing and reachability information between two or more networks. BGP enables the Azure VPN Gateways and your on-premises VPN devices, called BGP peers or neighbors, to exchange 'routes' that will inform both gateways on the availability and reachability for those prefixes to go through the gateways or routers involved. BGP can also enable transit routing among multiple networks by propagating routes a BGP gateway learns from one BGP peer to all other BGP peers.
See Overview of BGP with Azure VPN Gateways for more discussion on benefits of BGP and to understand the technical requirements and considerations of using BGP.
Getting started with BGP on Azure VPN gateways
This article walks you through the steps to do the following tasks:
- Part 2 - Establish a cross-premises connection with BGP
Each part of the instructions forms a basic building block for enabling BGP in your network connectivity. If you complete all three parts, you build the topology as shown in the following diagram:
You can combine parts together to build a more complex, multi-hop, transit network that meets your needs.
Part 1 - Configure BGP on the Azure VPN Gateway
The configuration steps set up the BGP parameters of the Azure VPN gateway as shown in the following diagram:
Before you begin
- Verify that you have an Azure subscription. If you don't already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free account.
- Install the Azure Resource Manager PowerShell cmdlets. For more information about installing the PowerShell cmdlets, see How to install and configure Azure PowerShell.
Step 1 - Create and configure VNet1
1. Declare your variables
For this exercise, we start by declaring our variables. The following example declares the variables using the values for this exercise. Be sure to replace the values with your own when configuring for production. You can use these variables if you are running through the steps to become familiar with this type of configuration. Modify the variables, and then copy and paste into your PowerShell console.
2. Connect to your subscription and create a new resource group
To use the Resource Manager cmdlets, Make sure you switch to PowerShell mode. For more information, see Using Windows PowerShell with Resource Manager.
Open your PowerShell console and connect to your account. Use the following sample to help you connect:
3. Create TestVNet1
The following sample creates a virtual network named TestVNet1 and three subnets, one called GatewaySubnet, one called FrontEnd, and one called Backend. When substituting values, it's important that you always name your gateway subnet specifically GatewaySubnet. If you name it something else, your gateway creation fails.
Step 2 - Create the VPN Gateway for TestVNet1 with BGP parameters
1. Create the IP and subnet configurations
Request a public IP address to be allocated to the gateway you will create for your VNet. You'll also define the required subnet and IP configurations.
2. Create the VPN gateway with the AS number
Create the virtual network gateway for TestVNet1. BGP requires a Route-Based VPN gateway, and also the addition parameter, -Asn, to set the ASN (AS Number) for TestVNet1. If you do not set the ASN parameter, ASN 65515 is assigned. Creating a gateway can take a while (30 minutes or more to complete).
3. Obtain the Azure BGP Peer IP address
Once the gateway is created, you need to obtain the BGP Peer IP address on the Azure VPN Gateway. This address is needed to configure the Azure VPN Gateway as a BGP Peer for your on-premises VPN devices.
The last command shows the corresponding BGP configurations on the Azure VPN Gateway; for example:
Once the gateway is created, you can use this gateway to establish cross-premises connection or VNet-to-VNet connection with BGP. The following sections walk through the steps to complete the exercise.
Part 2 - Establish a cross-premises connection with BGP
To establish a cross-premises connection, you need to create a Local Network Gateway to represent your on-premises VPN device, and a Connection to connect the VPN gateway with the local network gateway. While there are articles that walk you through these steps, this article contains the additional properties required to specify the BGP configuration parameters.
Before proceeding, make sure you have completed Part 1 of this exercise.
Step 1 - Create and configure the local network gateway
1. Declare your variables
This exercise continues to build the configuration shown in the diagram. Be sure to replace the values with the ones that you want to use for your configuration.
A couple of things to note regarding the local network gateway parameters:
- The local network gateway can be in the same or different location and resource group as the VPN gateway. This example shows them in different resource groups in different locations.
- The prefix you need to declare for the local network gateway is the host address of your BGP Peer IP address on your VPN device. In this case, it's a /32 prefix of '10.52.255.254/32'.
- As a reminder, you must use different BGP ASNs between your on-premises networks and Azure VNet. If they are the same, you need to change your VNet ASN if your on-premises VPN device already uses the ASN to peer with other BGP neighbors.
Before you continue, make sure you are still connected to Subscription 1.
2. Create the local network gateway for Site5
Be sure to create the resource group if it is not created, before you create the local network gateway. Notice the two additional parameters for the local network gateway: Asn and BgpPeerAddress.
Step 2 - Connect the VNet gateway and local network gateway
1. Get the two gateways
2. Create the TestVNet1 to Site5 connection
In this step, you create the connection from TestVNet1 to Site5. You must specify '-EnableBGP $True' to enable BGP for this connection. As discussed earlier, it is possible to have both BGP and non-BGP connections for the same Azure VPN Gateway. Unless BGP is enabled in the connection property, Azure will not enable BGP for this connection even though BGP parameters are already configured on both gateways.
The following example lists the parameters you enter into the BGP configuration section on your on-premises VPN device for this exercise:
The connection is established after a few minutes, and the BGP peering session starts once the IPsec connection is established.
Part 3 - Establish a VNet-to-VNet connection with BGP
This section adds a VNet-to-VNet connection with BGP, as shown in the following diagram:
The following instructions continue from the previous steps. You must complete Part I to create and configure TestVNet1 and the VPN Gateway with BGP.
Step 1 - Create TestVNet2 and the VPN gateway
It is important to make sure that the IP address space of the new virtual network, TestVNet2, does not overlap with any of your VNet ranges.
In this example, the virtual networks belong to the same subscription. You can set up VNet-to-VNet connections between different subscriptions. For more information, see Configure a VNet-to-VNet connection. Make sure you add the '-EnableBgp $True' when creating the connections to enable BGP.
1. Declare your variables
Be sure to replace the values with the ones that you want to use for your configuration.
2. Create TestVNet2 in the new resource group
3. Create the VPN gateway for TestVNet2 with BGP parameters
Request a public IP address to be allocated to the gateway you will create for your VNet and define the required subnet and IP configurations.
Create the VPN gateway with the AS number. You must override the default ASN on your Azure VPN gateways. The ASNs for the connected VNets must be different to enable BGP and transit routing.
Step 2 - Connect the TestVNet1 and TestVNet2 gateways
In this example, both gateways are in the same subscription. You can complete this step in the same PowerShell session.
1. Get both gateways
![Weight Weight](http://networklessons.com/wp-content/uploads/2013/02/bgp-as-path-prepend-lab.png)
Make sure you log in and connect to Subscription 1.
2. Create both connections
In this step, you create the connection from TestVNet1 to TestVNet2, and the connection from TestVNet2 to TestVNet1.
Important
Be sure to enable BGP for BOTH connections.
After completing these steps, the connection is established after a few minutes. The BGP peering session is up once the VNet-to-VNet connection is completed.
If you completed all three parts of this exercise, you have established the following network topology:
Next steps
Once your connection is complete, you can add virtual machines to your virtual networks. See Create a Virtual Machine for steps.