Skip to content

Commit d17f802

Browse files
committed
fixes
1 parent eb90f2c commit d17f802

File tree

1 file changed

+77
-100
lines changed

1 file changed

+77
-100
lines changed

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

Lines changed: 77 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ Create an Azure Bastion host with [New-AzBastion](/powershell/module/az.network/
185185
$bastionParams = @{
186186
ResourceGroupName = "test-rg"
187187
Name = "bastion"
188-
Location = "EastUS"
189188
VirtualNetworkName = "vnet-1"
190-
SubnetName = "AzureBastionSubnet"
191189
PublicIpAddressName = "public-ip-bastion"
190+
PublicIpAddressRgName = "test-rg"
191+
VirtualNetworkRgName = "test-rg"
192192
}
193193
New-AzBastion @bastionParams -AsJob
194194
```
@@ -249,83 +249,29 @@ Network virtual appliances (NVAs) are virtual machines that help with network fu
249249

250250
### [PowerShell](#tab/powershell)
251251

252-
### Create a network interface
252+
### Create a virtual machine
253253

254-
Before creating a network interface, you have to retrieve the virtual network Id with [Get-AzVirtualNetwork](/powershell/module/az.network/get-azvirtualnetwork), then the subnet Id with [Get-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/get-azvirtualnetworksubnetconfig). Create a network interface with [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) in the *DMZ* subnet:
254+
Create the VM with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *vm-nva*.
255255

256256
```azurepowershell-interactive
257-
# Retrieve the virtual network object into a variable.
258-
$vnetParams = @{
259-
Name = "vnet-1"
260-
ResourceGroupName = "test-rg"
261-
}
262-
$virtualNetwork = Get-AzVirtualNetwork @vnetParams
257+
# Create a credential object
258+
$cred = Get-Credential
263259
264-
# Retrieve the subnet configuration into a variable.
265-
$subnetConfigParams = @{
266-
Name = "subnet-dmz"
267-
VirtualNetwork = $virtualNetwork
268-
}
269-
$subnetConfigDmz = Get-AzVirtualNetworkSubnetConfig @subnetConfigParams
270-
271-
# Create the network interface.
272-
$nicParams = @{
273-
ResourceGroupName = "test-rg"
274-
Location = "eastus2"
275-
Name = "vm-nva"
276-
SubnetId = $subnetConfigDmz.Id
277-
}
278-
$nic = New-AzNetworkInterface @nicParams
279-
```
280-
281-
### Create a VM
282-
283-
To create a VM and attach an existing network interface to it, you must first create a VM configuration with [New-AzVMConfig](/powershell/module/az.compute/new-azvmconfig). The configuration includes the network interface created in the previous step. When prompted for a username and password, select the user name and password you want to log into the VM with.
284-
285-
```azurepowershell-interactive
286-
# Create a credential object.
287-
$credParams = @{
288-
Message = "Enter a username and password for the VM."
289-
}
290-
$cred = Get-Credential @credParams
291-
292-
# Create a VM configuration.
293-
$vmConfigParams = @{
294-
VMName = 'vm-nva'
295-
VMSize = 'Standard_DS2'
296-
}
297-
$vmConfig = New-AzVMConfig @vmConfigParams
298-
299-
$osParams = @{
300-
Windows = $true
301-
ComputerName = 'vm-nva'
302-
Credential = $cred
303-
}
304-
$vmConfig = $vmConfig | Set-AzVMOperatingSystem @osParams
305-
306-
$imageParams = @{
307-
PublisherName = 'Canonical'
308-
Offer = '0001-com-ubuntu-server-focal'
309-
Skus = '24_04-lts'
310-
Version = 'latest'
311-
}
312-
$vmConfig = $vmConfig | Set-AzVMSourceImage @imageParams
313-
314-
$nicParams = @{
315-
Id = $nic.Id
260+
# Define the VM parameters
261+
$vmParams = @{
262+
ResourceGroupName = "test-rg"
263+
Location = "EastUS2"
264+
Name = "vm-nva"
265+
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
266+
Size = "Standard_DS1_v2"
267+
Credential = $cred
268+
VirtualNetworkName = "vnet-1"
269+
SubnetName = "subnet-dmz"
270+
PublicIpAddressName = $null # No public IP address
316271
}
317-
$vmConfig = $vmConfig | Add-AzVMNetworkInterface @nicParams
318-
```
319-
320-
Create the VM using the VM configuration with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *vm-nva*.
321272
322-
```azurepowershell-interactive
323-
$vmNvaParams = @{
324-
ResourceGroupName = "test-rg"
325-
Location = "eastus2"
326-
VM = $vmConfig
327-
}
328-
$vmNva = New-AzVM @vmNvaParams -AsJob
273+
# Create the VM
274+
New-AzVM @vmParams -AsJob
329275
```
330276

331277
The `-AsJob` option creates the VM in the background, so you can continue to the next step.
@@ -434,33 +380,50 @@ The public virtual machine is used to simulate a machine in the public internet.
434380

435381
### [PowerShell](#tab/powershell)
436382

437-
Create a VM in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *myVmPublic* in the *subnet-public* subnet of the *vnet-1* virtual network.
383+
Create a VM in the *subnet-1* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *vm-public* in the *subnet-public* subnet of the *vnet-1* virtual network.
438384

439385
```azurepowershell-interactive
440-
$vmPublicParams = @{
441-
ResourceGroupName = "test-rg"
442-
Location = "eastus2"
443-
VirtualNetworkName = "vnet-1"
444-
SubnetName = "subnet-public"
445-
ImageName = "Canonical:0001-com-ubuntu-server-focal:24_04-lts:latest"
446-
Name = "vm-public"
447-
AsJob = $true
386+
# Create a credential object
387+
$cred = Get-Credential
388+
389+
# Define the VM parameters
390+
$vmParams = @{
391+
ResourceGroupName = "test-rg"
392+
Location = "EastUS2"
393+
Name = "vm-public"
394+
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
395+
Size = "Standard_DS1_v2"
396+
Credential = $cred
397+
VirtualNetworkName = "vnet-1"
398+
SubnetName = "subnet-1"
399+
PublicIpAddressName = $null # No public IP address
448400
}
449-
New-AzVm @vmPublicParams
401+
402+
# Create the VM
403+
New-AzVM @vmParams
450404
```
451405

452406
Create a VM in the *subnet-private* subnet.
453407

454408
```azurepowershell-interactive
455-
$vmPrivateParams = @{
456-
ResourceGroupName = "test-rg"
457-
Location = "eastus2"
458-
VirtualNetworkName = "vnet-1"
459-
SubnetName = "subnet-private"
460-
ImageName = "Canonical:0001-com-ubuntu-server-focal:24_04-lts:latest"
461-
Name = "vm-private"
409+
# Create a credential object
410+
$cred = Get-Credential
411+
412+
# Define the VM parameters
413+
$vmParams = @{
414+
ResourceGroupName = "test-rg"
415+
Location = "EastUS2"
416+
Name = "vm-private"
417+
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
418+
Size = "Standard_DS1_v2"
419+
Credential = $cred
420+
VirtualNetworkName = "vnet-1"
421+
SubnetName = "subnet-private"
422+
PublicIpAddressName = $null # No public IP address
462423
}
463-
New-AzVm @vmPrivateParams
424+
425+
# Create the VM
426+
New-AzVM @vmParams
464427
```
465428

466429
The VM takes a few minutes to create. Don't continue with the next step until the VM is created and Azure returns output to PowerShell.
@@ -503,18 +466,14 @@ Enable IP forwarding for the network interface of the **vm-nva** virtual machine
503466

504467
```azurepowershell-interactive
505468
$nicParams = @{
506-
Name = "vm-nva313"
469+
Name = "vm-nva"
507470
ResourceGroupName = "test-rg"
508471
}
509-
510472
$nic = Get-AzNetworkInterface @nicParams
511-
$nic.EnableIPForwarding = $true
512473
513-
$setNicParams = @{
514-
InputObject = $nic
515-
}
474+
$nic.EnableIPForwarding = $true
516475
517-
Set-AzNetworkInterface @setNicParams
476+
Set-AzNetworkInterface -NetworkInterface $nic
518477
```
519478

520479
### [CLI](#tab/cli)
@@ -646,15 +605,33 @@ $routeTableParams = @{
646605
647606
$routeConfigParams = @{
648607
Name = "to-private-subnet"
649-
AddressPrefix = "10.0.1.0/24"
608+
AddressPrefix = "10.0.2.0/24"
650609
NextHopType = "VirtualAppliance"
651-
NextHopIpAddress = "10.0.2.4"
610+
NextHopIpAddress = "10.0.3.4"
652611
}
653612
654613
$routeTable = Get-AzRouteTable @routeTableParams
655614
$routeTable | Add-AzRouteConfig @routeConfigParams | Set-AzRouteTable
656615
```
657616

617+
Associate the route table with the **subnet-1** subnet with [Set-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/set-azvirtualnetworksubnetconfig). The following example associates the *route-table-public* route table with the *subnet-1* subnet.
618+
619+
```azurepowershell-interactive
620+
$vnetParams = @{
621+
Name = 'vnet-1'
622+
ResourceGroupName = 'test-rg'
623+
}
624+
$virtualNetwork = Get-AzVirtualNetwork @vnetParams
625+
626+
$subnetParams = @{
627+
VirtualNetwork = $virtualNetwork
628+
Name = 'subnet-1'
629+
AddressPrefix = '10.0.0.0/24'
630+
RouteTable = $routeTablePublic
631+
}
632+
Set-AzVirtualNetworkSubnetConfig @subnetParams | Set-AzVirtualNetwork
633+
```
634+
658635
### [CLI](#tab/cli)
659636

660637
---

0 commit comments

Comments
 (0)