Skip to content

Commit afac5bb

Browse files
committed
docs: Update static private IP article with vnet/subnet creation, Linux VM with SSH keys, and no public IP
1 parent fa8c076 commit afac5bb

1 file changed

Lines changed: 106 additions & 32 deletions

File tree

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

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create a VM with a static private IP address using the Azure portal, Azure PowerShell, or Azure CLI
33
description: Learn to create a virtual machine with a static private IP address using the Azure portal, Azure PowerShell, or Azure CLI.
4-
ms.date: 11/19/2024
4+
ms.date: 02/19/2026
55
ms.author: mbender
66
author: mbender-ms
77
ms.service: azure-virtual-network
@@ -21,17 +21,53 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
2121

2222
# [Azure portal](#tab/azureportal)
2323

24-
Use the following steps to create a virtual network along with a resource group and necessary network resources:
24+
### Create a resource group
2525

2626
1. Sign in to the [Azure portal](https://portal.azure.com).
27+
28+
1. In the portal, search for and select **Resource groups**.
29+
30+
1. Select **+ Create**.
31+
32+
1. On the **Basics** tab, enter or select the following values:
33+
34+
| Setting | Value |
35+
|------------------------|---------------------------------------------------|
36+
| **Subscription** | Select your subscription |
37+
| **Resource group** | Enter *myResourceGroup* |
38+
| **Region** | Select **(US) East US** |
39+
40+
1. Select **Review + create**, and then select **Create**.
41+
42+
### Create a virtual network
43+
44+
1. In the portal, search for and select **Virtual networks**.
45+
46+
1. Select **+ Create**.
47+
48+
1. On the **Basics** tab of **Create virtual network**, enter or select the following values:
49+
50+
| Setting | Value |
51+
|------------------------|---------------------------------------------------|
52+
| **Subscription** | Select your subscription |
53+
| **Resource group** | Select **myResourceGroup** |
54+
| **Virtual network name** | Enter *myVNet* |
55+
| **Region** | Select **(US) East US** |
56+
57+
1. Select **Review + create**, and then select **Create**.
58+
59+
### Create a virtual machine
60+
2761
1. In the portal, search for and select **Virtual machines**.
62+
2863
1. Select **Create** > **Azure virtual machine**.
64+
2965
1. On the **Basics** tab of the **Create a virtual machine** screen, enter or select the following values:
3066

3167
| Setting | Value |
3268
|------------------------|---------------------------------------------------|
33-
| **Subscription** | Keep the default or select a different subscription |
34-
| **Resource group** | Select **Create new**, and then name the group *myResourceGroup* |
69+
| **Subscription** | Select your subscription |
70+
| **Resource group** | Select **myResourceGroup** |
3571
| **Virtual machine name** | Enter *myVM* |
3672
| **Region** | Select **(US) East US** |
3773
| **Availability options** | Select **No infrastructure redundancy required** |
@@ -40,82 +76,120 @@ Use the following steps to create a virtual network along with a resource group
4076
| **Username** | Enter an admin username for the VM |
4177
| **Password** | Enter a password for the VM |
4278
| **Confirm password** | Confirm the password for the VM |
43-
| **Public inbound ports** | Select **Allow selected ports** |
44-
| **Select inbound ports** | Select **RDP (3389)** |
45-
46-
> [!WARNING]
47-
> In this example, you open port 3389 to enable remote access to the Windows Server VM from the internet. However, opening port 3389 to the internet is not recommended to manage production workloads. For information about secure access to Azure VMs, see [What is Azure Bastion?](../../bastion/bastion-overview.md)
79+
| **Public inbound ports** | Select **None** |
4880

4981
1. Select the **Networking** tab at the top of the page.
50-
82+
5183
1. On the **Networking** page, enter or select the following values:
5284

53-
- **Virtual network**: Accept the default network name.
85+
- **Virtual network**: Select **myVNet**.
5486
- **Subnet**: Select **default** if not already selected.
55-
- **Public IP**: Accept the default public IP configuration.
56-
- **Public inbound ports**: Select **Allow selected ports**.
57-
- **Select inbound ports**: Select **RDP (3389)**.
87+
- **Public IP**: Select **None**.
5888

5989
1. Select **Review + create**. Review the settings, and then select **Create**.
6090

61-
[!INCLUDE [ephemeral-ip-note.md](~/reusable-content/ce-skilling/azure/includes/ephemeral-ip-note.md)]
62-
6391
# [Azure PowerShell](#tab/azurepowershell)
6492

65-
Use the following steps to create a resource group and a virtual machine.
93+
Use the following steps to create a resource group, virtual network, and virtual machine.
6694

6795
### Create a resource group
6896

6997
The following command creates a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup).
7098

