Skip to content

Commit 0785638

Browse files
committed
Add NSG creation to PowerShell and CLI tabs for virtual-networks-static-private-ip
1 parent ce07a01 commit 0785638

1 file changed

Lines changed: 91 additions & 41 deletions

File tree

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

Lines changed: 91 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
2121

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

24-
## Create a resource group
24+
### Create a resource group
2525

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

@@ -35,11 +35,28 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
3535
|------------------------|---------------------------------------------------|
3636
| **Subscription** | Select your subscription |
3737
| **Resource group** | Enter *myResourceGroup* |
38-
| **Region** | Select **(US) East US 2** |
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** |
3956

4057
1. Select **Review + create**, and then select **Create**.
4158

42-
## Create a virtual machine
59+
### Create a virtual machine
4360

4461
1. In the portal, search for and select **Virtual machines**.
4562

@@ -55,31 +72,29 @@ When you create a virtual machine (VM), it's automatically assigned a private IP
5572
| **Region** | Select **(US) East US 2** |
5673
| **Availability options** | Select **No infrastructure redundancy required** |
5774
| **Security type** | Select **Standard** |
58-
| **Image** | Select **Windows Server 2022 Datacenter: Azure Edition - x64 Gen2** |
75+
| **Image** | Select **Ubuntu Server 22.04 LTS - x64 Gen2** |
5976
| **Size** | Accept the default, or drop down and select a size |
60-
| **Username** | Enter an admin username for the VM |
61-
| **Password** | Enter a password for the VM |
62-
| **Confirm password** | Confirm the password for the VM |
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* |
6381
| **Public inbound ports** | Select **None** |
6482

65-
> [!NOTE]
66-
> All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see [Quickstart: Deploy Azure Bastion from the Azure portal](../../bastion/quickstart-host-portal.md).
67-
6883
1. Select the **Networking** tab at the top of the page.
6984

7085
1. On the **Networking** page, enter or select the following values:
7186

72-
- **Virtual network**: Accept the default network name.
87+
- **Virtual network**: Select **myVNet**.
7388
- **Subnet**: Select **default** if not already selected.
7489
- **Public IP**: Select **None**.
7590

7691
1. Select **Review + create**. Review the settings, and then select **Create**.
7792

7893
# [Azure PowerShell](#tab/azurepowershell)
7994

80-
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.
8196

82-
## Create a resource group
97+
### Create a resource group
8398

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

@@ -92,7 +107,30 @@ $rg = @{
92107
New-AzResourceGroup @rg
93108
```
94109

95-
## Create a network security group
110+
### Create a virtual network and subnet
111+
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
131+
```
132+
133+
### Create a network security group
96134

97135
Create a network security group with [New-AzNetworkSecurityGroup](/powershell/module/az.network/new-aznetworksecuritygroup). The default rules in the network security group deny all inbound access from the internet.
98136

@@ -106,38 +144,38 @@ $nsg = @{
106144
New-AzNetworkSecurityGroup @nsg
107145
```
108146

109-
> [!NOTE]
110-
> All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see [Quickstart: Deploy Azure Bastion from the Azure portal](/azure/bastion/quickstart-host-portal).
111-
112-
## Create a virtual machine
147+
### Create a virtual machine
113148

114-
Create a virtual machine with [New-AzVM](/powershell/module/az.compute/new-azvm). When prompted, enter the username and password for the virtual machine.
149+
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:
115150

116151
```azurepowershell-interactive
117-
# Create a credential object
118152
$cred = Get-Credential
153+
```
119154

120-
# Define the virtual machine parameters
121-
$vmParams = @{
155+
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:
156+
157+
```azurepowershell-interactive
158+
## Create virtual machine. ##
159+
$vm = @{
122160
ResourceGroupName = 'myResourceGroup'
123-
Location = 'EastUS2'
161+
Location = 'East US 2'
124162
Name = 'myVM'
125-
Image = 'Win2022AzureEditionCore'
126-
Size = 'Standard_DS1_v2'
163+
Image = 'Ubuntu2204'
127164
Credential = $cred
128-
SecurityGroupName = 'myNSG'
165+
VirtualNetworkName = 'myVNet'
166+
SubnetName = 'default'
129167
PublicIpAddressName = ''
168+
GenerateSshKey = $true
169+
SshKeyName = 'mySSHKey'
130170
}
131-
132-
# Create the virtual machine
133-
New-AzVM @vmParams
171+
New-AzVM @vm
134172
```
135173

136174
# [Azure CLI](#tab/azurecli)
137175

138-
Use the following steps to create a resource group and a virtual machine.
176+
Use the following steps to create a resource group, virtual network, and virtual machine.
139177

140-
## Create a resource group
178+
### Create a resource group
141179

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

@@ -147,7 +185,21 @@ az group create \
147185
--location eastus2
148186
```
149187

150-
## Create a network security group
188+
### Create a virtual network and subnet
189+
190+
The following command creates a virtual network and subnet with [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create):
191+
192+
```azurecli-interactive
193+
az network vnet create \
194+
--name myVNet \
195+
--resource-group myResourceGroup \
196+
--location eastus2 \
197+
--address-prefixes 10.0.0.0/16 \
198+
--subnet-name default \
199+
--subnet-prefixes 10.0.0.0/24
200+
```
201+
202+
### Create a network security group
151203

152204
Create a network security group with [az network nsg create](/cli/azure/network/nsg#az-network-nsg-create). The default rules in the network security group deny all inbound access from the internet.
153205

@@ -157,23 +209,21 @@ az network nsg create \
157209
--name myNSG
158210
```
159211

160-
> [!NOTE]
161-
> All public inbound ports are closed for this virtual machine. To manage your virtual machines, deploy Azure Bastion. For more information, see [Quickstart: Deploy Azure Bastion from the Azure portal](/azure/bastion/quickstart-host-portal).
212+
### Create a virtual machine
162213

163-
## Create a virtual machine
164-
165-
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:
214+
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:
166215

167216
```azurecli-interactive
168217
az vm create \
169218
--name myVM \
170219
--resource-group myResourceGroup \
220+
--vnet-name myVNet \
221+
--subnet default \
222+
--image Ubuntu2204 \
171223
--public-ip-address "" \
172-
--nsg myNSG \
173-
--image MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest \
174-
--admin-username azureuser
224+
--admin-username azureuser \
225+
--generate-ssh-keys
175226
```
176-
177227
---
178228

179229
## Change private IP address to static

0 commit comments

Comments
 (0)