You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-network/tutorial-restrict-network-access-to-resources.md
+59-58Lines changed: 59 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,27 +84,27 @@ Service endpoints are enabled per service, per subnet.
84
84
85
85
## Create a virtual network
86
86
87
-
Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup). The following example creates a resource group named *myResourceGroup*:
87
+
Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup). The following example creates a resource group named *test-rg*:
Create a virtual network with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). The following example creates a virtual network named *myVirtualNetwork* with the address prefix *10.0.0.0/16*.
93
+
Create a virtual network with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). The following example creates a virtual network named *vnet-1* with the address prefix *10.0.0.0/16*.
94
94
95
95
```azurepowershell-interactive
96
96
$virtualNetwork = New-AzVirtualNetwork `
97
-
-ResourceGroupName myResourceGroup `
98
-
-Location EastUS `
99
-
-Name myVirtualNetwork `
97
+
-ResourceGroupName test-rg `
98
+
-Location westus2 `
99
+
-Name vnet-1 `
100
100
-AddressPrefix 10.0.0.0/16
101
101
```
102
102
103
-
Create a subnet configuration with [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig). The following example creates a subnet configuration for a subnet named *Public*:
103
+
Create a subnet configuration with [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig). The following example creates a subnet configuration for a subnet named *subnet-public*:
@@ -115,11 +115,11 @@ Create the subnet in the virtual network by writing the subnet configuration to
115
115
$virtualNetwork | Set-AzVirtualNetwork
116
116
```
117
117
118
-
Create an additional subnet in the virtual network. In this example, a subnet named *Private* is created with a service endpoint for *Microsoft.Storage*:
118
+
Create an additional subnet in the virtual network. In this example, a subnet named *subnet-private* is created with a service endpoint for *Microsoft.Storage*:
Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with [az group create](/cli/azure/group). The following example creates a resource group named *test-rg* in the *eastus* location.
134
+
Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with [az group create](/cli/azure/group). The following example creates a resource group named *test-rg* in the *westus2* location.
135
135
136
136
```azurecli-interactive
137
137
az group create \
138
138
--name test-rg \
139
-
--location eastus
139
+
--location westus2
140
140
```
141
141
142
142
Create a virtual network with one subnet with [az network vnet create](/cli/azure/network/vnet).
@@ -150,11 +150,11 @@ az network vnet create \
150
150
--subnet-prefix 10.0.0.0/24
151
151
```
152
152
153
-
You can enable service endpoints only for services that support service endpoints. View service endpoint-enabled services available in an Azure location with [az network vnet list-endpoint-services](/cli/azure/network/vnet). The following example returns a list of service-endpoint-enabled services available in the *eastus* region. The list of services returned will grow over time, as more Azure services become service endpoint enabled.
153
+
You can enable service endpoints only for services that support service endpoints. View service endpoint-enabled services available in an Azure location with [az network vnet list-endpoint-services](/cli/azure/network/vnet). The following example returns a list of service-endpoint-enabled services available in the *westus2* region. The list of services returned will grow over time, as more Azure services become service endpoint enabled.
154
154
155
155
```azurecli-interactive
156
156
az network vnet list-endpoint-services \
157
-
--location eastus \
157
+
--location westus2 \
158
158
--out table
159
159
```
160
160
@@ -196,13 +196,13 @@ By default, all virtual machine instances in a subnet can communicate with any r
196
196
197
197
### [PowerShell](#tab/powershell)
198
198
199
-
Create a network security group with [New-AzNetworkSecurityGroup](/powershell/module/az.network/new-aznetworksecuritygroup). The following example creates a network security group named *myNsgPrivate*.
199
+
Create a network security group with [New-AzNetworkSecurityGroup](/powershell/module/az.network/new-aznetworksecuritygroup). The following example creates a network security group named *nsg-private*.
Associate the network security group to the *Private* subnet with [Set-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/set-azvirtualnetworksubnetconfig) and then write the subnet configuration to the virtual network. The following example associates the *myNsgPrivate* network security group to the *Private* subnet:
334
+
Associate the network security group to the *subnet-private* subnet with [Set-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/set-azvirtualnetworksubnetconfig) and then write the subnet configuration to the virtual network. The following example associates the *nsg-private* network security group to the *subnet-private* subnet:
335
335
336
336
```azurepowershell-interactive
337
337
Set-AzVirtualNetworkSubnetConfig `
338
338
-VirtualNetwork $VirtualNetwork `
339
-
-Name Private `
339
+
-Name subnet-private `
340
340
-AddressPrefix 10.0.1.0/24 `
341
341
-ServiceEndpoint Microsoft.Storage `
342
342
-NetworkSecurityGroup $nsg
@@ -407,7 +407,6 @@ az network vnet subnet update \
407
407
--network-security-group nsg-private
408
408
```
409
409
410
-
411
410
---
412
411
413
412
## Restrict network access to a resource
@@ -426,9 +425,9 @@ Create an Azure storage account with [New-AzStorageAccount](/powershell/module/a
@@ -571,7 +572,7 @@ By default, storage accounts accept network connections from clients in any netw
571
572
572
573
```azurepowershell-interactive
573
574
Update-AzStorageAccountNetworkRuleSet `
574
-
-ResourceGroupName "myresourcegroup" `
575
+
-ResourceGroupName "test-rg" `
575
576
-Name $storageAcctName `
576
577
-DefaultAction Deny
577
578
```
@@ -580,17 +581,17 @@ Retrieve the created virtual network with [Get-AzVirtualNetwork](/powershell/mod
580
581
581
582
```azurepowershell-interactive
582
583
$privateSubnet = Get-AzVirtualNetwork `
583
-
-ResourceGroupName "myResourceGroup" `
584
-
-Name "myVirtualNetwork" `
584
+
-ResourceGroupName "test-rg" `
585
+
-Name "vnet-1" `
585
586
| Get-AzVirtualNetworkSubnetConfig `
586
-
-Name "Private"
587
+
-Name "subnet-private"
587
588
```
588
589
589
-
Allow network access to the storage account from the *Private* subnet with [Add-AzStorageAccountNetworkRule](/powershell/module/az.network/add-aznetworksecurityruleconfig).
590
+
Allow network access to the storage account from the *subnet-private* subnet with [Add-AzStorageAccountNetworkRule](/powershell/module/az.network/add-aznetworksecurityruleconfig).
590
591
591
592
```azurepowershell-interactive
592
593
Add-AzStorageAccountNetworkRule `
593
-
-ResourceGroupName "myresourcegroup" `
594
+
-ResourceGroupName "test-rg" `
594
595
-Name $storageAcctName `
595
596
-VirtualNetworkResourceId $privateSubnet.Id
596
597
```
@@ -644,15 +645,15 @@ To test network access to a storage account, deploy a virtual machine to each su
644
645
645
646
### Create the first virtual machine
646
647
647
-
Create a virtual machine in the *Public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). When running the command that follows, you are prompted for credentials. The values that you enter are configured as the user name and password for the VM. The `-AsJob` option creates the VM in the background, so that you can continue to the next step.
648
+
Create a virtual machine in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). When running the command that follows, you are prompted for credentials. The values that you enter are configured as the user name and password for the VM. The `-AsJob` option creates the VM in the background, so that you can continue to the next step.
648
649
649
650
```azurepowershell-interactive
650
651
New-AzVm `
651
-
-ResourceGroupName "myResourceGroup" `
652
-
-Location "East US" `
653
-
-VirtualNetworkName "myVirtualNetwork" `
654
-
-SubnetName "Public" `
655
-
-Name "myVmPublic" `
652
+
-ResourceGroupName "test-rg" `
653
+
-Location "WestUS2" `
654
+
-VirtualNetworkName "vnet-1" `
655
+
-SubnetName "subnet-public" `
656
+
-Name "vm-public" `
656
657
-AsJob
657
658
```
658
659
@@ -666,15 +667,15 @@ Id Name PSJobTypeName State HasMoreData Location
666
667
667
668
### Create the second virtual machine
668
669
669
-
Create a virtual machine in the *Private* subnet:
670
+
Create a virtual machine in the *subnet-private* subnet:
670
671
671
672
```azurepowershell-interactive
672
673
New-AzVm `
673
-
-ResourceGroupName "myResourceGroup" `
674
+
-ResourceGroupName "test-rg" `
674
675
-Location "East US" `
675
-
-VirtualNetworkName "myVirtualNetwork" `
676
-
-SubnetName "Private" `
677
-
-Name "myVmPrivate"
676
+
-VirtualNetworkName "vnet-1" `
677
+
-SubnetName "subnet-private" `
678
+
-Name "vm-private" `
678
679
```
679
680
680
681
It takes a few minutes for Azure to create the VM. Do not continue to the next step until Azure finishes creating the VM and returns output to PowerShell.
@@ -704,7 +705,7 @@ The VM takes a few minutes to create. After the VM is created, the Azure CLI sho
@@ -796,12 +797,12 @@ The virtual machine you created earlier that is assigned to the **subnet-private
796
797
797
798
### [PowerShell](#tab/powershell)
798
799
799
-
Use [Get-AzPublicIpAddress](/powershell/module/az.network/get-azpublicipaddress) to return the public IP address of a VM. The following example returns the public IP address of the *myVmPrivate* VM:
800
+
Use [Get-AzPublicIpAddress](/powershell/module/az.network/get-azpublicipaddress) to return the public IP address of a VM. The following example returns the public IP address of the *vm-private" `* VM:
800
801
801
802
```azurepowershell-interactive
802
803
Get-AzPublicIpAddress `
803
-
-Name myVmPrivate `
804
-
-ResourceGroupName myResourceGroup `
804
+
-Name vm-private" ` `
805
+
-ResourceGroupName test-rg `
805
806
| Select IpAddress
806
807
```
807
808
@@ -813,7 +814,7 @@ mstsc /v:<publicIpAddress>
813
814
814
815
A Remote Desktop Protocol (.rdp) file is created and downloaded to your computer. Open the downloaded rdp file. If prompted, select **Connect**. Enter the user name and password you specified when creating the VM. You may need to select **More choices**, then **Use a different account**, to specify the credentials you entered when you created the VM. Select **OK**. You may receive a certificate warning during the sign-in process. If you receive the warning, select **Yes** or **Continue**, to proceed with the connection.
815
816
816
-
On the *myVmPrivate* VM, map the Azure file share to drive Z using PowerShell. Before running the commands that follow, replace `<storage-account-key>` and `<storage-account-name>` with values from you supplied or retrieved in [Create a storage account](#create-a-storage-account).
817
+
On the *vm-private" `* VM, map the Azure file share to drive Z using PowerShell. Before running the commands that follow, replace `<storage-account-key>` and `<storage-account-name>` with values from you supplied or retrieved in [Create a storage account](#create-a-storage-account).
You receive no replies, because the network security group associated to the *Private* subnet does not allow outbound access to public IP addresses other than the addresses assigned to the Azure Storage service.
841
842
842
-
Close the remote desktop session to the *myVmPrivate* VM.
843
+
Close the remote desktop session to the *vm-private" `* VM.
843
844
844
845
### [CLI](#tab/cli)
845
846
@@ -951,12 +952,12 @@ Exit the SSH session to the *vm-private* VM.
951
952
952
953
### [PowerShell](#tab/powershell)
953
954
954
-
Get the public IP address of the *myVmPublic* VM:
955
+
Get the public IP address of the *vm-public* VM:
955
956
956
957
```azurepowershell-interactive
957
958
Get-AzPublicIpAddress `
958
-
-Name myVmPublic `
959
-
-ResourceGroupName myResourceGroup `
959
+
-Name vm-public `
960
+
-ResourceGroupName test-rg `
960
961
| Select IpAddress
961
962
```
962
963
@@ -966,27 +967,27 @@ Replace `<publicIpAddress>` in the following command, with the public IP address
966
967
mstsc /v:<publicIpAddress>
967
968
```
968
969
969
-
On the *myVmPublic* VM, attempt to map the Azure file share to drive Z. Before running the commands that follow, replace `<storage-account-key>` and `<storage-account-name>` with values from you supplied or retrieved in [Create a storage account](#create-a-storage-account).
970
+
On the *vm-public* VM, attempt to map the Azure file share to drive Z. Before running the commands that follow, replace `<storage-account-key>` and `<storage-account-name>` with values from you supplied or retrieved in [Create a storage account](#create-a-storage-account).
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\<storage-account-name>.file.core.windows.net\my-file-share" -Credential $credential
975
+
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\<storage-account-name>.file.core.windows.net\file-share" -Credential $credential
975
976
```
976
977
977
-
Access to the share is denied, and you receive a `New-PSDrive : Access is denied` error. Access is denied because the *myVmPublic* VM is deployed in the *Public* subnet. The *Public* subnet does not have a service endpoint enabled for Azure Storage, and the storage account only allows network access from the *Private* subnet, not the *Public* subnet.
978
+
Access to the share is denied, and you receive a `New-PSDrive : Access is denied` error. Access is denied because the *vm-public* VM is deployed in the *subnet-public* subnet. The *subnet-public* subnet does not have a service endpoint enabled for Azure Storage, and the storage account only allows network access from the *subnet-private* subnet, not the *subnet-public* subnet.
978
979
979
-
Close the remote desktop session to the *myVmPublic* VM.
980
+
Close the remote desktop session to the *vm-public* VM.
980
981
981
982
From your computer, attempt to view the file shares in the storage account with the following command:
982
983
983
984
```powershell-interactive
984
985
Get-AzStorageFile `
985
-
-ShareName my-file-share `
986
+
-ShareName file-share `
986
987
-Context $storageContext
987
988
```
988
989
989
-
Access is denied, and you receive a *Get-AzStorageFile : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is not authorized to perform this operation* error, because your computer is not in the *Private* subnet of the *MyVirtualNetwork* virtual network.
990
+
Access is denied, and you receive a *Get-AzStorageFile : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is not authorized to perform this operation* error, because your computer is not in the *subnet-private* subnet of the *vnet-1* virtual network.
990
991
991
992
### [CLI](#tab/cli)
992
993
@@ -1039,7 +1040,7 @@ Access is denied and you receive a **This request isn't authorized to perform th
1039
1040
When no longer needed, you can use [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) to remove the resource group and all of the resources it contains:
0 commit comments