Skip to content

Commit bfa81bb

Browse files
committed
docs: Fix VM creation commands to use GenerateSshKey and Ubuntu2204 image alias
1 parent 83b0efc commit bfa81bb

1 file changed

Lines changed: 47 additions & 29 deletions

File tree

articles/virtual-network/tutorial-create-route-table.md

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -403,25 +403,22 @@ Network virtual appliances (NVAs) are virtual machines that help with network fu
403403
Create the virtual machine with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a virtual machine named *vm-nva*.
404404

405405
```azurepowershell-interactive
406-
# Create an SSH key for the virtual machine
407-
$sshParams = @{
408-
ResourceGroupName = "test-rg"
409-
Name = "vm-nva-ssh-key"
410-
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-nva-key -N "" -q; Get-Content ~/.ssh/vm-nva-key.pub -Raw)
411-
}
412-
New-AzSshKey @sshParams
406+
# Create a credential object
407+
$cred = Get-Credential
413408
414409
# Define the virtual machine parameters
415410
$vmParams = @{
416411
ResourceGroupName = "test-rg"
417412
Location = "EastUS2"
418413
Name = "vm-nva"
419-
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
414+
Image = "Ubuntu2204"
420415
Size = "Standard_DS1_v2"
416+
Credential = $cred
421417
VirtualNetworkName = "vnet-1"
422418
SubnetName = "subnet-dmz"
423-
PublicIpAddressName = $null # No public IP address
419+
PublicIpAddressName = "" # No public IP address
424420
SshKeyName = "vm-nva-ssh-key"
421+
GenerateSshKey = $true
425422
}
426423
427424
# Create the virtual machine
@@ -551,25 +548,19 @@ The public virtual machine is used to simulate a machine in the public internet.
551548
Create a virtual machine in the *subnet-1* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a virtual machine named *vm-public* in the *subnet-public* subnet of the *vnet-1* virtual network.
552549

553550
```azurepowershell-interactive
554-
# Create an SSH key for the virtual machine
555-
$sshParams = @{
556-
ResourceGroupName = "test-rg"
557-
Name = "vm-public-ssh-key"
558-
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-public-key -N "" -q; Get-Content ~/.ssh/vm-public-key.pub -Raw)
559-
}
560-
New-AzSshKey @sshParams
561-
562551
# Define the virtual machine parameters
563552
$vmParams = @{
564553
ResourceGroupName = "test-rg"
565554
Location = "EastUS2"
566555
Name = "vm-public"
567-
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
556+
Image = "Ubuntu2204"
568557
Size = "Standard_DS1_v2"
558+
Credential = $cred
569559
VirtualNetworkName = "vnet-1"
570560
SubnetName = "subnet-1"
571-
PublicIpAddressName = $null # No public IP address
561+
PublicIpAddressName = "" # No public IP address
572562
SshKeyName = "vm-public-ssh-key"
563+
GenerateSshKey = $true
573564
}
574565
575566
# Create the virtual machine
@@ -579,25 +570,19 @@ New-AzVM @vmParams
579570
Create a virtual machine in the *subnet-private* subnet.
580571

581572
```azurepowershell-interactive
582-
# Create an SSH key for the virtual machine
583-
$sshParams = @{
584-
ResourceGroupName = "test-rg"
585-
Name = "vm-private-ssh-key"
586-
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-private-key -N "" -q; Get-Content ~/.ssh/vm-private-key.pub -Raw)
587-
}
588-
New-AzSshKey @sshParams
589-
590573
# Define the virtual machine parameters
591574
$vmParams = @{
592575
ResourceGroupName = "test-rg"
593576
Location = "EastUS2"
594577
Name = "vm-private"
595-
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
578+
Image = "Ubuntu2204"
596579
Size = "Standard_DS1_v2"
580+
Credential = $cred
597581
VirtualNetworkName = "vnet-1"
598582
SubnetName = "subnet-private"
599-
PublicIpAddressName = $null # No public IP address
583+
PublicIpAddressName = "" # No public IP address
600584
SshKeyName = "vm-private-ssh-key"
585+
GenerateSshKey = $true
601586
}
602587
603588
# Create the virtual machine
@@ -699,6 +684,8 @@ az network nic update \
699684

700685
In this section, turn on IP forwarding for the operating system of the **vm-nva** virtual machine to forward network traffic. Use the Run Command feature to execute a script on the virtual machine.
701686

687+
### [Portal](#tab/portal)
688+
702689
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
703690

704691
1. In **Virtual machines**, select **vm-nva**.
@@ -720,6 +707,37 @@ In this section, turn on IP forwarding for the operating system of the **vm-nva*
720707

721708
1. Return to the **Overview** page of **vm-nva** and select **Restart** to restart the virtual machine.
722709

710+
### [PowerShell](#tab/powershell)
711+
712+
Enable IP forwarding in the operating system of the **vm-nva** virtual machine with [Invoke-AzVMRunCommand](/powershell/module/az.compute/invoke-azvmruncommand). The following example enables IP forwarding in the operating system.
713+
714+
```azurepowershell-interactive
715+
$runCommandParams = @{
716+
ResourceGroupName = "test-rg"
717+
VMName = "vm-nva"
718+
CommandId = "RunShellScript"
719+
ScriptString = @"
720+
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
721+
sudo sysctl -p
722+
"@
723+
}
724+
Invoke-AzVMRunCommand @runCommandParams
725+
```
726+
727+
### [CLI](#tab/cli)
728+
729+
Enable IP forwarding in the operating system of the **vm-nva** virtual machine with [az vm run-command invoke](/cli/azure/vm/run-command). The following example enables IP forwarding in the operating system.
730+
731+
```azurecli-interactive
732+
az vm run-command invoke \
733+
--resource-group test-rg \
734+
--name vm-nva \
735+
--command-id RunShellScript \
736+
--scripts "sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf" "sudo sysctl -p"
737+
```
738+
739+
---
740+
723741
## Create a route table
724742

725743
In this section, create a route table to define the route of the traffic through the NVA virtual machine. The route table is associated to the **subnet-1** subnet where the **vm-public** virtual machine is deployed.

0 commit comments

Comments
 (0)