{"id":97774,"date":"2020-10-26T16:00:18","date_gmt":"2020-10-26T13:00:18","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it\/"},"modified":"2020-10-26T16:00:18","modified_gmt":"2020-10-26T13:00:18","slug":"how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it\/","title":{"rendered":"#How To Connect Azure Virtual Networks Using Virtual Network Peering \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a283eb64e953\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a283eb64e953\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it\/#Connecting_Virtual_Machines_via_Peered_Virtual_Networks\" >Connecting Virtual Machines via Peered Virtual Networks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it\/#Demonstrating_the_Peered_Virtual_Network_Connection\" >Demonstrating the Peered Virtual Network Connection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-azure-virtual-networks-using-virtual-network-peering-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How To Connect Azure Virtual Networks Using Virtual Network Peering \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4724\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/dd73232a7248fcf591e921f5e52164df\/p\/uploads\/2020\/04\/30fdf294.png\" alt=\"azure logo\" width=\"1400\" height=\"600\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Azure Virtual Network (VNet) Peering enables the connection of two or more virtual networks in Azure. Connectivity-wise the two peered networks <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ear as one. Peered traffic is routed through Microsoft\u2019s private network and not over the public internet. An Azure virtual network is a software-defined network with a custom address space and segmented subnets.<\/p>\n<p>There are two types of peering offered by Azure.<\/p>\n<ul>\n<li>Virtual network peering enables connecting virtual networks within the same Azure region.<\/li>\n<li>Global virtual network peering connects traffic across Azure regions.<\/li>\n<\/ul>\n<p>Why would we want to use virtual network peering to connect two different virtual networks? There are a couple of benefits to peered networks.<\/p>\n<ul>\n<li>Utilize a low-latency and high-bandwidth connection between resources in different virtual networks.<\/li>\n<li>Transfer data across Azure subscriptions, tenants, and regions.<\/li>\n<li>No downtime when configuring peered virtual networks.<\/li>\n<\/ul>\n<p>In this article, we are going to demonstrate creating a peered network using Azure Powershell commands. You will need the <a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Finstall-az-ps%3Fview%3Dazps-4.8.0&amp;key=204a528a336ede4177fff0d84a044482\">Azure PowerShell<\/a> module to perform these commands.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Connecting_Virtual_Machines_via_Peered_Virtual_Networks\"><\/span>Connecting Virtual Machines via Peered Virtual Networks<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this tutorial, we are going to create two new resources groups, virtual networks, and virtual machines. Once everything has been set up, we will peer the virtual networks between the two Azure VM\u2019s and demonstrate that they can indeed communicate. First, we need to import the <code>Az<\/code> module and authenticate to Azure using the <code>Connect-AzAccount<\/code> cmdlet.<\/p>\n<pre><code class=\"language-powershell\">Import-Module -Name 'Az'&#13;\nConnect-AzAccount&#13;\n<\/code><\/pre>\n<p>Next, for the sake of this tutorial, we are going to create two resource groups where our virtual machines and virtual networks will reside.<\/p>\n<pre><code class=\"language-powershell\">New-AzResourceGroup -Name 'TestLocation1' -Location \"Central US\"&#13;\nNew-AzResourceGroup -Name 'TestLocation2' -Location \"Central US\"<\/code><\/pre>\n<figure id=\"attachment_7600\" style=\"width: 1115px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7600\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/633a010917360918896d00edbd9bb058\/p\/uploads\/2020\/10\/e1fab9af.png\" alt=\"Creating the resource groups for this tutorial.\" width=\"1115\" height=\"298\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Creating the resource groups for this tutorial.<\/figcaption><\/figure>\n<p>Before we provision our virtual machines, we first need to create the different virtual networks that we would like to peer together.<\/p>\n<pre><code class=\"language-powershell\">$Params = @{&#13;\n  \"Name\"              = 'TestVirtualNetwork1'&#13;\n  \"ResourceGroupName\" = 'TestLocation1'&#13;\n  \"Location\"          = 'Central US'&#13;\n  \"AddressPrefix\"     = '10.0.0.0\/16'&#13;\n  \"Subnet\"            = (New-AzVirtualNetworkSubnetConfig -Name 'VMSubnet' -AddressPrefix '10.0.1.0\/24')&#13;\n}&#13;\n&#13;\nNew-AzVirtualNetwork @Params&#13;\n<\/code><\/pre>\n<pre><code class=\"language-powershell\">$Params = @{&#13;\n  \"Name\"              = 'TestVirtualNetwork2'&#13;\n  \"ResourceGroupName\" = 'TestLocation2'&#13;\n  \"Location\"          = 'Central US'&#13;\n  \"AddressPrefix\"     = '10.1.0.0\/16'&#13;\n  \"Subnet\"            = (New-AzVirtualNetworkSubnetConfig -Name 'VMSubnet' -AddressPrefix '10.1.1.0\/24')&#13;\n}&#13;\n&#13;\nNew-AzVirtualNetwork @Params&#13;\n<\/code><\/pre>\n<p>We can verify that the virtual networks have been created successfully, using the <code>Get-AzVirtualNetwork<\/code> cmdlet.<\/p>\n<figure id=\"attachment_7601\" style=\"width: 1149px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7601\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/ff54b4f59fc64caf702743b69a5b3b01\/p\/uploads\/2020\/10\/ad0e26c9.png\" alt=\"Verifying that the virtual networks were successfully created.\" width=\"1149\" height=\"139\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Verifying that the virtual networks were successfully created.<\/figcaption><\/figure>\n<p>To demonstrate that we can connect two virtual networks, we need resources from within those networks to send traffic from. To do this, we will create two standard virtual machines each located in different virtual networks.<\/p>\n<pre><code class=\"language-powershell\">$Params = @{&#13;\n  'Name'                = 'LCWin2019-01'&#13;\n  'ResourceGroupName'   = 'TestLocation1'&#13;\n  'Location'            = 'centralus'&#13;\n  'VirtualNetworkName'  = 'TestVirtualNetwork1'&#13;\n  'SubnetName'          = 'VMSubnet'&#13;\n  'AddressPrefix'       = '10.0.1.0\/24'&#13;\n  'PublicIpAddressName' = 'TestVM01PublicIP'&#13;\n  'OpenPorts'           = 3389&#13;\n  'Image'               = 'MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest'&#13;\n  'Size'                = 'Standard_D2_v3'&#13;\n  'Credential'          = $VMCredential&#13;\n}&#13;\n&#13;\n$VM1 = New-AzVM @Params&#13;\n&#13;\n$Params = @{&#13;\n  'Name'                = 'LCWin2019-02'&#13;\n  'ResourceGroupName'   = 'TestLocation2'&#13;\n  'Location'            = 'centralus'&#13;\n  'VirtualNetworkName'  = 'TestVirtualNetwork2'&#13;\n  'SubnetName'          = 'VMSubnet'&#13;\n  'AddressPrefix'       = '10.1.1.0\/24'&#13;\n  'PublicIpAddressName' = 'TestVM02PublicIP'&#13;\n  'OpenPorts'           = 3389&#13;\n  'Image'               = 'MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest'&#13;\n  'Size'                = 'Standard_D2_v3'&#13;\n  'Credential'          = $VMCredential&#13;\n}&#13;\n&#13;\n$VM2 = New-AzVM @Params&#13;\n<\/code><\/pre>\n<p>Finally, we will connect the two virtual networks by using <code>Add-AzVirtualNetworkPeering<\/code>. After retrieving the virtual network configurations, we will pass that information to create our peered connection.<\/p>\n<blockquote><p><em>You may notice that we need to peer from both directions. This gives you flexibility in how you want to structure your data flow, but it is also easy to miss when setting up the peering!<\/em><\/p>\n<\/blockquote>\n<pre><code class=\"language-powershell\">$VNet1 = Get-AzVirtualNetwork -Name 'TestVirtualNetwork1' -ResourceGroupName 'TestLocation1'&#13;\n$VNet2 = Get-AzVirtualNetwork -Name 'TestVirtualNetwork2' -ResourceGroupName 'TestLocation2'&#13;\n&#13;\n$Params = @{&#13;\n    'Name'                   = 'TestVirtualNetwork1peerTestVirtualNetwork2'&#13;\n    'VirtualNetwork'         =  $VNet1&#13;\n    'RemoteVirtualNetworkId' =  $VNet2.Id&#13;\n}&#13;\n&#13;\nAdd-AzVirtualNetworkPeering @Params&#13;\n&#13;\n$Params = @{&#13;\n    'Name'                   = 'TestVirtualNetwork2peerTestVirtualNetwork1'&#13;\n    'VirtualNetwork'         =  $VNet2&#13;\n    'RemoteVirtualNetworkId' =  $VNet1.Id&#13;\n}&#13;\n&#13;\nAdd-AzVirtualNetworkPeering @Params&#13;\n<\/code><\/pre>\n<p>Using <code>Get-AzVirtualNetworkPeering<\/code> we can see that our peered networks are now available for use.<\/p>\n<figure id=\"attachment_7602\" style=\"width: 1280px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7602\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/4a5a8d31b800581704ad0ee1f745966b\/p\/uploads\/2020\/10\/c1050222.png\" alt=\"Demonstrating that the peering connection was successfully created.\" width=\"1280\" height=\"241\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Demonstrating that the peering connection was successfully created.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Demonstrating_the_Peered_Virtual_Network_Connection\"><\/span>Demonstrating the Peered Virtual Network Connection<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that everything is properly connected, we can show that the virtual machines can ping each other successfully. First, make sure that your network adapters are on a private network and that you have allowed the File and Printer Sharing (Echo Request \u2013 ICMPv4-In) firewall rule. Otherwise, even with a peered network, your ping tests will most likely fail.<\/p>\n<figure id=\"attachment_7603\" style=\"width: 1296px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7603\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/41ab273b8444e74469ec78ac1db022bf\/p\/uploads\/2020\/10\/e99b088d.png\" alt=\"Verifying firewall settings.\" width=\"1296\" height=\"576\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Verifying firewall settings.<\/figcaption><\/figure>\n<p>As you can see below, both sides of the peered virtual network connection work as expected.<\/p>\n<figure id=\"attachment_7604\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7604\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/d5e1dafd588caaf09ab739f42da1fae5\/p\/uploads\/2020\/10\/f3f1d38c.png\" alt=\"Sending ICMP pings from the first VM to the 2nd.\" width=\"848\" height=\"395\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Sending ICMP pings from the first VM to the 2nd.<\/figcaption><\/figure>\n<figure id=\"attachment_7605\" style=\"width: 755px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7605\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/855ab17a0de4d4708f99c3fd77a4bf8b\/p\/uploads\/2020\/10\/b59bc11e.png\" alt=\"Sending ICMP pings from the second VM to the 1st.\" width=\"755\" height=\"352\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\">Sending ICMP pings from the second VM to the 1st.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Connecting Azure Virtual Networks through peering enables different resources to easily communicate and share data securely. With PowerShell, this task is made easy and can be quickly incorporated into deployment scripts. Even though you may be using separate virtual networks for both policy and security reasons, you are not limited in your VM connectivity. Get started with Azure Virtual Networks today!\n<\/p><\/div>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong>\n<\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/7599\/how-to-connect-azure-virtual-networks-using-virtual-network-peering\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How To Connect Azure Virtual Networks Using Virtual Network Peering \u2013 CloudSavvy IT&#8221; Azure Virtual Network (VNet) Peering enables the connection of two or more virtual networks in Azure. Connectivity-wise the two peered networks appear as one. Peered traffic is routed through Microsoft\u2019s private network and not over the public internet. An Azure virtual network&#8230;<\/p>\n","protected":false},"author":1,"featured_media":97775,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/04\/30fdf294.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-97774","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/97774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=97774"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/97774\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/97775"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=97774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=97774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=97774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}