Skip to content

Commit 1cc3643

Browse files
authored
Merge pull request #312037 from asudbring/tsk544800-sfi-ssh
Update static private IP article - SSH, Linux VM, no public IP
2 parents 46cd3ce + bbf3e94 commit 1cc3643

1 file changed

Lines changed: 120 additions & 37 deletions

File tree

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

Lines changed: 120 additions & 37 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,101 +21,184 @@ 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* |
36-
| **Region** | Select **(US) East US** |
72+
| **Region** | Select **(US) East US 2** |
3773
| **Availability options** | Select **No infrastructure redundancy required** |
38-
| **Image** | Select **Windows Server 2019 Datacenter - x64 Gen2** |
74+
| **Security type** | Select **Standard** |
75+
| **Image** | Select **Ubuntu Server 22.04 LTS - x64 Gen2** |
3976
| **Size** | Accept the default, or drop down and select a size |
40-
| **Username** | Enter an admin username for the VM |
41-
| **Password** | Enter a password for the VM |
42-
| **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)
77+
| **Authentication type** | Select **SSH public key** |
78+
| **Username** | Enter *azureuser* |
79+
| **SSH public key source** | Select **Generate new key pair** |
80+
| **Key pair name** | Enter *mySSHKey* |
81+
| **Public inbound ports** | Select **None** |
4882

4983
1. Select the **Networking** tab at the top of the page.
50-
84+
5185
1. On the **Networking** page, enter or select the following values:
5286

53-
- **Virtual network**: Accept the default network name.
87+
- **Virtual network**: Select **myVNet**.
5488
- **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)**.
89+
- **Public IP**: Select **None**.
5890

5991
1. Select **Review + create**. Review the settings, and then select **Create**.
6092

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

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

6797
### Create a resource group
6898

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

71101
```azurepowershell-interactive
72102
## Create resource group. ##
73-
$rg =@{
103+
$rg = @{
74104
Name = 'myResourceGroup'
75105
Location = 'eastus2'
76106
}
77107
New-AzResourceGroup @rg
108+
```
109+
110+
### Create a virtual network and subnet
78111

112+
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).
113+
114+
```azurepowershell-interactive
115+
## Create subnet configuration. ##
116+
$subnet = @{
117+
Name = 'default'
118+
AddressPrefix = '10.0.0.0/24'
119+
}
120+
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet
121+
122+
## Create virtual network. ##
123+
$vnet = @{
124+
Name = 'myVNet'
125+
ResourceGroupName = 'myResourceGroup'
126+
Location = 'eastus2'
127+
AddressPrefix = '10.0.0.0/16'
128+
Subnet = $subnetConfig
129+
}
130+
New-AzVirtualNetwork @vnet
79131
```
132+
80133
### Create a virtual machine
81134

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:
135+
Create a credential object for the virtual machine with [Get-Credential](/powershell/module/microsoft.powershell.security/get-credential). Enter a username and password when prompted:
136+
137+
```azurepowershell-interactive
138+
$cred = Get-Credential
139+
```
140+
141+
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:
83142

84143
```azurepowershell-interactive
85144
## Create virtual machine. ##
86145
$vm = @{
87146
ResourceGroupName = 'myResourceGroup'
88147
Location = 'East US 2'
89148
Name = 'myVM'
90-
PublicIpAddressName = 'myPublicIP'
149+
Image = 'Ubuntu2204'
150+
Credential = $cred
151+
VirtualNetworkName = 'myVNet'
152+
SubnetName = 'default'
153+
PublicIpAddressName = ''
154+
GenerateSshKey = $true
155+
SshKeyName = 'mySSHKey'
91156
}
92157
New-AzVM @vm
93158
```
94159

95160
# [Azure CLI](#tab/azurecli)
96161

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

99164
### Create a resource group
100165

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

103-
```azurecli
104-
az group create --name myResourceGroup --location eastus2
168+
```azurecli-interactive
169+
az group create \
170+
--name myResourceGroup \
171+
--location eastus2
172+
```
173+
174+
### Create a virtual network and subnet
175+
176+
The following command creates a virtual network and subnet with [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create):
177+
178+
```azurecli-interactive
179+
az network vnet create \
180+
--name myVNet \
181+
--resource-group myResourceGroup \
182+
--location eastus2 \
183+
--address-prefixes 10.0.0.0/16 \
184+
--subnet-name default \
185+
--subnet-prefixes 10.0.0.0/24
105186
```
106187

107188
### Create a virtual machine
108189

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:
190+
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:
110191

111192
```azurecli-interactive
112-
az vm create \
193+
az vm create \
113194
--name myVM \
114195
--resource-group myResourceGroup \
115-
--public-ip-address myPublicIP \
116-
--public-ip-sku Standard \
117-
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
118-
--admin-username azureuser
196+
--vnet-name myVNet \
197+
--subnet default \
198+
--image Ubuntu2204 \
199+
--public-ip-address "" \
200+
--admin-username azureuser \
201+
--generate-ssh-keys
119202
```
120203
---
121204

@@ -163,14 +246,14 @@ With the following commands, you change the private IP address of the virtual ma
163246
```azurepowershell-interactive
164247
## Place virtual network configuration into a variable. ##
165248
$net = @{
166-
Name = 'myVM'
249+
Name = 'myVNet'
167250
ResourceGroupName = 'myResourceGroup'
168251
}
169252
$vnet = Get-AzVirtualNetwork @net
170253
171254
## Place subnet configuration into a variable. ##
172255
$sub = @{
173-
Name = 'myVM'
256+
Name = 'default'
174257
VirtualNetwork = $vnet
175258
}
176259
$subnet = Get-AzVirtualNetworkSubnetConfig @sub
@@ -188,7 +271,7 @@ $nic = Get-AzNetworkInterface -ResourceId $vm.NetworkProfile.NetworkInterfaces.I
188271
## Set interface configuration. ##
189272
$config =@{
190273
Name = 'myVM'
191-
PrivateIpAddress = '192.168.1.4'
274+
PrivateIpAddress = '10.0.0.4'
192275
Subnet = $subnet
193276
}
194277
$nic | Set-AzNetworkInterfaceIpConfig @config -Primary

0 commit comments

Comments
 (0)