简体   繁体   English

我可以使用AWS Tools for Powershell创建新的EC2实例并设置私有IP吗?

[英]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.

相关问题 如何使用powershell获取EC2实例公网IP和私有IP地址? 并列出这些实例的 IP - How to use powershell to get EC2 instance public IP and private IP address? And list the IPs for these instances AWS ec2实例标记名称Powershell - AWS ec2 instance tag names Powershell AWS Powershell 命令检索附加到 EC2 实例的所有辅助私有 IP - AWS Powershell command to retrieve all secondary private IPs attached to EC2 instance 如何通过Powershell中的IAM角色过滤AWS实例并获取该实例的私有IP地址? - How can I filter AWS Instances by IAM role in powershell and get the private ip address of that instance? 使用AWS Powershell工具启动/停止AWS EC2实例 - Starting/Stopping AWS EC2 Instances using AWS Powershell Tools AWS EC2通过PowerShell / CMD工具停止所有操作 - AWS EC2 stop all through PowerShell/CMD tools 使用 AWS PowerShell 向 AWS EC2 实例添加标签? - Add tag to an AWS EC2 instance using AWS PowerShell? AWS ec2 run-instances 命令在 PowerShell 中创建具有多个安全组的实例 - AWS ec2 run-instances command to create the instance with multiple security groups in PowerShell 如何在PowerShell中将EC2实例启动到具有公共IP地址的VPC中? - How to launch an EC2 instance into a VPC with a public IP address in PowerShell? 使用 Z2F2D399F0EA88448339FE5514B304 为 Windows EC2 实例配置 static IP 地址 - Configuring static IP address for Windows EC2 instance using powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM