共用方式為


在 Azure 本機上為 Azure Arc 虛擬機器建立網路介面。

適用於:Azure Local 2311.2 和更新版本

本文說明如何建立網路介面,以便與 Azure 本機實例上的 Arc VM 產生關聯。 您可以使用 Azure 入口網站 或 Azure CLI 來建立網路介面。

關於網路介面

網路介面是 Azure 資源,可用來在您的系統上部署虛擬機。 建立邏輯網路之後,您可以建立網路介面,並將這些網路介面與您將建立的虛擬機產生關聯。

您可以使用 Azure 入口網站 或 Azure CLI 來建立網路介面。 使用 Azure 入口網站 時,網路介面建立是 VM 建立程式的一部分。 使用 Azure CLI 時,您可以先建立網路介面,然後使用它來建立 VM。

必要條件

建立網路介面之前,請確定下列必要條件已完成。

建立網路介面

若要建立 VM,您必須先在邏輯網路上建立網路介面。 視邏輯網路是靜態還是 DHCP 而定,這些步驟可能會有所不同。

登入並設定訂用帳戶

  1. 連接到您的 Azure 本地環境中的電腦

  2. 登入。 類型:

    az login --use-device-code
    
  3. 設定您的訂用帳戶。

    az account set --subscription <Subscription ID>
    

具有靜態IP的虛擬網路介面

請遵循下列步驟,在您的靜態邏輯網路上建立網路介面。 將中的 < > 參數取代為適當的值。

  1. 設定必要參數。 以下是範例輸出:

    $lnetName = "mylocal-lnet-static"
    $gateway ="100.68.180.1" 
    $ipAddress ="100.68.180.6" 
    $nicName ="mylocal-nic-static"
    $subscription =  "<Subscription ID>"
    $resource_group = "mylocal-rg"
    $customLocationName = "mylocal-cl" 
    $customLocationID ="/subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.ExtendedLocation/customLocations/$customLocationName"
    $location = "eastus"
    

    以下是參數的描述:

    參數 描述:
    name 您將在 Azure 本機環境中部署的邏輯網路上建立的網路介面名稱。 請務必提供遵循 Azure 資源規則的名稱。 您無法在建立網路介面之後重新命名。
    資源群組 部署 Azure Local 的資源群組名稱。 這也可能是另一個預先建立的資源群組。
    訂閱 訂用帳戶的名稱或識別碼,其中部署了 Azure Local。 這可能是您在 Azure 本機上用於邏輯網路的另一個訂用帳戶。
    自訂位置 用於 Azure 本機區域之邏輯網路的自定義位置名稱或 ID。
    位置 Azure 區域,如 az locations 所指定。 例如,這可能是 eastuswesteurope
    subnet-id 邏輯網路的名稱。 例如: test-lnet-dynamic
    IP 分配方法 (ip-allocation-method) IP 位址設定方法,可以是 dynamicstatic 適用於您的網路介面。 如果未指定此參數,預設會使用動態組態建立網路介面。
    ip-address 您想要指派給所建立網路介面的 IPv4 位址。 例如:「192.168.0.10」。。
  2. 若要建立具有靜態 IP 位址的網路介面,請執行下列命令:

    az stack-hci-vm network nic create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --name $nicName --subnet-id $lnetName --ip-address $ipAddress
    

    以下是範例輸出:

    {
      "extendedLocation": {
        "name": "/subscriptions/<subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.ExtendedLocation/customLocations/mylocal-cl",
        "type": "CustomLocation"
      },
      "id": "/subscriptions/<subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/networkinterfaces/mylocal-nic-static",
      "location": "eastus",
      "name": "mylocal-nic-static",
      "properties": {
        "dnsSettings": {
          "dnsServers": null
        },
        "ipConfigurations": [
          {
            "name": null,
            "properties": {
              "gateway": "192.168.200.1",
              "prefixLength": "24",
              "privateIpAddress": "192.168.201.3",
              "privateIpAllocationMethod": null,
              "subnet": {
                "id": "/subscriptions/<subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/logicalnetworks/mylocal-lnet-static",
                "resourceGroup": "mylocal-rg"
              }
            }
          }
        ],
        "macAddress": null,
        "provisioningState": "Succeeded",
        "resourceName": null,
        "status": {}
      },
      "resourceGroup": "mylocal-rg",
      "systemData": {
        "createdAt": "2023-11-02T23:00:47.714910+00:00",
        "createdBy": "guspinto@contoso.com",
        "createdByType": "User",
        "lastModifiedAt": "2023-11-02T23:02:08.720545+00:00",
        "lastModifiedBy": "<ID>",
        "lastModifiedByType": "Application"
      },
      "tags": null,
      "type": "microsoft.azurestackhci/networkinterfaces"
    } 
    

