[英]How do I assign an EC2 instance to a fixed IP address within a subnet?
I'm using CloudFormation to define a subnet and EC2 instance.我正在使用 CloudFormation 来定义子网和 EC2 实例。 I want to allocate a particular private IP address to an EC2 instance and have attempted to do so using the resource definitions such as those below.
我想为 EC2 实例分配一个特定的私有 IP 地址,并尝试使用如下所示的资源定义来这样做。
When I try to deploy my template the creation of the NetworkInterface resource fails with the message 'Address is in subnet's reserved address range' .当我尝试部署我的模板时,NetworkInterface 资源的创建失败,并显示消息“地址在子网的保留地址范围内” 。 I've tried to work this out but am not making progress.
我试图解决这个问题,但没有取得进展。 How do I define my subnet with a range of private IP addresses which I can apply to my EC2 instances?
如何使用可应用于我的 EC2 实例的私有 IP 地址范围定义我的子网?
Thanks.谢谢。
Note: The whole template contains other resources and so I've attempted to reduce it to the important components, hence the below is purposely incomplete.注意:整个模板包含其他资源,因此我尝试将其缩减为重要组件,因此以下内容故意不完整。
"SharedVPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.10.0.0/16",
"EnableDnsHostnames": true,
"EnableDnsSupport": true,
"InstanceTenancy": "default"
}
},
"SharedVPCPrivateSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": "eu-west-1a",
"CidrBlock": "10.10.129.0/24",
"MapPublicIpOnLaunch": false,
"VpcId": {
"Ref": "SharedVPC"
}
}
},
"DbServerEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": "WindowsEC2",
"InstanceType": "t2.micro",
"AvailabilityZone": "eu-west-1a",
"ImageId": {
"Ref": "DbServerEC2ImageAMI"
},
"IamInstanceProfile": {
"Ref": "EC2InstanceProfile"
},
"NetworkInterfaces": [{
"NetworkInterfaceId": {
"Ref": "DbServerEC2InstanceNetworkInterface"
},
"DeviceIndex" : "0"
}]
}
},
"DbServerEC2InstanceNetworkInterface": {
"Type": "AWS::EC2::NetworkInterface",
"Properties": {
"Description": "eth0",
"PrivateIpAddresses": [{
"PrivateIpAddress": "10.10.129.2",
"Primary": "true"
},
{
"PrivateIpAddress": "10.10.129.3",
"Primary": "false"
}
],
"SourceDestCheck": "true",
"SubnetId": {
"Ref": "SharedVPCPrivateSubnet1"
}
}
}
AWS reserves the first 4 IP addresses and the last IP of a subnets. AWS 保留子网的前 4 个 IP 地址和最后一个 IP。 These ranges within a subnet are not available.
子网内的这些范围不可用。
The AWS documentation states the following: AWS 文档声明如下:
The first four IP addresses and the last IP address in each subnet CIDR block are not available for you to use, and cannot be assigned to an instance.
每个子网 CIDR 块中的前四个 IP 地址和最后一个 IP 地址不可供您使用,并且不能分配给实例。 For example, in a subnet with CIDR block
10.0.0.0/24
, the following five IP addresses are reserved:例如,在 CIDR 块为
10.0.0.0/24
的子网中,保留以下五个 IP 地址:
10.0.0.0
: Network address.10.0.0.0
:网络地址。10.0.0.1
: Reserved by AWS for the VPC router.10.0.0.1
:AWS 为 VPC 路由器保留。10.0.0.2
: Reserved by AWS.10.0.0.2
保留。 The IP address of the DNS server is the base of the VPC network range plus two.DNS 服务器的 IP 地址是 VPC 网络范围的基础加 2。 For VPCs with multiple CIDR blocks, the IP address of the DNS server is located in the primary CIDR.
对于具有多个 CIDR 块的 VPC,DNS 服务器的 IP 地址位于主 CIDR 中。 We also reserve the base of each subnet range plus two for all CIDR blocks in the VPC.
我们还为 VPC 中的所有 CIDR 块保留每个子网范围的基础加上两个。 For more information, see Amazon DNS server.
有关更多信息,请参阅 Amazon DNS 服务器。
10.0.0.3
: Reserved by AWS for future use.10.0.0.3
:由 AWS 保留以备将来使用。10.0.0.255
: Network broadcast address.10.0.0.255
:网络广播地址。 We do not support broadcast in a VPC, therefore we reserve this address.我们不支持在 VPC 中广播,因此我们保留此地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.