本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用字首
您可以搭配使用字首與網路介面,如下所示。
在建立網路介面期間指派字首
如果您使用自動指派選項,您可以在子網路中保留 IP 位址區塊。 AWS 從此區塊中選擇首碼。如需詳細資訊,請參閱《Amazon VPC 使用者指南》中的 子網 CIDR 保留。
建立網路介面後,請使用指attach-network-interface AWS CLI 令將網路介面附加至執行個體。您必须使用字首設定使用網路介面的作業系統。如需詳細資訊,請參閱 使用字首設定網路介面的作業系統。
在建立網路介面期間指派自動字首
您可以使用下列方法之一在建立網路介面期間指派自動字首。
- Console
-
在建立網路介面期間指派自動字首
-
前往 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面),然後選擇 Create network interface (建立網路介面)。
-
指定網路介面的描述,選取要在其中建立網路介面的子網,然後設定私有 IPv4 和 IPv6 地址。
-
展開 Advanced settings (進階設定),並執行下列動作:
-
若要自動指派 IPv4 字首,對於 IPv4 prefix delegation (IPv4 字首委派),選擇 Auto-assign (自動指派)。然後對於 Number of IPv4 prefixes (IPv4 字首的數目),指定要指派的字首數目。
-
若要自動指派 IPv4 字首,對於 IPv6 prefix delegation (IPv6 字首委派),選擇 Auto-assign (自動指派)。然後對於 Number of IPv6 prefixes (IPv6 字首的數目),指定要指派的字首數目。
注意
IPv6 prefix delegation (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。
-
-
選取要與網路介面建立關聯的安全群組,並視需要指派資源標籤。
-
選擇 Create network interface (建立網路介面)。
-
- AWS CLI
-
在建立網路介面期間指派自動 IPv4 字首
使用指 create-network-interface令並設定
--ipv4-prefix-count
為您要 AWS 指定的前置字元數目。在下列範例中, AWS 指定1
前置字元。C:\>
aws ec2 create-network-interface \ --subnet-idsubnet-047cfed18eEXAMPLE
\ --description "IPv4 automatic example
" \ --ipv4-prefix-count1
範例輸出
{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "IPv4 automatic example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c4EXAMPLE" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:98:65:dd:18:47", "NetworkInterfaceId": "eni-02b80b4668EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.62", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.62" } ], "Ipv4Prefixes": [ { "Ipv4Prefix": "10.0.0.208/28" } ], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-047cfed18eEXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b21EXAMPLE" } }
在建立網路介面期間指派自動 IPv6 字首
使用指 create-network-interface令並設定
--ipv6-prefix-count
為您要 AWS 指定的前置字元數目。在下列範例中, AWS 指定1
前置字元。C:\>
aws ec2 create-network-interface \ --subnet-idsubnet-047cfed18eEXAMPLE
\ --description "IPv6 automatic example
" \ --ipv6-prefix-count1
範例輸出
{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "IPv6 automatic example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c4EXAMPLE" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:bb:e4:31:fe:09", "NetworkInterfaceId": "eni-006edbcfa4EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.73", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.73" } ], "Ipv6Prefixes": [ { "Ipv6Prefix": "2600:1f13:fc2:a700:1768::/80" } ], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-047cfed18eEXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b21EXAMPLE" } }
在建立網路介面期間指派特定的字首
您可以使用下列方法之一在建立網路介面期間指派特定字首。
- Console
-
在建立網路介面期間指派特定的字首
-
前往 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面),然後選擇 Create network interface (建立網路介面)。
-
指定網路介面的描述,選取要在其中建立網路介面的子網,然後設定私有 IPv4 和 IPv6 地址。
-
展開 Advanced settings (進階設定),並執行下列動作:
-
若要指派特定的 IPv4 字首,對於 IPv4 prefix delegation (IPv4 字首委派),選擇 Custom (自訂)。然後選擇 Add new prefix (新增字首),並輸入要使用的字首。
-
若要指派特定的 IPv6 字首,對於 IPv6 prefix delegation (IPv6 字首委派),選擇 Custom (自訂)。然後選擇 Add new prefix (新增字首),並輸入要使用的字首。
注意
IPv6 prefix delegation (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。
-
-
選取要與網路介面建立關聯的安全群組,並視需要指派資源標籤。
-
選擇 Create network interface (建立網路介面)。
-
- AWS CLI
-
在建立網路介面期間指派特定的 IPv4 字首
使用指 create-network-interface令並設定
--ipv4-prefixes
為前置字元。 AWS 選取此範圍內的 IP 位址。在下列範例中,字首 CIDR 是10.0.0.208/28
。C:\>
aws ec2 create-network-interface \ --subnet-idsubnet-047cfed18eEXAMPLE
\ --description "IPv4 manual example
" \ --ipv4-prefixes Ipv4Prefix=10.0.0.208/28
範例輸出
{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "IPv4 manual example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c4EXAMPLE" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:98:65:dd:18:47", "NetworkInterfaceId": "eni-02b80b4668EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.62", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.62" } ], "Ipv4Prefixes": [ { "Ipv4Prefix": "10.0.0.208/28" } ], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-047cfed18eEXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b21EXAMPLE" } }
在建立網路介面期間指派特定的 IPv6 字首
使用指 create-network-interface令並設定
--ipv6-prefixes
為前置字元。 AWS 選取此範圍內的 IP 位址。在下列範例中,字首 CIDR 是2600:1f13:fc2:a700:1768::/80
。C:\>
aws ec2 create-network-interface \ --subnet-idsubnet-047cfed18eEXAMPLE
\ --description "IPv6 manual example
" \ --ipv6-prefixes Ipv6Prefix=2600:1f13:fc2:a700:1768::/80
範例輸出
{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "IPv6 automatic example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c4EXAMPLE" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:bb:e4:31:fe:09", "NetworkInterfaceId": "eni-006edbcfa4EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.73", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.73" } ], "Ipv6Prefixes": [ { "Ipv6Prefix": "2600:1f13:fc2:a700:1768::/80" } ], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-047cfed18eEXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b21EXAMPLE" } }
為現有的網路介面指派字首
指定首碼後,請使用指 attach-network-interface AWS CLI 令將網路介面附加至例證。您必须使用字首設定使用網路介面的作業系統。如需詳細資訊,請參閱 使用字首設定網路介面的作業系統。
將自動字首指派給現有的網路介面
您可以使用下列方法之一向現有網路介面指派自動字首。
- Console
-
將自動字首指派給現有網路介面
-
在 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面)。
-
選取要指派字首的網路介面,然後選取 Actions (動作)、Manage prefixes (管理字首)。
-
若要自動指派 IPv4 字首,對於 IPv4 prefix delegation (IPv4 字首委派),選擇 Auto-assign (自動指派)。然後對於 Number of IPv4 prefixes (IPv4 字首的數目),指定要指派的字首數目。
-
若要自動指派 IPv4 字首,對於 IPv6 prefix delegation (IPv6 字首委派),選擇 Auto-assign (自動指派)。然後對於 Number of IPv6 prefixes (IPv6 字首的數目),指定要指派的字首數目。
注意
IPv6 prefix delegation (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。
-
選擇儲存。
-
- AWS CLI
-
您可以使用指定 IPv6 位址指令來指定 IPv6 前置詞,並使用指令將 IPv4 前置字元指派給現有的網路介面assign-private-ip-addresses。
將自動 IPv4 字首指派給現有網路介面
使用指 assign-private-ip-addresses令並設定
--ipv4-prefix-count
為您要 AWS 指定的前置字元數目。在下列範例中, AWS 指定1
IPv4 前置詞。C:\>
aws ec2 assign-private-ip-addresses \ --network-interface-ideni-081fbb4095EXAMPLE
\ --ipv4-prefix-count1
範例輸出
{ "NetworkInterfaceId": "eni-081fbb4095EXAMPLE", "AssignedIpv4Prefixes": [ { "Ipv4Prefix": "10.0.0.176/28" } ] }
將自動 IPv6 字首指派給現有網路介面
使用指定 -ipv6 位址指令,並設定
--ipv6-prefix-count
為您要指派的前置字元數目。 AWS 在下列範例中, AWS 指定1
IPv6 前置詞。C:\>
aws ec2 assign-ipv6-addresses \ --network-interface-ideni-00d577338cEXAMPLE
\ --ipv6-prefix-count1
範例輸出
{ "AssignedIpv6Prefixes": [ "2600:1f13:fc2:a700:18bb::/80" ], "NetworkInterfaceId": "eni-00d577338cEXAMPLE" }
將特定字首指派給現有的網路介面
您可以使用下列方法之一向現有網路介面指派特定字首。
- Console
-
將特定字首指派給現有的網路介面
-
在 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面)。
-
選取要指派字首的網路介面,然後選取 Actions (動作)、Manage prefixes (管理字首)。
-
若要指派特定的 IPv4 字首,對於 IPv4 prefix delegation (IPv4 字首委派),選擇 Custom (自訂)。然後選擇 Add new prefix (新增字首),並輸入要使用的字首。
-
若要指派特定的 IPv6 字首,對於 IPv6 prefix delegation (IPv6 字首委派),選擇 Custom (自訂)。然後選擇 Add new prefix (新增字首),並輸入要使用的字首。
注意
IPv6 prefix delegation (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。
-
選擇儲存。
-
- AWS CLI
-
將特定 IPv4 字首指派給現有的網路介面
使用 assign-private-ip-addresses指令並設
--ipv4-prefixes
定為首碼。 AWS 從此範圍中選取 IPv4 位址。在下列範例中,字首 CIDR 是10.0.0.208/28
。C:\>
aws ec2 assign-private-ip-addresses \ --network-interface-ideni-081fbb4095EXAMPLE
\ --ipv4-prefixes10.0.0.208/28
範例輸出
{ "NetworkInterfaceId": "eni-081fbb4095EXAMPLE", "AssignedIpv4Prefixes": [ { "Ipv4Prefix": "10.0.0.208/28" } ] }
將特定 IPv6 字首指派給現有的網路介面
使用分配 ipv6 地址命令並設置為前綴。
--ipv6-prefixes
AWS 從此範圍中選取 IPv6 位址。在下列範例中,字首 CIDR 是2600:1f13:fc2:a700:18bb::/80
。C:\>
aws ec2 assign-ipv6-addresses \ --network-interface-ideni-00d577338cEXAMPLE
\ --ipv6-prefixes2600:1f13:fc2:a700:18bb::/80
範例輸出
{ "NetworkInterfaceId": "eni-00d577338cEXAMPLE", "AssignedIpv6Prefixes": [ { "Ipv6Prefix": "2600:1f13:fc2:a700:18bb::/80" } ] }
使用字首設定網路介面的作業系統
Amazon Linux AMI 可能包含由安裝的其他指令碼 AWS,稱為ec2-net-utils
. 這些指令碼會選擇性自動化您網路介面的組態。這些指令碼僅供 Amazon Linux 使用。
如果您不是使用 Amazon Linux,則可以使用容器網路介面 (CNI) 作為 Kubernetes 外掛程式,或 dockerd
(如果您使用 Docker 來管理容器)。
檢視被指派給網路介面的字首
您可以使用下列方法之一檢視被指派給網路介面的字首。
- Console
-
檢視被指派給現有網路介面的自動字首
-
在 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面)。
-
選取要檢視字首的網路介面,並選取 Details (詳細資訊) 索引標籤。
-
IPv4 Prefix Delegation (IPv4 字首委派) 欄位會列出指派的 IPv4 字首,而 IPv6 Prefix Delegation (IPv6 字首委派) 欄位會列出指派的 IPv6 字首。
-
- AWS CLI
-
您可以使用指 describe-network-interfaces AWS CLI 令來檢視指派給網路介面的首碼。
C:\>
aws ec2 describe-network-interfaces範例輸出
{ "NetworkInterfaces": [ { "AvailabilityZone": "us-west-2a", "Description": "IPv4 automatic example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c4EXAMPLE" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:98:65:dd:18:47", "NetworkInterfaceId": "eni-02b80b4668EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.62", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.62" } ], "Ipv4Prefixes": [ { "Ipv4Prefix": "10.0.0.208/28" } ], "Ipv6Prefixes": [], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "available", "SubnetId": "subnet-05eef9fb78EXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b2146bf252" }, { "AvailabilityZone": "us-west-2a", "Description": "IPv6 automatic example", "Groups": [ { "GroupName": "default", "GroupId": "sg-044c2de2c411c91b5" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "02:bb:e4:31:fe:09", "NetworkInterfaceId": "eni-006edbcfa4EXAMPLE", "OwnerId": "123456789012", "PrivateIpAddress": "10.0.0.73", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.73" } ], "Ipv4Prefixes": [], "Ipv6Prefixes": [ { "Ipv6Prefix": "2600:1f13:fc2:a700:1768::/80" } ], "RequesterId": "AIDAIV5AJI5LXF5XXDPCO", "RequesterManaged": false, "SourceDestCheck": true, "Status": "available", "SubnetId": "subnet-05eef9fb78EXAMPLE", "TagSet": [], "VpcId": "vpc-0e12f52b21EXAMPLE" } ] }
從網路介面移除字首
您可以使用下列方法之一從您的網路介面移除字首。
- Console
-
從網路介面移除字首
-
在 https://console.aws.amazon.com/ec2/
開啟 Amazon EC2 主控台。 -
在導覽窗格中,選擇 Network Interfaces (網路介面)。
-
選取要從中移除字首的網路介面,然後選取 Actions (動作)、Manage prefixes (管理字首)。
-
執行以下任意一項:
-
若要移除所有指定的字首,對於 IPv4 prefix delegation (IPv4 字首委派) 和 IPv6 prefix delegation (IPv6 字首委派),選擇 Do not assign (不指派)。
-
如要移除特定指定的字首,對於 IPv4 prefix delegation (IPv4 字首委派) 或 IPv6 prefix delegation (IPv6 字首委派),選擇 Custom (自訂),然後選擇要移除的字首旁邊的 Unassign (取消指派)。
注意
IPv6 prefix delegation (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。
-
-
選擇儲存。
-
- AWS CLI
-
您可以使用未指定 IPv4 位址指令移除 IPv6 前置詞,以及從現有網路介面移除 IPv4 前置詞的命unassign-private-ip-addresses令。
從網路介面移除 IPv4 字首
使用unassign-private-ip-addresses命令並設置
--ipv4-prefix
為要刪除的地址。C:\>
aws ec2 unassign-private-ip-addresses \ --network-interface-ideni-081fbb4095EXAMPLE
\ --ipv4-prefixes10.0.0.176/28
從網路介面移除 IPv6 字首
使用 unassign-ipv6-addresses 命令,並將
--ipv6-prefix
設定為您要移除的位址。C:\>
aws ec2 unassign-ipv6-addresses \ --network-interface-ideni-00d577338cEXAMPLE
\ --ipv6-prefix2600:1f13:fc2:a700:18bb::/80