Configuring private and public IP addresses

In this section, we are going to configure both a private and a public IP address. When we created the VNet, a private IP address was created for us automatically by Azure. However, we are going to create another in this demonstration and associate it, along with the public IP address, to a network interface card (NIC). To configure a private and public IP address from PowerShell, you have to perform the following steps:

  1. In the same PowerShell window, add the following code to retrieve the VNet and subnet configuration:
$vnet = Get-AzVirtualNetwork -Name PacktVirtualNetwork -ResourceGroupName PacktVNetResourceGroup
$subnet = Get-AzVirtualNetworkSubnetConfig -Name default -VirtualNetwork $vnet
  1. Next, create a private and a public IP address and assign them to the configuration, as follows:
$publicIP = New-AzPublicIpAddress `
-Name PacktPublicIP `
-ResourceGroupName PacktVNetResourceGroup `
-AllocationMethod Dynamic `
-Location EastUS

$IpConfig = New-AzNetworkInterfaceIpConfig `
-Name PacktPrivateIP `
-Subnet $subnet `
-PrivateIpAddress 10.0.0.4 `
-PublicIPAddress $publicIP `
-Primary
  1. Then, create a network interface and assign the configuration to it, as follows:
$NIC = New-AzNetworkInterface `
-Name PacktNIC `
-ResourceGroupName PacktVNetResourceGroup `
-Location EastUS `
-IpConfiguration $IpConfig

Now, we have configured an NIC, a public and a private IP address, and associated them with the VNet that we created in the previous section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.247