## Place NAT gateway into a variable. ##
$ng = @{
Name = 'myNATgateway'
ResourceGroupName = 'myResourceGroup'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP address associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'myPublicIP-NAT'
ResourceGroupName = 'myResourceGroup'
}
$publicIP1 = Get-AzPublicIPaddress @ip
## Place the public IP address you created previously into a variable. ##
$ip = @{
Name = 'myPublicIP-NAT2'
ResourceGroupName = 'myResourceGroup'
}
$publicIP2 = Get-AzPublicIPaddress @ip
## Place the public IP address variables into an array. ##
$pipArray = $publicIP1,$publicIP2
## Add the IP address to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpAddress = $pipArray
}
Set-AzNatGateway @nt
移除公用 IP 位址
若要從 NAT 閘道中移除公用 IP,請建立一個不包含您想要移除之 IP 位址的陣列物件。 例如,您有一個 NAT 閘道已設定兩個公用 IP 位址。 您想要移除其中一個 IP 位址。 與 NAT 閘道相關聯的 IP 位址名為 myPublicIP-NAT 和 myPublicIP-NAT2。 若要移除 myPublicIP-NAT2,請為只包含 myPublicIP-NAT 的 PowerShell 命令建立一個陣列物件。 當您套用此命令時,該陣列會重新套用至 NAT 閘道,而 myPublicIP-NAT 是唯一相關聯的公用 IP 位址。
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'myNATgateway'
ResourceGroupName = 'myResourceGroup'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP address associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'myPublicIP-NAT'
ResourceGroupName = 'myResourceGroup'
}
$publicIP1 = Get-AzPublicIPaddress @ip
## Place the second public IP address into a variable. ##
$ip = @{
Name = 'myPublicIP-NAT2'
ResourceGroupName = 'myResourceGroup'
}
$publicIP2 = Get-AzPublicIPAddress @ip
## Place ONLY the public IP you wish to keep in the array. ##
$pipArray = $publicIP1
## Add the public IP address to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpAddress = $pipArray
}
Set-AzNatGateway @nt
使用 az network nat gateway update 從 NAT 閘道移除公用 IP 位址。 該 Azure CLI 命令會取代值。 它不會移除值。 若要移除公用 IP 位址,請在您想要保留的命令中包含任何 IP 位址。 省略您要移除的值。 例如,您有一個 NAT 閘道已設定兩個公用 IP 位址。 您想要移除其中一個 IP 位址。 與 NAT 閘道相關聯的 IP 位址名為 myPublicIP-NAT 和 myPublicIP-NAT2。 若要移除 myPublicIP-NAT2,請從此命令中省略 IP 位址的名稱。 此命令會將命令中列出的 IP 位址重新套用至 NAT 閘道。 它會移除未列出的任何 IP 位址。
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'myNATgateway'
ResourceGroupName = 'myResourceGroup'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'myPublicIPprefix-NAT'
ResourceGroupName = 'myResourceGroup'
}
$prefixIP1 = Get-AzPublicIPPrefix @ip
## Place the public IP prefix you created previously into a variable. ##
$ip = @{
Name = 'myPublicIPprefix-NAT2'
ResourceGroupName = 'myResourceGroup'
}
$prefixIP2 = Get-AzPublicIPprefix @ip
## Place the public IP address variables into an array. ##
$preArray = $prefixIP1,$prefixIP2
## Add the IP address prefix to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpPrefix = $preArray
}
Set-AzNatGateway @nt
移除公用 IP 前置詞
若要從 NAT 閘道中移除公用 IP 前置詞,請建立一個不包含您要移除的 IP 位址前置詞的陣列物件。 例如,您有一個 NAT 閘道已設定兩個公用 IP 前置詞。 您想要移除其中一個 IP 前置詞。 與 NAT 閘道相關聯的 IP 前置詞名為 myPublicIPprefix-NAT 和 myPublicIPprefix-NAT2。 若要移除 myPublicIPprefix-NAT2,請為只包含 myPublicIPprefix-NAT 的 PowerShell 命令建立一個陣列物件。 當您套用此命令時,該陣列會重新套用至 NAT 閘道,而 myPublicIPprefix-NAT 是唯一相關聯的前置詞。
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'myNATgateway'
ResourceGroupName = 'myResourceGroup'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'myPublicIPprefix-NAT'
ResourceGroupName = 'myResourceGroup'
}
$prefixIP1 = Get-AzPublicIPPrefix @ip
## Place the secondary public IP prefix into a variable. ##
$ip = @{
Name = 'myPublicIPprefix-NAT2'
ResourceGroupName = 'myResourceGroup'
}
$prefixIP2 = Get-AzPublicIPprefix @ip
## Place ONLY the prefix you wish to keep in the array. DO NOT ADD THE SECONDARY VARIABLE ##
$preArray = $prefixIP1
## Add the IP address prefix to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpPrefix = $preArray
}
Set-AzNatGateway @nt
新增公用 IP 首碼
在此範例中,與 NAT 閘道相關聯的現有公用 IP 前置詞名為 myPublicIPprefix-NAT。