CreateNetworkInterface与 a 一起使用 CLI - Amazon Elastic Compute Cloud

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

CreateNetworkInterface与 a 一起使用 CLI

以下代码示例演示如何使用 CreateNetworkInterface

CLI
AWS CLI

示例 1:为网络接口指定IPv4地址

以下create-network-interface示例使用指定的主IPv4地址为指定子网创建网络接口。

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my network interface" \ --groups sg-09dfba7ed20cda78b \ --private-ip-address 10.0.8.17

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my network interface", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-09dfba7ed20cda78b" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "06:6a:0f:9a:49:37", "NetworkInterfaceId": "eni-0492b355f0cf3b3f8", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.17", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-17.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.17" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

示例 2:使用IPv4地址和地址创建网络接口 IPv6

以下create-network-interface示例使用由 Amazon 选择IPv4的地址和地址为指定子网创建网络接口EC2。IPv6

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my dual stack network interface" \ --ipv6-address-count 1 \ --groups sg-09dfba7ed20cda78b

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my dual stack network interface", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-09dfba7ed20cda78b" } ], "InterfaceType": "interface", "Ipv6Addresses": [ { "Ipv6Address": "2600:1f13:cfe:3650:a1dc:237c:393a:4ba7", "IsPrimaryIpv6": false } ], "MacAddress": "06:b8:68:d2:b2:2d", "NetworkInterfaceId": "eni-05da417453f9a84bf", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.18", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.18" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b", "Ipv6Address": "2600:1f13:cfe:3650:a1dc:237c:393a:4ba7" } }

示例 3:使用连接跟踪配置选项创建网络接口

以下create-network-interface示例创建网络接口并配置空闲连接跟踪超时。

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --groups sg-02e57dbcfe0331c1b \ --connection-tracking-specification TcpEstablishedTimeout=86400,UdpTimeout=60

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "ConnectionTrackingConfiguration": { "TcpEstablishedTimeout": 86400, "UdpTimeout": 60 }, "Description": "", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-02e57dbcfe0331c1b" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "06:4c:53:de:6d:91", "NetworkInterfaceId": "eni-0c133586e08903d0b", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-94.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.94", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-94.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.94" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

示例 4:创建弹性结构适配器

以下create-network-interface示例创建了一个EFA。

aws ec2 create-network-interface \ --interface-type efa \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my efa" \ --groups sg-02e57dbcfe0331c1b

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my efa", "Groups": [ { "GroupName": "my-efa-sg", "GroupId": "sg-02e57dbcfe0331c1b" } ], "InterfaceType": "efa", "Ipv6Addresses": [], "MacAddress": "06:d7:a4:f7:4d:57", "NetworkInterfaceId": "eni-034acc2885e862b65", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-180.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.180", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-180.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.180" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性网络接口

PowerShell
用于 PowerShell

示例 1:此示例创建指定的网络接口。

New-EC2NetworkInterface -SubnetId subnet-1a2b3c4d -Description "my network interface" -Group sg-12345678 -PrivateIpAddress 10.0.0.17

输出:

Association : Attachment : AvailabilityZone : us-west-2c Description : my network interface Groups : {my-security-group} MacAddress : 0a:72:bc:1a:cd:7f NetworkInterfaceId : eni-12345678 OwnerId : 123456789012 PrivateDnsName : ip-10-0-0-17.us-west-2.compute.internal PrivateIpAddress : 10.0.0.17 PrivateIpAddresses : {} RequesterId : RequesterManaged : False SourceDestCheck : True Status : pending SubnetId : subnet-1a2b3c4d TagSet : {} VpcId : vpc-12345678

有关 AWS SDK开发者指南和代码示例的完整列表,请参阅使用创建 Amazon EC2 资源 AWS SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。