7199
```azurepowershell-interactive
72100
## Create resource group. ##
73-
$rg =@{
101+
$rg = @{
74102
Name = 'myResourceGroup'
75103
Location = 'eastus2'
76104
}
77105
New-AzResourceGroup @rg
106+
```
107+
108+
### Create a virtual network and subnet
109+
110+
The following commands create a virtual network and subnet with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) and [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig).
78111

112+
```azurepowershell-interactive
113+
## Create subnet configuration. ##
114+
$subnet = @{
115+
Name = 'default'
116+
AddressPrefix = '10.0.0.0/24'
117+
}
118+
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet
119+
120+
## Create virtual network. ##
121+
$vnet = @{
122+
Name = 'myVNet'
123+
ResourceGroupName = 'myResourceGroup'
124+
Location = 'eastus2'
125+
AddressPrefix = '10.0.0.0/16'
126+
Subnet = $subnetConfig
127+
}
128+
New-AzVirtualNetwork @vnet
79129
```
130+
80131
### Create a virtual machine
81132

82-
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:
133+
The following command creates a Linux virtual machine without a public IP address with [New-AzVM](/powershell/module/az.compute/new-azvm). The `-GenerateSshKey` parameter generates an SSH key pair for the VM:
83134

84135
```azurepowershell-interactive
85136
## Create virtual machine. ##
86137
$vm = @{
87138
ResourceGroupName = 'myResourceGroup'
88139
Location = 'East US 2'
89140
Name = 'myVM'
90-
PublicIpAddressName = 'myPublicIP'
141+
Image = 'Ubuntu2204'
142+
VirtualNetworkName = 'myVNet'
143+
SubnetName = 'default'
144+
PublicIpAddressName = ''
145+
GenerateSshKey = $true
146+
SshKeyName = 'mySSHKey'
91147
}
92148
New-AzVM @vm
93149
```
94150

95151
# [Azure CLI](#tab/azurecli)
96152

97-
Use the following steps to create a resource group and a virtual machine.
153+
Use the following steps to create a resource group, virtual network, and virtual machine.
98154

99155
### Create a resource group
100156

101157
The following command creates a resource group with [az group create](/cli/azure/group#az-group-create):
102158

103-
```azurecli
104-
az group create --name myResourceGroup --location eastus2
159+
```azurecli-interactive
160+
az group create \
161+
--name myResourceGroup \
162+
--location eastus2
163+
```
164+
165+
### Create a virtual network and subnet
166+
167+
The following command creates a virtual network and subnet with [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create):
168+
169+
```azurecli-interactive
170+
az network vnet create \
171+
--name myVNet \
172+
--resource-group myResourceGroup \
173+
--location eastus2 \
174+
--address-prefixes 10.0.0.0/16 \
175+
--subnet-name default \
176+
--subnet-prefixes 10.0.0.0/24
105177
```
106178

107179
### Create a virtual machine
108180

109-
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:
181+
The following command creates a Linux virtual machine without a public IP address with [az vm create](/cli/azure/vm#az-vm-create). The `--generate-ssh-keys` parameter generates an SSH key pair for the VM:
110182

111183
```azurecli-interactive
112-
az vm create \
184+
az vm create \
113185
--name myVM \
114186
--resource-group myResourceGroup \
115-
--public-ip-address myPublicIP \
116-
--public-ip-sku Standard \
117-
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
118-
--admin-username azureuser
187+
--vnet-name myVNet \
188+
--subnet default \
189+
--image Ubuntu2204 \
190+
--public-ip-address "" \
191+
--admin-username azureuser \
192+
--generate-ssh-keys
119193
```
120194
---
121195

@@ -163,14 +237,14 @@ With the following commands, you change the private IP address of the virtual ma
163237
```azurepowershell-interactive
164238
## Place virtual network configuration into a variable. ##
165239
$net = @{
166-
Name = 'myVM'
240+
Name = 'myVNet'
167241
ResourceGroupName = 'myResourceGroup'
168242
}
169243
$vnet = Get-AzVirtualNetwork @net
170244
171245
## Place subnet configuration into a variable. ##
172246
$sub = @{
173-
Name = 'myVM'
247+
Name = 'default'
174248
VirtualNetwork = $vnet
175249
}
176250
$subnet = Get-AzVirtualNetworkSubnetConfig @sub
@@ -188,7 +262,7 @@ $nic = Get-AzNetworkInterface -ResourceId $vm.NetworkProfile.NetworkInterfaces.I
188262
## Set interface configuration. ##
189263
$config =@{
190264
Name = 'myVM'
191-
PrivateIpAddress = '192.168.1.4'
265+
PrivateIpAddress = '10.0.0.4'
192266
Subnet = $subnet
193267
}
194268
$nic | Set-AzNetworkInterfaceIpConfig @config -Primary

0 commit comments

Comments
 (0)