AWS - 在 172.168.0.0/16 CIDR 块中意外创建 VPC,影响?
AWS - Acceidentally created VPC in 172.168.0.0/16 CIDR block, effects?
我们不小心在 172.168.0.0/16 CIDR 块中创建了一个 VPC,我们意识到我们需要更改它,但是,有人知道这样一个问题的不良影响吗?
对本地 ip 的每次调用(如我们所料)实际上会通过互联网进行吗?
我们可以与占用这些 IP 的人发生 IP 冲突吗?
如果有人在此块中拥有 IP,我们的内部流量是否真的可以传到 Internet 上?
编辑:
我们的子网路由表将此范围内的流量路由到本地网络,但我很确定仍然会有不利影响。
VPC 允许您创建 AWS 网络的隔离部分供您自己私人使用。
您可以在您的 VPC 中选择任意范围的 IP 地址(最大大小为 /16)并且不会与其他 AWS 客户的 IP 地址冲突。
默认情况下,VPC 网络不会暴露在 Internet 上。要将子网公开到 Internet,您需要以下内容:
- 将 Internet 网关附加到您的 VPC
- 有一条路由 table 附加到您的子网,其路由规则为“0.0.0.0/0 IGW-ID”(您的互联网网关的 ID)
- 为您的服务(EC2、RDS、ElasticCache...)附加一个 public IP 地址对于 EC2 实例,Public IP 可以在实例启动时自动分配(参数位于子网级别)或之后的任何时候(使用弹性 IP 地址)
现在您的 VPC 已创建,您将无法修改其 IP 地址范围。您将需要创建一个新的 VPC。
VPC 在我们位于 http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Introduction.html
的文档中有详细说明
[更新]
我测试了您使用 publicly routable IP 地址范围创建 VPC 的用例。我确认 - 毫不奇怪 - 您无法连接到使用 VPC 范围内 IP 地址的基于 Internet 的机器(没有主机路由)。此行为是预期的,因为 VPC 正在尝试在本地路由这些地址。
测试详情。
在54.72.0.0/16地址范围内创建一个VPC。
$ aws ec2 describe-vpcs --region us-west-2 --filters Name=tag:Name,Values=test
{
"Vpcs": [
{
"VpcId": "vpc-e5df7680",
"InstanceTenancy": "default",
"Tags": [
{
"Value": "test",
"Key": "Name"
}
],
"State": "available",
"DhcpOptionsId": "dopt-73848e11",
"CidrBlock": "54.72.0.0/16",
"IsDefault": false
}
]
}
在该 VPC 中创建一个 EC2 实例,使用自动分配的 public IP 地址
$ aws ec2 describe-instances --region us-west-2 --query 'Reservations[].Instances[].NetworkInterfaces[?VpcId == `vpc-e5df7680`]'
[
[
{
"Status": "in-use",
"MacAddress": "0a:9c:b1:82:d5:ed",
"SourceDestCheck": true,
"VpcId": "vpc-e5df7680",
"Description": "Primary network interface",
"Association": {
"PublicIp": "54.213.235.16",
"PublicDnsName": "ec2-54-213-235-16.us-west-2.compute.amazonaws.com",
"IpOwnerId": "amazon"
},
"NetworkInterfaceId": "eni-7d37d025",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-54-72-24-135.us-west-2.compute.internal",
"Association": {
"PublicIp": "54.213.235.16",
"PublicDnsName": "ec2-54-213-235-16.us-west-2.compute.amazonaws.com",
"IpOwnerId": "amazon"
},
"Primary": true,
"PrivateIpAddress": "54.72.24.135"
}
],
"PrivateDnsName": "ip-54-72-24-135.us-west-2.compute.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-aaa7e1a2",
"AttachTime": "2015-02-11T19:05:34.000Z"
},
"Groups": [
{
"GroupName": "SSH",
"GroupId": "sg-f2752e97"
}
],
"SubnetId": "subnet-7978bc20",
"OwnerId": "577031028568",
"PrivateIpAddress": "54.72.24.135"
}
],
[]
]
连接到那个实例
$ ssh ec2-user@54.213.235.16
Warning: Permanently added '54.213.235.16' (RSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2014.09-release-notes/
检查私有 IP 地址(范围无效!)
[ec2-user@ip-54-72-24-135 ~]$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 0A:9C:B1:82:D5:ED
inet addr:54.72.24.135 Bcast:54.72.24.255 Mask:255.255.255.0
inet6 addr: fe80::89c:b1ff:fe82:d5ed/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:23418 errors:0 dropped:0 overruns:0 frame:0
TX packets:2930 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33618848 (32.0 MiB) TX bytes:274735 (268.2 KiB)
测试互联网连接
[ec2-user@ip-54-72-24-135 ~]$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=7.75 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=7.81 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=7.79 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2489ms
rtt min/avg/max/mdev = 7.756/7.790/7.815/0.024 ms
[ec2-user@ip-54-72-24-135 ~]$ curl -I www.stormacq.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Date: Wed, 11 Feb 2015 19:23:04 GMT
Server: Apache/2.4.10 (Amazon) PHP/5.5.20
X-Powered-By: PHP/5.5.20
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
Vary: Accept-Encoding,Cookie
X-Cache: Miss from cloudfront
Via: 1.1 4f4f94bdda0837b3f79484c70f2d1348.cloudfront.net (CloudFront)
X-Amz-Cf-Id: us5_V9oNZak_8WAqsbBu6q9wNm4A0S6VRXGu10nDoQnWS5PYnVMwgg==
有效!
现在,使用与我们的 VPC 相同的 ip 地址测试与互联网机器的连接
[ec2-user@ip-54-72-24-135 ~]$ ssh 54.72.24.171
ssh: connect to host 54.72.24.171 port 22: No route to host
[ec2-user@ip-54-72-24-135 ~]$ sudo traceroute 54.72.24.171
traceroute to 54.72.24.171 (54.72.24.171), 30 hops max, 60 byte packets
1 ec2-54-72-24-135.eu-west-1.compute.amazonaws.com (54.72.24.135) 2997.785 ms !H 2997.769 ms !H 2997.765 ms !H
失败。
我们不小心在 172.168.0.0/16 CIDR 块中创建了一个 VPC,我们意识到我们需要更改它,但是,有人知道这样一个问题的不良影响吗?
对本地 ip 的每次调用(如我们所料)实际上会通过互联网进行吗?
我们可以与占用这些 IP 的人发生 IP 冲突吗?
如果有人在此块中拥有 IP,我们的内部流量是否真的可以传到 Internet 上?
编辑:
我们的子网路由表将此范围内的流量路由到本地网络,但我很确定仍然会有不利影响。
VPC 允许您创建 AWS 网络的隔离部分供您自己私人使用。
您可以在您的 VPC 中选择任意范围的 IP 地址(最大大小为 /16)并且不会与其他 AWS 客户的 IP 地址冲突。
默认情况下,VPC 网络不会暴露在 Internet 上。要将子网公开到 Internet,您需要以下内容:
- 将 Internet 网关附加到您的 VPC
- 有一条路由 table 附加到您的子网,其路由规则为“0.0.0.0/0 IGW-ID”(您的互联网网关的 ID)
- 为您的服务(EC2、RDS、ElasticCache...)附加一个 public IP 地址对于 EC2 实例,Public IP 可以在实例启动时自动分配(参数位于子网级别)或之后的任何时候(使用弹性 IP 地址)
现在您的 VPC 已创建,您将无法修改其 IP 地址范围。您将需要创建一个新的 VPC。
VPC 在我们位于 http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Introduction.html
的文档中有详细说明[更新]
我测试了您使用 publicly routable IP 地址范围创建 VPC 的用例。我确认 - 毫不奇怪 - 您无法连接到使用 VPC 范围内 IP 地址的基于 Internet 的机器(没有主机路由)。此行为是预期的,因为 VPC 正在尝试在本地路由这些地址。
测试详情。
在54.72.0.0/16地址范围内创建一个VPC。
$ aws ec2 describe-vpcs --region us-west-2 --filters Name=tag:Name,Values=test
{
"Vpcs": [
{
"VpcId": "vpc-e5df7680",
"InstanceTenancy": "default",
"Tags": [
{
"Value": "test",
"Key": "Name"
}
],
"State": "available",
"DhcpOptionsId": "dopt-73848e11",
"CidrBlock": "54.72.0.0/16",
"IsDefault": false
}
]
}
在该 VPC 中创建一个 EC2 实例,使用自动分配的 public IP 地址
$ aws ec2 describe-instances --region us-west-2 --query 'Reservations[].Instances[].NetworkInterfaces[?VpcId == `vpc-e5df7680`]'
[
[
{
"Status": "in-use",
"MacAddress": "0a:9c:b1:82:d5:ed",
"SourceDestCheck": true,
"VpcId": "vpc-e5df7680",
"Description": "Primary network interface",
"Association": {
"PublicIp": "54.213.235.16",
"PublicDnsName": "ec2-54-213-235-16.us-west-2.compute.amazonaws.com",
"IpOwnerId": "amazon"
},
"NetworkInterfaceId": "eni-7d37d025",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-54-72-24-135.us-west-2.compute.internal",
"Association": {
"PublicIp": "54.213.235.16",
"PublicDnsName": "ec2-54-213-235-16.us-west-2.compute.amazonaws.com",
"IpOwnerId": "amazon"
},
"Primary": true,
"PrivateIpAddress": "54.72.24.135"
}
],
"PrivateDnsName": "ip-54-72-24-135.us-west-2.compute.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-aaa7e1a2",
"AttachTime": "2015-02-11T19:05:34.000Z"
},
"Groups": [
{
"GroupName": "SSH",
"GroupId": "sg-f2752e97"
}
],
"SubnetId": "subnet-7978bc20",
"OwnerId": "577031028568",
"PrivateIpAddress": "54.72.24.135"
}
],
[]
]
连接到那个实例
$ ssh ec2-user@54.213.235.16
Warning: Permanently added '54.213.235.16' (RSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2014.09-release-notes/
检查私有 IP 地址(范围无效!)
[ec2-user@ip-54-72-24-135 ~]$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 0A:9C:B1:82:D5:ED
inet addr:54.72.24.135 Bcast:54.72.24.255 Mask:255.255.255.0
inet6 addr: fe80::89c:b1ff:fe82:d5ed/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:23418 errors:0 dropped:0 overruns:0 frame:0
TX packets:2930 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33618848 (32.0 MiB) TX bytes:274735 (268.2 KiB)
测试互联网连接
[ec2-user@ip-54-72-24-135 ~]$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=7.75 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=7.81 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=7.79 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2489ms
rtt min/avg/max/mdev = 7.756/7.790/7.815/0.024 ms
[ec2-user@ip-54-72-24-135 ~]$ curl -I www.stormacq.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Date: Wed, 11 Feb 2015 19:23:04 GMT
Server: Apache/2.4.10 (Amazon) PHP/5.5.20
X-Powered-By: PHP/5.5.20
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
Vary: Accept-Encoding,Cookie
X-Cache: Miss from cloudfront
Via: 1.1 4f4f94bdda0837b3f79484c70f2d1348.cloudfront.net (CloudFront)
X-Amz-Cf-Id: us5_V9oNZak_8WAqsbBu6q9wNm4A0S6VRXGu10nDoQnWS5PYnVMwgg==
有效!
现在,使用与我们的 VPC 相同的 ip 地址测试与互联网机器的连接
[ec2-user@ip-54-72-24-135 ~]$ ssh 54.72.24.171
ssh: connect to host 54.72.24.171 port 22: No route to host
[ec2-user@ip-54-72-24-135 ~]$ sudo traceroute 54.72.24.171
traceroute to 54.72.24.171 (54.72.24.171), 30 hops max, 60 byte packets
1 ec2-54-72-24-135.eu-west-1.compute.amazonaws.com (54.72.24.135) 2997.785 ms !H 2997.769 ms !H 2997.765 ms !H
失败。