使用 DHCP 的虛擬網路介面

請遵循下列步驟,在您的 DHCP 邏輯網路上建立網路介面。 將中的 < > 參數取代為適當的值。

  1. 設定必要參數。 以下是範例輸出:

    $nicName = "mylocal-nic-dhcp"
    $lnetName = "mylocal-lnet-dhcp"   
    $subscription =  "<subscription ID>" 
    $resource_group = "mylocal-rg"
    $customLocationName = "mylocal-cl" 
    $customLocationID ="/subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.ExtendedLocation/customLocations/$customLocationName"
    $location = "eastus"
    

    以下是參數的描述:

    參數 描述:
    name 您將在 Azure 本機上部署之邏輯網路上建立的網路介面名稱。 請務必提供遵循 Azure 資源規則的名稱。 您無法在建立網路介面之後重新命名。
    資源群組 部署 Azure 本機部署的資源群組名稱。 這也可能是另一個預先建立的資源群組。
    訂閱 部署 Azure Local 的訂閱名稱或 ID。 這可能是您在 Azure 本地環境中用於邏輯網路的另一個訂閱。
    自訂位置 要用於 Azure 本地上邏輯網路的自訂位置名稱或識別碼。
    位置 Azure 區域,根據 az locations 指定。 例如,可以是 eastus
    subnet-id 邏輯網路的名稱。 例如: test-lnet-dynamic
  2. 若要建立網路介面,請執行下列命令:

    az stack-hci-vm network nic create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --name $nicName --subnet-id $lnetName
    

    以下是範例輸出:

    {
      "extendedLocation": {
        "name": "/subscriptions/<subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.ExtendedLocation/customLocations/mylocal-cl",
        "type": "CustomLocation"
      },
      "id": "/subscriptions/<subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/networkinterfaces/mylocal-vnic",
      "location": "eastus",
      "name": "mylocal-nic-dhcp",
      "properties": {
        "ipConfigurations": [
          {
            "name": null,
            "properties": {
              "gateway": null,
              "prefixLength": null,
              "privateIpAddress": null,
              "privateIpAllocationMethod": null,
              "subnet": {
                "id": "mylocal-lnet-dhcp"
              }
            }
          }
        ],
        "macAddress": null,
        "provisioningState": "Succeeded",
        "resourceName": "mylocal-nic-dhcp",
        "status": {}
      },
      "resourceGroup": "mylocal-rg",
      "systemData": {
        "createdAt": "2023-02-08T23:25:10.984508+00:00",
        "createdBy": "guspinto@contoso.com",
        "createdByType": "User",
        "lastModifiedAt": "2023-02-08T23:26:03.262252+00:00",
        "lastModifiedBy": "<ID>",
        "lastModifiedByType": "Application"
      },
      "tags": null,
      "type": "microsoft.azurestackhci/networkinterfaces"
    }
    PS C:\windows\system32> 
    

您可以使用此網路介面來建立 VM。 如需詳細資訊,請參閱 建立 VM

下一步