Skip to content

Commit e6c60db

Browse files
committed
tabs + acrolinx
1 parent f44a434 commit e6c60db

File tree

1 file changed

+149
-9
lines changed

1 file changed

+149
-9
lines changed

articles/virtual-network/ip-services/virtual-networks-static-private-ip-arm-pportal.md

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
2323
# [Azure PowerShell](#tab/azurepowershell)
2424

2525
- 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.
2930

3031
# [Azure CLI](#tab/azurecli)
3132

@@ -35,12 +36,11 @@ If you choose to install and use PowerShell locally, this article requires the A
3536
- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
3637

3738
---
39+
## Create a resource group and a virtual machine
3840

3941
# [Azure portal](#tab/azureportal)
4042

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:
4444

4545
1. Sign in to the [Azure portal](https://portal.azure.com).
4646

@@ -81,22 +81,77 @@ Use the following steps to create a VM, and its virtual network and subnet:
8181
[!INCLUDE [ephemeral-ip-note.md](~/reusable-content/ce-skilling/azure/includes/ephemeral-ip-note.md)]
8282

8383
# [Azure PowerShell](#tab/azurepowershell)
84+
85+
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+
84115
# [Azure CLI](#tab/azurecli)
85116

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:
130+
131+
```azurecli-interactive
132+
az vm create \
133+
--name myVM \
134+
--resource-group myResourceGroup \
135+
--public-ip-address myPublicIP \
136+
--public-ip-sku Standard \
137+
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
138+
--admin-username azureuser
139+
```
86140
---
87141

88142
## Change private IP address to static
143+
89144
# [Azure portal](#tab/azureportal)
90145

91-
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:
92147

93148
1. In the portal, search for and select **Virtual machines**.
94149

95150
2. In **Virtual machines**, select **myVM** from the list.
96151

97152
3. On the **myVM** page, under **Settings**, select **Networking**.
98153

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**.
100155

101156
:::image type="content" source="./media/virtual-networks-static-private-ip-arm-pportal/select-nic.png" alt-text="Screenshot of select network interface.":::
102157

@@ -119,23 +174,108 @@ In this procedure, you change the private IP address from **dynamic** to **stati
119174
>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).
120175
121176
# [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. ##
212+
$nic = Get-AzNetworkInterface -ResourceId $vm.NetworkProfile.NetworkInterfaces.Id
213+
214+
## Set interface configuration. ##
215+
$config =@{
216+
Name = 'myVM'
217+
PrivateIpAddress = '192.168.1.4'
218+
Subnet = $subnet
219+
}
220+
$nic | Set-AzNetworkInterfaceIpConfig @config -Primary
221+
222+
## Save interface configuration. ##
223+
$nic | Set-AzNetworkInterface
224+
```
225+
226+
> [!WARNING]
227+
> 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+
122231
# [Azure CLI](#tab/azurecli)
123232

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+
124250
---
125251

126252
## Clean up resources
127253
# [Azure portal](#tab/azureportal)
128254

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:
130256

131257
1. In the portal, search for and select **myResourceGroup**.
132258

133259
1. From the **myResourceGroup** screen, select **Delete resource group**.
134260

135261
1. Enter *myResourceGroup* for **Enter resource group name to confirm deletion**, and then select **Delete**.
262+
1.
136263
# [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:
266+
267+
```azurepowershell-interactive
268+
Remove-AzResourceGroup -Name myResourceGroup -Force
269+
```
270+
137271
# [Azure CLI](#tab/azurecli)
138272

273+
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:
274+
275+
```azurecli-interactive
276+
az group delete --name myResourceGroup --yes
277+
```
278+
139279
---
140280
## Next steps
141281

0 commit comments

Comments
 (0)