gpt4 book ai didi

amazon-web-services - 如何将 EC2 实例分配给子网内的固定 IP 地址?

转载 作者:行者123 更新时间:2023-12-04 16:25:57 29 4
gpt4 key购买 nike

我正在使用 CloudFormation 定义子网和 EC2 实例。我想为 EC2 实例分配特定的私有(private) IP 地址,并尝试使用如下资源定义来实现此目的。

当我尝试部署模板时,NetworkInterface 资源的创建失败,并显示消息“地址位于子网的保留地址范围内”。我试图解决这个问题,但没有取得进展。如何使用可应用于我的 EC2 实例的一系列私有(private) IP 地址定义我的子网?

谢谢。

注意:整个模板包含其他资源,因此我尝试将其缩减为重要组件,因此下面的内容故意不完整。

"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 保留子网的前 4 个 IP 地址和最后一个 IP 地址。子网内的这些范围不可用。

AWS documentation声明如下:

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. For example, in a subnet with CIDR block 10.0.0.0/24, the following five IP addresses are reserved:

  • 10.0.0.0: Network address.
  • 10.0.0.1: Reserved by AWS for the VPC router.
  • 10.0.0.2: Reserved by AWS. The IP address of the DNS server is the base of the VPC network range plus two. For VPCs with multiple CIDR blocks, the IP address of the DNS server is located in the primary CIDR. We also reserve the base of each subnet range plus two for all CIDR blocks in the VPC. For more information, see Amazon DNS server.
  • 10.0.0.3: Reserved by AWS for future use.
  • 10.0.0.255: Network broadcast address. We do not support broadcast in a VPC, therefore we reserve this address.

关于amazon-web-services - 如何将 EC2 实例分配给子网内的固定 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64212709/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com