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/ip-services/virtual-networks-static-private-ip-arm-pportal.md
+149-9Lines changed: 149 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,9 +23,10 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
23
23
# [Azure PowerShell](#tab/azurepowershell)
24
24
25
25
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
26
-
- Azure PowerShell installed locally or Azure Cloud Shell
27
-
28
-
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run `Get-Module -ListAvailable Az` to find the installed version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
26
+
- Azure PowerShell installed locally or Azure Cloud Shell.
27
+
- If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later.
28
+
- Run `Get-Module -ListAvailable Az` to find the installed version.
29
+
- If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
29
30
30
31
# [Azure CLI](#tab/azurecli)
31
32
@@ -35,12 +36,11 @@ If you choose to install and use PowerShell locally, this article requires the A
35
36
- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
36
37
37
38
---
39
+
## Create a resource group and a virtual machine
38
40
39
41
# [Azure portal](#tab/azureportal)
40
42
41
-
## Create a VM
42
-
43
-
Use the following steps to create a VM, and its virtual network and subnet:
43
+
Use the following steps to create a virtual network along with a resource group and necessary network resources:
44
44
45
45
1. Sign in to the [Azure portal](https://portal.azure.com).
46
46
@@ -81,22 +81,77 @@ Use the following steps to create a VM, and its virtual network and subnet:
Use the following steps to create a resource group and a virtual machine.
86
+
87
+
### Create a resource group
88
+
89
+
The following command creates a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup).
90
+
91
+
```azurepowershell-interactive
92
+
## Create resource group. ##
93
+
$rg =@{
94
+
Name = 'myResourceGroup'
95
+
Location = 'eastus2'
96
+
}
97
+
New-AzResourceGroup @rg
98
+
99
+
```
100
+
### Create a virtual machine
101
+
102
+
The following command creates a Windows Server virtual machine with [New-AzVM](/powershell/module/az.compute/new-azvm). When prompted, provide a username and password to be used as the credentials for the virtual machine:
103
+
104
+
```azurepowershell-interactive
105
+
## Create virtual machine. ##
106
+
$vm = @{
107
+
ResourceGroupName = 'myResourceGroup'
108
+
Location = 'East US 2'
109
+
Name = 'myVM'
110
+
PublicIpAddressName = 'myPublicIP'
111
+
}
112
+
New-AzVM @vm
113
+
```
114
+
84
115
# [Azure CLI](#tab/azurecli)
85
116
117
+
Use the following steps to create a resource group and a virtual machine.
118
+
119
+
### Create a resource group
120
+
121
+
The following command creates a resource group with [az group create](/cli/azure/group#az-group-create):
122
+
123
+
```azurecli
124
+
az group create --name myResourceGroup --location eastus2
125
+
```
126
+
127
+
### Create a virtual machine
128
+
129
+
The following command creates a Windows Server virtual machine with [az vm create](/cli/azure/vm#az-vm-create). When prompted, provide a username and password to be used as the credentials for the virtual machine:
In this procedure, you change the private IP address from **dynamic** to **static** for the VM you created previously:
146
+
In the following steps, you change the private IP address **static** for the VM created previously:
92
147
93
148
1. In the portal, search for and select **Virtual machines**.
94
149
95
150
2. In **Virtual machines**, select **myVM** from the list.
96
151
97
152
3. On the **myVM** page, under **Settings**, select **Networking**.
98
153
99
-
4. In **Networking**, select the name of the network interface next to **Network interface**. In this example, the name of the NIC is **myvm472**.
154
+
4. In **Networking**, select the name of the network interface next to **Network interface**. In this example, the name of the network interface is **myvm472**.
100
155
101
156
:::image type="content" source="./media/virtual-networks-static-private-ip-arm-pportal/select-nic.png" alt-text="Screenshot of select network interface.":::
102
157
@@ -119,23 +174,108 @@ In this procedure, you change the private IP address from **dynamic** to **stati
119
174
>If you manually set the private IP address within the operating system, make sure it matches the private IP address assigned to the Azure [network interface](virtual-network-network-interface-addresses.md#change-ip-address-settings). Otherwise, you can lose connectivity to the VM. For more information, see [private IP address settings](virtual-network-network-interface-addresses.md#private).
120
175
121
176
# [Azure PowerShell](#tab/azurepowershell)
177
+
178
+
Azure PowerShell cmdlets used to change the private IP address to static are as follows:
179
+
| Command | Description |
180
+
|---------|-------------|
181
+
|`Get-AzVirtualNetwork`| Use [Get-AzVirtualNetwork](/powershell/module/az.network/get-azvirtualnetwork) to place the virtual network configuration into a variable. |
182
+
|`Get-AzVirtualNetworkSubnetConfig`| Use [Get-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/get-azvirtualnetworksubnetconfig) to place the subnet configuration into a variable. |
183
+
|`Get-AzNetworkInterface`| Use [Get-AzNetworkInterface](/powershell/module/az.network/get-aznetworkinterface) to obtain the network interface configuration and place into a variable. |
184
+
|`Set-AzNetworkInterfaceIpConfig`| Use [Set-AzNetworkInterfaceIpConfig](/powershell/module/az.network/set-aznetworkinterfaceipconfig) to set the configuration of the network interface. |
185
+
|`Set-AzNetworkInterface`| Finally, use [Set-AzNetworkInterface](/powershell/module/az.network/set-aznetworkinterface) to set the configuration for the virtual machine. |
186
+
187
+
With the following commands, you change the private IP address of the virtual machine to **static**:
188
+
189
+
```azurepowershell-interactive
190
+
## Place virtual network configuration into a variable. ##
191
+
$net = @{
192
+
Name = 'myVM'
193
+
ResourceGroupName = 'myResourceGroup'
194
+
}
195
+
$vnet = Get-AzVirtualNetwork @net
196
+
197
+
## Place subnet configuration into a variable. ##
198
+
$sub = @{
199
+
Name = 'myVM'
200
+
VirtualNetwork = $vnet
201
+
}
202
+
$subnet = Get-AzVirtualNetworkSubnetConfig @sub
203
+
204
+
## Get name of network interface and place into a variable ##
205
+
$int1 = @{
206
+
Name = 'myVM'
207
+
ResourceGroupName = 'myResourceGroup'
208
+
}
209
+
$vm = Get-AzVM @int1
210
+
211
+
## Place network interface configuration into a variable. ##
> From within the operating system of a VM, you shouldn't statically assign the *private* IP that's assigned to the Azure VM. Only do static assignment of a private IP when it's necessary, such as when [assigning many IP addresses to VMs](virtual-network-multiple-ip-addresses-portal.md).
228
+
>
229
+
>If you manually set the private IP address within the operating system, make sure it matches the private IP address assigned to the Azure [network interface](virtual-network-network-interface-addresses.md#change-ip-address-settings). Otherwise, you can lose connectivity to the VM. Learn more about [private IP address](virtual-network-network-interface-addresses.md#private) settings.
230
+
122
231
# [Azure CLI](#tab/azurecli)
123
232
233
+
Use [az network nic ip-config update](/cli/azure/network/nic/ip-config#az-network-nic-ip-config-update) to update the network interface configuration.
234
+
235
+
With the following commands, you change the private IP address of the virtual machine to **static**:
236
+
237
+
```azurecli-interactive
238
+
az network nic ip-config update \
239
+
--name ipconfigmyVM \
240
+
--resource-group myResourceGroup \
241
+
--nic-name myVMVMNic \
242
+
--private-ip-address 10.0.0.4
243
+
```
244
+
245
+
> [!WARNING]
246
+
> From within the operating system of a VM, you shouldn't statically assign the *private* IP that's assigned to the Azure VM. Only do static assignment of a private IP when it's necessary, such as when [assigning many IP addresses to VMs](virtual-network-multiple-ip-addresses-portal.md).
247
+
>
248
+
>If you manually set the private IP address within the operating system, make sure it matches the private IP address assigned to the Azure [network interface](virtual-network-network-interface-addresses.md#change-ip-address-settings). Otherwise, you can lose connectivity to the VM. Learn more about [private IP address](virtual-network-network-interface-addresses.md#private) settings.
249
+
124
250
---
125
251
126
252
## Clean up resources
127
253
# [Azure portal](#tab/azureportal)
128
254
129
-
When you're finished, delete the resource group and all of the resources it contains:
255
+
When all the resources are no longer need, delete the resource group and all of the resources it contains:
130
256
131
257
1. In the portal, search for and select **myResourceGroup**.
132
258
133
259
1. From the **myResourceGroup** screen, select **Delete resource group**.
134
260
135
261
1. Enter *myResourceGroup* for **Enter resource group name to confirm deletion**, and then select **Delete**.
262
+
1.
136
263
# [Azure PowerShell](#tab/azurepowershell)
264
+
265
+
When all the resources are no longer need, use [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) to remove the resource group and all of the resources it contains:
When all the resources are no longer need, use [az group delete](/cli/azure/group#az-group-delete) to remove the resource group and all of the resources it contains:
0 commit comments