Skip to content

Commit 6a2b274

Browse files
Merge pull request #298335 from asudbring/us417294-vnet-top-freshness
Updated command blocks and freshness review for manage subnet article
2 parents 85bdd4f + 5836b50 commit 6a2b274

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

articles/virtual-network/virtual-network-manage-subnet.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.custom:
1010
- devx-track-azurecli
1111
- devx-track-azurepowershell
1212
- ignite-2023
13-
ms.date: 11/15/2023
13+
ms.date: 04/15/2025
1414
ms.author: allensu
1515
---
1616

@@ -23,17 +23,20 @@ All Azure resources in a virtual network are deployed into subnets within the vi
2323
# [Portal](#tab/azure-portal)
2424

2525
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
26+
2627
- An existing Azure virtual network. To create one, see [Quickstart: Create a virtual network by using the Azure portal](quick-create-portal.md).
28+
2729
- To run the procedures, sign in to the [Azure portal](https://portal.azure.com) with your Azure account.
2830

2931
# [Azure CLI](#tab/azure-cli)
3032

3133
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
34+
3235
- An existing Azure virtual network. To create one, see [Quickstart: Create a virtual network by using Azure CLI](quick-create-cli.md).
3336

3437
You can run the commands either in the [Azure Cloud Shell](/azure/cloud-shell/overview) or from Azure CLI on your computer.
3538

36-
- Azure Cloud Shell is a free interactive shell that has common Azure tools preinstalled and configured to use with your account. To run the commands in the Cloud Shell, select **Open Cloudshell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
39+
- Azure Cloud Shell is a free interactive shell that has common Azure tools preinstalled and configured to use with your account. To run the commands in the Cloud Shell, select **Open Cloud shell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
3740

3841
- If you [install Azure CLI locally](/cli/azure/install-azure-cli) to run the commands, you need Azure CLI version 2.31.0 or later. Run [az version](/cli/azure/reference-index?#az-version) to find your installed version, and run [az upgrade](/cli/azure/reference-index?#az-upgrade) to upgrade.
3942

@@ -42,11 +45,12 @@ You can run the commands either in the [Azure Cloud Shell](/azure/cloud-shell/ov
4245
# [PowerShell](#tab/azure-powershell)
4346

4447
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
48+
4549
- An existing Azure virtual network. To create one, see [Quickstart: Create a virtual network by using Azure PowerShell](quick-create-powershell.md).
4650

4751
You can run the commands either in the [Azure Cloud Shell](/azure/cloud-shell/overview) or from PowerShell on your computer.
4852

49-
- Azure Cloud Shell is a free interactive shell that has common Azure tools preinstalled and configured to use with your account. To run the commands in the Cloud Shell, select **Open Cloudshell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
53+
- Azure Cloud Shell is a free interactive shell that has common Azure tools preinstalled and configured to use with your account. To run the commands in the Cloud Shell, select **Open Cloud shell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
5054

5155
- If you [install Azure PowerShell locally](/powershell/azure/install-azure-powershell) to run the commands, you need Azure PowerShell module version 5.4.1 or later. Run `Get-Module -ListAvailable Az` to find your installed version. If you need to upgrade, see [Update the Azure PowerShell module](/powershell/azure/install-Az-ps#update-the-azure-powershell-module).
5256

@@ -59,7 +63,7 @@ You can run the commands either in the [Azure Cloud Shell](/azure/cloud-shell/ov
5963

6064
### Permissions
6165

62-
To do tasks on subnets, your account must be assigned to the [Network contributor role](../role-based-access-control/built-in-roles.md?toc=%2fazure%2fvirtual-network%2ftoc.json#network-contributor) or to a [custom role](../role-based-access-control/custom-roles.md?toc=%2fazure%2fvirtual-network%2ftoc.json) that's assigned the appropriate actions in the following list:
66+
To do tasks on subnets, your account must be assigned to the [Network contributor role](../role-based-access-control/built-in-roles.md?toc=%2fazure%2fvirtual-network%2ftoc.json#network-contributor) or to a [custom role](../role-based-access-control/custom-roles.md?toc=%2fazure%2fvirtual-network%2ftoc.json) assigned the appropriate actions in the following list:
6367

6468
|Action | Name |
6569
|----------------------------------------------------------------------- | ----------------------------------------- |
@@ -75,34 +79,47 @@ To do tasks on subnets, your account must be assigned to the [Network contributo
7579
# [Portal](#tab/azure-portal)
7680

7781
1. In the [Azure portal](https://portal.azure.com), search for and select *virtual networks*.
82+
7883
1. On the **Virtual networks** page, select the virtual network you want to add a subnet to.
84+
7985
1. On the virtual network page, select **Subnets** from the left navigation.
86+
8087
1. On the **Subnets** page, select **+ Subnet**.
88+
8189
1. On the **Add subnet** screen, enter or select values for the subnet settings.
90+
8291
1. Select **Save**.
8392

8493
# [Azure CLI](#tab/azure-cli)
8594

8695
Run the [az network vnet subnet create](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-create) command with the options you want to configure.
8796

8897
```azurecli-interactive
89-
az network vnet subnet create --name <subnetName> --resource-group <resourceGroupName> --vnet-name <virtualNetworkName>
98+
az network vnet subnet create \
99+
--name <subnetName> \
100+
--resource-group <resourceGroupName> \
101+
--vnet-name <virtualNetworkName>
90102
```
91103

92104
# [PowerShell](#tab/azure-powershell)
93105

94106
1. Use the [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig) command to configure the subnet.
95107

96-
```azurepowershell-interactive
97-
$vnet = Get-AzVirtualNetwork -Name <virtualNetworkName> -ResourceGroupName <resourceGroupName>
98-
Add-AzVirtualNetworkSubnetConfig -Name <subnetName> -VirtualNetwork $vnet -AddressPrefix <String[]>
99-
```
108+
```azurepowershell-interactive
109+
$vnet = Get-AzVirtualNetwork @vnetParams
110+
$subnetParams = @{
111+
Name = "<subnetName>"
112+
VirtualNetwork = $vnet
113+
AddressPrefix = "<String[]>"
114+
}
115+
Add-AzVirtualNetworkSubnetConfig @subnetParams
116+
```
100117
101118
1. Then associate the subnet configuration to the virtual network with [Set-AzVirtualNetwork](/powershell/module/az.network/Set-azVirtualNetwork).
102119
103-
```azurepowershell-interactive
104-
Set-AzVirtualNetwork -VirtualNetwork $vnet
105-
```
120+
```azurepowershell-interactive
121+
Set-AzVirtualNetwork -VirtualNetwork $vnet
122+
```
106123
107124
---
108125
@@ -151,7 +168,7 @@ You can change the following subnet settings after the subnet is created:
151168
| --- | --- |
152169
| **Subnet address range** | If no resources are deployed within the subnet, you can change the address range. If any resources exist in the subnet, you must first either move the resources to another subnet or delete them from the subnet. The steps you take to move or delete a resource vary depending on the resource. To learn how to move or delete resources that are in subnets, read the documentation for each resource type.|
153170
| **Add IPv6 address space**, **NAT gateway**, **Network security group**, and **Route table** | You can add IPv6, NAT gateway, NSG, or route table support after you create the subnet.|
154-
| **Service endpoints** | To enable a service endpoint for an existing subnet, ensure that no critical tasks are running on any resource in the subnet. Service endpoints switch routes on every network interface in the subnet. The service endpoints change from using the default route with the `0.0.0.0/0` address prefix and next hop type of `Internet` to using a new route with the address prefix of the service and a next hop type of `VirtualNetworkServiceEndpoint`.<br><br>During the switch, any open TCP connections may be terminated. The service endpoint isn't enabled until traffic to the service for all network interfaces updates with the new route. For more information, see [Virtual network traffic routing](virtual-networks-udr-overview.md).|
171+
| **Service endpoints** | To enable a service endpoint for an existing subnet, ensure that no critical tasks are running on any resource in the subnet. Service endpoints switch routes on every network interface in the subnet. The service endpoints change from using the default route with the `0.0.0.0/0` address prefix and next hop type of `Internet` to using a new route with the address prefix of the service and a next hop type of `VirtualNetworkServiceEndpoint`.<br><br>During the switch, any open TCP connections might be terminated. The service endpoint isn't enabled until traffic to the service for all network interfaces updates with the new route. For more information, see [Virtual network traffic routing](virtual-networks-udr-overview.md).|
155172
| **Subnet delegation** | You can modify subnet delegation to enable zero or multiple delegations. If a resource for a service is already deployed in the subnet, you can't add or remove subnet delegations until you remove all the resources for the service. To delegate for a different service in the portal, select the service you want to delegate to from the popup list. |
156173
| **Network policy for private endpoints**| You can change private endpoint network policy after subnet creation.|
157174

@@ -162,25 +179,36 @@ You can change the following subnet settings after the subnet is created:
162179
You can delete a subnet only if there are no resources in the subnet. If resources are in the subnet, you must delete those resources before you can delete the subnet. The steps you take to delete a resource vary depending on the resource. To learn how to delete the resources, see the documentation for each resource type.
163180

164181
1. In the [Azure portal](https://portal.azure.com), search for and select *virtual networks*.
182+
165183
1. On the **Virtual networks** page, select the virtual network you want to delete a subnet from.
184+
166185
1. On the virtual network's page, select **Subnets** from the left navigation.
186+
167187
1. On the **Subnets** page, select the subnet you want to delete.
188+
168189
1. Select **Delete**, and then select **Yes** in the confirmation dialog box.
169190

170191
# [Azure CLI](#tab/azure-cli)
171192

172193
Run the [az network vnet subnet delete](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-delete) command.
173194

174195
```azurecli-interactive
175-
az network vnet subnet delete --name <subnetName> --resource-group <resourceGroupName> --vnet-name <virtualNetworkName>
196+
az network vnet subnet delete \
197+
--name <subnetName> \
198+
--resource-group <resourceGroupName> \
199+
--vnet-name <virtualNetworkName>
176200
```
177201

178202
# [PowerShell](#tab/azure-powershell)
179203

180204
Run the [Remove-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/remove-azvirtualnetworksubnetconfig?toc=%2fazure%2fvirtual-network%2ftoc.json) command and then set the configuration.
181205

182206
```azurepowershell-interactive
183-
Remove-AzVirtualNetworkSubnetConfig -Name <subnetName> -VirtualNetwork $vnet | Set-AzVirtualNetwork
207+
$subnetParams = @{
208+
Name = "<subnetName>"
209+
VirtualNetwork = $vnet
210+
}
211+
Remove-AzVirtualNetworkSubnetConfig @subnetParams | Set-AzVirtualNetwork
184212
```
185213

186214
---

0 commit comments

Comments
 (0)