Create a Site to site VPN
Create a Site to site VPN
Azure portal
A Site-to-Site VPN gateway connection is used to connect your on-premises network to an
Azure virtual network over an IPsec/IKE (IKEv1 or IKEv2) VPN tunnel. This type of
connection requires a VPN device located on-premises that has an externally facing public IP
address assigned to it. For more information about VPN gateways, see About VPN gateway.
Make sure you have a compatible VPN device and someone who can configure it. For
more information about compatible VPN devices and device configuration, see About
VPN Devices.
Verify that you have an externally facing public IPv4 address for your VPN device.
This IP address cannot be located behind a NAT.
If you are unfamiliar with the IP address ranges located in your on-premises network
configuration, you need to coordinate with someone who can provide those details for
you. When you create this configuration, you must specify the IP address range
prefixes that Azure will route to your on-premises location. None of the subnets of
your on-premises network can over lap with the virtual network subnets that you want
to connect to.
Example values
The examples in this article use the following values. You can use these values to create a test
environment, or refer to them to better understand the examples in this article. For more
information about VPN Gateway settings in general, see About VPN Gateway Settings.
Note
In order for this VNet to connect to an on-premises location you need to coordinate with your
on-premises network administrator to carve out an IP address range that you can use
specifically for this virtual network. If a duplicate address range exists on both sides of the
VPN connection, traffic does not route the way you may expect it to. Additionally, if you
want to connect this VNet to another VNet, the address space cannot overlap with other
VNet. Take care to plan your network configuration accordingly.
1. From a browser, navigate to the Azure portal and sign in with your Azure account.
2. Click Create a resource. In the Search the marketplace field, type 'virtual network'.
Locate Virtual network from the returned list and click to open the Virtual Network
page.
3. Near the bottom of the Virtual Network page, from the Select a deployment model
list, select Resource Manager, and then click Create. This opens the 'Create virtual
network' page.
4. On the Create virtual network page, configure the VNet settings. When you fill in
the fields, the red exclamation mark becomes a green check mark when the characters
entered in the field are valid.
o Name: Enter the name for your virtual network. In this example, we use
VNet1.
o Address space: Enter the address space. If you have multiple address spaces
to add, add your first address space. You can add additional address spaces
later, after creating the VNet. Make sure that the address space that you
specify does not overlap with the address space for your on-premises location.
o Subscription: Verify that the subscription listed is the correct one. You can
change subscriptions by using the drop-down.
o Resource group: Select an existing resource group, or create a new one by
typing a name for your new resource group. If you are creating a new group,
name the resource group according to your planned configuration values. For
more information about resource groups, visit Azure Resource Manager
Overview.
o Location: Select the location for your VNet. The location determines where
the resources that you deploy to this VNet will reside.
o Subnet: Add the first subnet name and subnet address range. You can add
additional subnets and the gateway subnet later, after creating this VNet.
5. Select Pin to dashboard if you want to be able to find your VNet easily on the
dashboard, and then click Create. After clicking Create, you will see a tile on your
dashboard that will reflect the progress of your VNet. The tile changes as the VNet is
being created.
1. On the Settings page for your virtual network, navigate to DNS Servers and click to
open the DNS servers page.
When you create the gateway subnet, you specify the number of IP addresses that the subnet
contains. The number of IP addresses needed depends on the VPN gateway configuration that
you want to create. Some configurations require more IP addresses than others. We
recommend that you create a gateway subnet that uses a /27 or /28.
If you see an error that specifies that the address space overlaps with a subnet, or that the
subnet is not contained within the address space for your virtual network, check your VNet
address range. You may not have enough IP addresses available in the address range you
created for your virtual network. For example, if your default subnet encompasses the entire
address range, there are no IP addresses left to create additional subnets. You can either
adjust your subnets within the existing address space to free up IP addresses, or specify an
additional address range and create the gateway subnet there.
1. In the portal, navigate to the virtual network for which you want to create a virtual
network gateway.
2. In the Settings section of your VNet page, click Subnets to expand the Subnets page.
3. On the Subnets page, click +Gateway subnet at the top to open the Add subnet
page.
4. The Name for your subnet is automatically filled in with the value 'GatewaySubnet'.
The GatewaySubnet value is required in order for Azure to recognize the subnet as the
gateway subnet. Adjust the auto-filled Address range values to match your
configuration requirements.
Important
When working with gateway subnets, avoid associating a network security group (NSG) to
the gateway subnet. Associating a network security group to this subnet may cause your VPN
gateway to stop functioning as expected. For more information about network security
groups, see What is a network security group?
After the gateway is created, view the IP address that has been assigned to it by looking at the
virtual network in the portal. The gateway appears as a connected device. You can click the
connected device (your virtual network gateway) to view more information.
A shared key. This is the same shared key that you specify when creating your Site-
to-Site VPN connection. In our examples, we use a basic shared key. We recommend
that you generate a more complex key to use.
The Public IP address of your virtual network gateway. You can view the public IP
address by using the Azure portal, PowerShell, or CLI. To find the Public IP address
of your VPN gateway using the Azure portal, navigate to Virtual network gateways,
then click the name of your gateway.
Depending on the VPN device that you have, you may be able to download a VPN device
configuration script. For more information, see Download VPN device configuration scripts.
1. Navigate to and open the page for your virtual network gateway. There are multiple
ways to navigate. You can navigate to the gateway 'VNet1GW' by going to
TestVNet1 -> Overview -> Connected devices -> VNet1GW.
2. On the page for VNet1GW, click Connections. At the top of the Connections page,
click +Add to open the Add connection page.
3. On the Add connection page, configure the values for your connection.
o Name: Name your connection.
o Connection type: Select Site-to-site(IPSec).
o Virtual network gateway: The value is fixed because you are connecting
from this gateway.
o Local network gateway: Click Choose a local network gateway and select
the local network gateway that you want to use.
o Shared Key: the value here must match the value that you are using for your
local on-premises VPN device. The example uses 'abc123', but you can (and
should) use something more complex. The important thing is that the value
you specify here must be the same value that you specify when configuring
your VPN device.
o The remaining values for Subscription, Resource Group, and Location are
fixed.
4. Click OK to create your connection. You'll see Creating Connection flash on the
screen.
5. You can view the connection in the Connections page of the virtual network gateway.
The Status will go from Unknown to Connecting, and then to Succeeded.
1. In the Azure portal, click All resources and navigate to your virtual network gateway.
2. On the blade for your virtual network gateway, click Connections. You can see the
status of each connection.
3. Click the name of the connection that you want to verify to open Essentials. In
Essentials, you can view more information about your connection. The Status is
'Succeeded' and 'Connected' when you have made a successful connection.
Azure PowerShell
1.
o $VMs = Get-AzureRmVM
o $Nics = Get-AzureRmNetworkInterface | Where VirtualMachine -ne
$null
o
o foreach($Nic in $Nics)
o {
o $VM = $VMs | Where-Object -Property Id -eq
$Nic.VirtualMachine.Id
o $Prv = $Nic.IpConfigurations | Select-Object -ExpandProperty
PrivateIpAddress
o $Alloc = $Nic.IpConfigurations | Select-Object -ExpandProperty
PrivateIpAllocationMethod
o Write-Output "$($VM.Name): $Prv,$Alloc"
o }
o
2. Verify that you are connected to your VNet using the VPN connection.
3. Open Remote Desktop Connection by typing "RDP" or "Remote Desktop
Connection" in the search box on the taskbar, then select Remote Desktop
Connection. You can also open Remote Desktop Connection using the 'mstsc'
command in PowerShell.
4. In Remote Desktop Connection, enter the private IP address of the VM. You can click
"Show Options" to adjust additional settings, then connect.
If you are having trouble connecting to a virtual machine over your VPN connection, check
the following: