Creating two EC2 Instances with the same public IP - amazon-web-services

I am trying to emulate an environment where two computers are connected to the same network using EC2 instances.
I tried creating a VPC with a public and private subnets. I connected a NAT gateway to the private subnet and then created an instance in private subnet and it doesn't seem to have public ip. Is there another way to approach to create this environment

private subnet and it doesn't seem to have public ip.
That's correct. Instances in private subnets do not have public IP. However, they do access the internet through NAT which as a single public IP. This means that for any external API/service, the two instance will seem to have same IP address.

You can use a Load Balancer as the public interface and a auto scaling to scale to 2 instances of ec2

Related

pass traffic between private and and public subnet by Nat Gateway

is it possible to pass traffic between one resource in private subnet and another one in public subnet?
for example; the caching servers in front of NLB. the NLB is in public subnet and the cache instances are in private subnet with NAT gateway.
All resources within the same AWS VPC can communicate with each other. It doesn't matter if some of them are Public or Private subnets, they can all communicate with each other.
You should use the private IP address to communicate with another resource in the same VPC.

AWS Public Subnet Internet Access for Non Public IP Instances

I have a public subnet in AWS and I have 3 instances in it ...
WebApp01 (Elastic IP - 54.23.61.239 for example)
WebApp02 (Private IP - 192.168.0.24)
WebApp03 (Private IP - 192.168.0.25)
And my route table is setup as
192.168.0.0/16 -> local
0.0.0.0/0 -> Internet Gateway
I can see that the instance that has the public IP has internet access but the instances that don't have public IP are not able to access the internet.
How can I give internet access to the other instances inside the Public Subnet ?
I'm a newbie in networking and any help will be appreciated.
Just FYI : I know that creating a NAT, and then creating a separate route table with 0.0.0.0 -> NAT and associating that route with the Private Subnet gives internet access to the instances in the private subnet, but I cant figure out how to give internet access to the non public IP instances in the public subnet. Please help !
You will need to assign public IP addresses to your instances that do not have one or add an EIP in order for them to access the Internet.
An AWS Internet Gateway is a special type of NAT Gateway (1 - 1 address mapping). Without a public IP address there is nothing for the Internet Gateway to map to the EC2 instance - one public IP maps to one private IP inside the Internet Gateway.
Although you add a NAT Gateway to a public subnet with an Internet Gateway,
the NAT Gateway does provide address translation (NAT) to instances in the public subnet - only to instances in the private subnets. The default route in each private subnet points to the NAT Gateway.
If you want these instances to be protected by only having private IP addresses then you will need to move the instances to a private subnet (one with a NAT Gateway).
An instance in a public subnet without a public IP address is orphaned from the Internet. The instance can talk to other instances in the VPC (the Intranet) but cannot talk to the Internet.
There is a lot of confusion on what are AWS VPC subnets. There are three types. 1) Public subnet (one that has an IGW). 2) Private subnet (one that has a NAT Gateway or NAT instance, or neither). 3) Hybrid (one that has a VGW routing to a data center or similar).

Public Subnet is not created in one VPC

I have created a VPC with CIDR 10.0.0.0/16. Then in that VPC, I wanted to create two public subnets. So I have created two subnets with CIDR 10.0.1.0/24 and 10.0.2.0/24.
Now I have launched two EC2 instances on these subnets but I am not getting public IP of both the Instances. Please help me understand why I am not getting public IP of these instances and what should I do to get the public IP of these instances.
To get a public IP address you either
specify a flag on the subnet (in cli it's MapPublicIpOnLaunch, in the console I don't recall where) you want a public address by default on the EC2 instances
explicitly specify you want a public IP when launching an EC2 instance (on the screen you select the vpc and subnets)
assign an elastic IP address to an instance
and do not forget to create a default routing on the subnet to the internet gateway

Amazon EC2: instace in public subnetwork without public IP vs instance in private subnetwork

I have a VPC created according to scenario 2: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html
When creating an instance in the public subnet, I'm given the choice of:
1- Not associating a public IP to the instance
2- Associating a public IP that can change when the instance is restarted
3- Associating an Elastic IP
My question is: what is the difference, security-wise, between creating an instance in the public subnet but without a public IP (option 1) and creating the instance in the private subnet? I know that private instances are behind a NAT, but does this really add a relevant layer of security? Wouldn't I be as protected with a public instance without a public IP belonging to a sound security group?
Check out this answer about the difference between private and public subnets in AWS.
In short, the distinction is at the networking layer with the resulting security posture being similar. The instance on the public subnet without a publicly routable address will not be able to receive inbound connections nor make outbound connections without an attached EIP address -- even if the security group would otherwise allow it. (So, for example, you'd have to attach an EIP just to SSH into the instance.) In effect, it's a blanket block whereas the NAT allows you to fine tune access like you would normally expect.
You can also read more about instance addressing in the AWS User Guide.

My EC2 instance has a Public IP but don't have a Public DNS

I created a new VPC called testglobal with 2 subnets: opennet, closednet
So I created EC2 instances on those subnets and now I can't ping them.
In EC2 panel it shows the Public IP but don't shows Public DNS.
They are all associated to ElasticIPs and added to a group with All Traffic IN/OUT.
Am I doing something wrong?
EC2 instances in your public subnet (what you've called opennet) will have a public DNS and a public IP address. You will only be able to ping them if they are in a security group that allows ICMP echo requests from your client-side IP address.
Instances in your private subnet (closednet) will not have public IP addresses or public DNS names. They will only have private addresses within the range of your subnets. That is the intent of a private subnet - to not allow direct public Internet traffic. Access systems in the private subnets only from the instance in public subnets, or alternatively via VPN.
More specific advice would require further information, like screenshots of the instance, subnet, route table and security group details.