[英]Can I use AWS Tools for Powershell to create a new EC2 instance and set the private IP?
Cmdlet: 小命令:
New-EC2Instance -ImageId ami-abcdefg123 -MinCount 1 -MaxCount 1 -KeyName Keypair `
-SecurityGroupId sg-abcdefg -InstanceType m1.small `
-SubnetId subnet-01bd1e76
How can I change this to add a private IP address to this instance? 我该如何更改以向该实例添加私有IP地址? Also, I don't want a public IP address assigned to it.
另外,我也不想为它分配一个公共IP地址。
You should always be assigned a private IP address on instance launch. 在实例启动时,应该始终为您分配一个专用IP地址。 In EC2 classic, this is assigned from the EC2-Classic range every time your instance is started.
在EC2 classic中,每次启动实例时,都会从EC2-Classic范围中分配该值。 In a VPC, this address is static (doesn't reset on stop/start) and comes from the address range of your subnet.
在VPC中,该地址是静态的(在停止/启动时不会重置),并且来自您子网的地址范围。
You can disable public IP assignment, but be aware of the default settings for assignment of Public IPs: 您可以禁用公共IP分配,但是请注意公共IP分配的默认设置:
EC2-Classic: Your instance receives a public IP address.
EC2-Classic:您的实例收到一个公共IP地址。 This behavior cannot be changed.
此行为无法更改。
Default Subnet: Your instance receives a public IP address by default, unless you specify otherwise during launch, or you modify the subnet's public IP address attribute.
默认子网:默认情况下,您的实例默认情况下会收到一个公共IP地址,除非在启动过程中另外指定,或者您修改了子网的公共IP地址属性。
Nondefault Subnet: Your instance doesn't receive a public IP address by default, unless you specify otherwise during launch, or you modify the subnet's public IP address attribute.
非默认子网:除非在启动过程中另外指定,或者修改子网的公共IP地址属性,否则默认情况下,您的实例默认不会收到公共IP地址。
Since you've specified a SubnetId in your New-EC2Instance
I can safely assume you're working in a VPC, and since you're asking this question I can assume that the VPC is configured to set the public IP address by default. 由于您已在
New-EC2Instance
指定了SubnetId, New-EC2Instance
我可以安全地假定您正在使用VPC,并且由于您正在询问此问题,因此我可以假定VPC已配置为默认设置公共IP地址。
In this case, toggling the assignment of a public IP address is as simple as specifying the -AssociatePublicIP
parameter of New-EC2Instance
. 在这种情况下,切换公共IP地址的分配就像指定
New-EC2Instance
的-AssociatePublicIP
参数一样简单。
Example 1: Simply toggle off on EC2 Launch 示例1:只需关闭EC2启动
New-EC2Instance -ImageId ami-abcdefg123 -MinCount 1 -MaxCount 1 -KeyName Keypair `
-SecurityGroupId sg-abcdefg -InstanceType m1.small `
-SubnetId subnet-1a2b3c4d -AssociatePublicIP $false
Example 2: Disable default public IP on all new instances in your subnet. 示例2:在子网中的所有新实例上禁用默认公用IP。 Use -Force when specifying this in a script to skip interactive confirmation.
在脚本中指定此选项时,请使用-Force来跳过交互式确认。
Edit-EC2SubnetAttribute -MapPublicIpOnLaunch $false -SubnetId subnet-1a2b3c4d -Force
Documentation: 文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.