AWS 创建 vpc 并启动实例
AWS create vpc and launch instance
我正在尝试启动一个 ec2 实例并通过 ssh 登录。我不小心删除了 deafaul vpc,因此从头开始创建了一个 vpc 来执行此操作。我创建了一个 VPC,其中 10.0.0.0/16 VPC CIDR 和 10.0.0.0/24 作为子网,还创建了一个网关。 A也修改了路由table到这个
10.0.0.0/16 本地
0.0.0.0/0 igw-xxxx
我选择了一个 ubuntu ami 并在我的 vpc 中启动它并为实例分配了一个弹性 ip。
我为我的实例分配了一个 public ip,安全组也打开了端口 22。我能够 ping 这个 public ip 但是当我尝试使用
ssh 进入 ec2 实例时
ssh -i access.pem ubuntu@public.ip
我的连接超时,我是否遗漏了配置中的任何内容?
最近也在玩这样的配置。下面是我的笔记(这对我有用),检查你是否没有遗漏什么。如果您可以 ping 实例 IP,但无法通过 ssh 连接,则安全组似乎有问题。我也会检查不同的 AMI。
创建VPC
$ vpcId=`aws ec2 create-vpc --cidr-block 10.0.0.0/24 --query 'Vpc.VpcId' --output text` $$ echo $vpcId
vpc-xxxxxxxx
在VPC内启用DNS解析
$ aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-support "{\"Value\":true}"
$ aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-hostnames "{\"Value\":true}"
为创建的 VPC 创建默认网关
$ internetGatewayId=`aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text` && echo $internetGatewayId
igw-yyyyyyy
$ aws ec2 attach-internet-gateway --internet-gateway-id $internetGatewayId --vpc-id $vpcId
在 VPC 中创建子网
$ subnetId=`aws ec2 create-subnet --vpc-id $vpcId --cidr-block 10.0.0.0/24 --query 'Subnet.SubnetId' --output text` && echo $subnetId
subnet-zzzzzzz
配置路由table
$ routeTableId=`aws ec2 create-route-table --vpc-id $vpcId --query 'RouteTable.RouteTableId' --output text` && echo $routeTableId
$ aws ec2 associate-route-table --route-table-id $routeTableId --subnet-id $subnetId
$ aws ec2 create-route --route-table-id $routeTableId --destination-cidr-block 0.0.0.0/0 --gateway-id $internetGatewayId
创建安全组并向任何连接开放端口 22
$ securityGroupId=`aws ec2 create-security-group --group-name ec2-dev-secgroup --description "security group" --vpc-id $vpcId --query 'GroupId' --output text` && echo $securityGroupId
sg-xyzyzyz
$ aws ec2 authorize-security-group-ingress --group-id $securityGroupId --protocol tcp --port 22 --cidr 0.0.0.0/0
创建 ssh 密钥
aws ec2 create-key-pair --key-name ec2-dev --query 'KeyMaterial' --output text > ~/.ssh/ec2-dev.pem
chmod 400 ~/.ssh/ec2-dev.pem
创建 EC2 实例
$ instanceId=`aws ec2 run-instances --image-id ami-ecd5e884 --count 1 --instance-type t2.micro --key-name ec2-dev --security-group-ids $securityGroupId --subnet-id $subnetId --associate-public-ip-address --query 'Instances[0].InstanceId' --output text`
ssh -i .ssh/ec2-dev.pem ec2-user@52.x.y.z
我正在尝试启动一个 ec2 实例并通过 ssh 登录。我不小心删除了 deafaul vpc,因此从头开始创建了一个 vpc 来执行此操作。我创建了一个 VPC,其中 10.0.0.0/16 VPC CIDR 和 10.0.0.0/24 作为子网,还创建了一个网关。 A也修改了路由table到这个
10.0.0.0/16 本地
0.0.0.0/0 igw-xxxx
我选择了一个 ubuntu ami 并在我的 vpc 中启动它并为实例分配了一个弹性 ip。
我为我的实例分配了一个 public ip,安全组也打开了端口 22。我能够 ping 这个 public ip 但是当我尝试使用
ssh 进入 ec2 实例时ssh -i access.pem ubuntu@public.ip
我的连接超时,我是否遗漏了配置中的任何内容?
最近也在玩这样的配置。下面是我的笔记(这对我有用),检查你是否没有遗漏什么。如果您可以 ping 实例 IP,但无法通过 ssh 连接,则安全组似乎有问题。我也会检查不同的 AMI。
创建VPC
$ vpcId=`aws ec2 create-vpc --cidr-block 10.0.0.0/24 --query 'Vpc.VpcId' --output text` $$ echo $vpcId
vpc-xxxxxxxx
在VPC内启用DNS解析
$ aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-support "{\"Value\":true}"
$ aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-hostnames "{\"Value\":true}"
为创建的 VPC 创建默认网关
$ internetGatewayId=`aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text` && echo $internetGatewayId
igw-yyyyyyy
$ aws ec2 attach-internet-gateway --internet-gateway-id $internetGatewayId --vpc-id $vpcId
在 VPC 中创建子网
$ subnetId=`aws ec2 create-subnet --vpc-id $vpcId --cidr-block 10.0.0.0/24 --query 'Subnet.SubnetId' --output text` && echo $subnetId
subnet-zzzzzzz
配置路由table
$ routeTableId=`aws ec2 create-route-table --vpc-id $vpcId --query 'RouteTable.RouteTableId' --output text` && echo $routeTableId
$ aws ec2 associate-route-table --route-table-id $routeTableId --subnet-id $subnetId
$ aws ec2 create-route --route-table-id $routeTableId --destination-cidr-block 0.0.0.0/0 --gateway-id $internetGatewayId
创建安全组并向任何连接开放端口 22
$ securityGroupId=`aws ec2 create-security-group --group-name ec2-dev-secgroup --description "security group" --vpc-id $vpcId --query 'GroupId' --output text` && echo $securityGroupId
sg-xyzyzyz
$ aws ec2 authorize-security-group-ingress --group-id $securityGroupId --protocol tcp --port 22 --cidr 0.0.0.0/0
创建 ssh 密钥
aws ec2 create-key-pair --key-name ec2-dev --query 'KeyMaterial' --output text > ~/.ssh/ec2-dev.pem
chmod 400 ~/.ssh/ec2-dev.pem
创建 EC2 实例
$ instanceId=`aws ec2 run-instances --image-id ami-ecd5e884 --count 1 --instance-type t2.micro --key-name ec2-dev --security-group-ids $securityGroupId --subnet-id $subnetId --associate-public-ip-address --query 'Instances[0].InstanceId' --output text`
ssh -i .ssh/ec2-dev.pem ec2-user@52.x.y.z