EC2 instance unable to reach itself via hostname - amazon-web-services

I have created an EC2 instance behind an ELB and the hostname is
mysubdomain.domain.com
The instance is reachable via the internet from my local workstation (have opened all connections from My IP --> to the instance in the security group it belongs to);
However, when performing
curl mysubdomain.domain.com
from within the instance, it times out;
Do I need to assign a public (I assume I want it to be elastic so that I don't have to change it every now and then in my security group inbound rules) and add an allow rule in my security group (that the instance belongs to) from that specific IP?
Is there another way to go about it, given that I have reached the limit of Elastic IPs?

For an Amazon EC2 instance to access the Internet, it must either be:
In a public subnet with a public IP address, or
In a private subnet with a NAT Gateway or similar NAT service
By default, security groups allow all outbound traffic, so you will not need to modify the security groups.
Even if you have reached the limit of your Elastic IP addresses, you can launch the EC2 instance with a Public IP address via Auto-assign Public IP — this is different to an Elastic IP address, in that it is assigned when the instance is Started and might change when the instance is Stopped/Started. However, it will work perfectly fine to obtain Internet access.
If an instance is behind a load balancer, there is no reason to want to reach that instance directly from the Internet. Thus, there is no need for an Elastic IP address. In fact, in best-practice architectures, the instances should be in a Private Subnet so that they are better protected from the Internet. This will then require a NAT Gateway or NAT Instance to enable the instance to access the Internet.

Related

EC2 open port for only private IP address

My Linux based EC2 instances have both public and private IPs. I am hosting two servers on it:
S3 server, which will be accessible over both internet/private network and
NFS server, which should be accessed only via private IPs/internal network.
I want to open NFS port in the Security Group but only allow the access over the EC2 instances's private IP. I don't think this can be achieved by using only security groups as when the request reaches EC2 node, the Internet Gateway has already replaced the public IP with the private IP of the EC2 instance and the instance is not even aware that there is an extra public IP associated with it.
Instead what can be done is to choose the sources and selectively allow NFS access only to the VPCs and on-premises network (in case there is a VPN connectivity) but that would also mean that every time a new VPC is created OR a new VPN endpoint is established, someone has to modify the Security Group to accommodate new IP addresses.
What I ideally need is a way to apply port and IP based rules on the Internet Gateway which is currently not available/exported. Looking for alternatives.
The simplest method would be to add an Inbound rule to the Security Group where the Source is the CIDR range of the VPC.
For example, if your VPC is 172.31.0.0/16, then use this as the Source in the security group. It would permit any inbound connection from that IP address range.

aws ec2 public ip from vpc timeout

Is it possible to configure aws vpc/subnet so that the public ip4 addresses are reachable from within the VPC?
At the moment, the ec2 machine's ip4 addresses are reachable from the internet, but timeout when connecting from within the same machine or from another machine on the same subnet.
Quite embarrasing. But maybe this will help someone in the future.
We had a security group assigned to the instances which only allowed specific ips to access http ports. The sec groups also apply to instances within the same subnet, so an access rule from instances with the same security group was added which resolved the problem. Alternatively you can also allow access by private ip, for instance.
So if it ever happens that you need to access localhost via the public ip, access must be allowed by the active security group.

can we connect AWS ec2 instance which is having only private IP with the other ec2 instance with a public IP ? from putty

I have just started my career in the IT field and currently learning new technologies like AWS.
I have a small doubt and it will be really helpful for me if anyone can help me with it.
"Can we connect ec2 instance which is having only private IP with the other ec2 instance with a public IP"
In Putty, I have logged into an EC2 instance (With public IP) and tried to ssh into other EC2 instances (which is having only private IP) by mentioning its private IP Address, but I wasn't able to login to that.
Thank you in advance :)
You can do this (providing security groups and network configuration allows).
The first method (and more prefered) is through a private to private connection, just because an instance has a public IP does not mean it is inaccessible from private inbound connections. If they share the same VPC as long as your security groups/NACLs allow inbound from the private IP range you will be able to connect to the instance via its private IP.
If the instances share a different VPC (or even account) you can connect between using either transit gateway or a single peering connection, then whitelist the IP range of the source. A caveat is that these separate networks cannot be peered if they have a crossover in network address ranges (you would need to create a secondary range to deal with this).
The alternative is to use either a NAT Gateway or NAT instance and then bind this to the route table for your instance for the 0.0.0.0/0 route. You would then need to whitelist in the public instances security group the public EIP of the NAT. This is less preferable as it requires communication across the internet.

Can a the same AWS ElasticIP be shared by a NAT gateway and an EC2 instance in a public subnet?

As described in the aws VPC scenario 2 page I have a VPC with 2 subnets defined - one private and one public. The private subnet uses a NAT gateway for the outbound traffic (the NAT gateway lives in the public subnet). The public subnet uses an internet gateway for inbound and outbound.
The usage of the NAT gateway requires an ElasticIP to be registered and associated with that NAT. Now, I need a public IP for the EC2 instance I have in the public subnet, that remains static even after restarting the instance, where outside traffic can come into. Do I need to register another ElasticIP for that purpose, or can I reuse the same ElasticIP that I already created for the NAT Gateway?
An Elastic IP address can only be registered to one ENI at a single time. When you create it a mapping is formed to resolve the elastic IP address to a single private address on an ENI (be that a NAT Gateway or an EC2 host).
When you associate an Elastic IP address with an instance, it is also associated with the instance's primary network interface. When you associate an Elastic IP address with a network interface that is attached to an instance, it is also associated with the instance.
You will need to create a new one for your EC2 host, by default you can use 5 elastic IP addresses in a region, if you need more than this you would need to contact Amazon to increase your accounts quota.
For more information take a look at the Elastic IP addresses page.

How an EC2 access another EC2 in the same VPC using public IP?

I find this
Can an AWS private IP address server connect to a public IP address server that is in the same VPC?
Both my two EC2s have public IP, and work fine, I have no NAT instance.
How do I
Make sure the security group of the server with public IP accepts inbound traffic from the VPC NAT
Your question is a bit unclear about your current configuration, but let's say you have:
An Amazon VPC with one public subnet
Two instances both in the public subnet
They each have Public IP addresses assigned
Yes, the two instances can communicate directly with each other. It is best that they communicate via the private IP address -- this way, the traffic remains totally within the VPC.
If they communicate via their public IP addresses, then the traffic goes out of the VPC to the AWS edge of the Internet, then back into the VPC. Such traffic is charged at 1c/GB.
All instances within a VPC can communicate directly with each other via their private IP addresses, even if they are in different subnets. However, the Security Group will need to be configured to accept the incoming traffic. This can be configured based on the IP address of the source instance, or by reference to a security group that is associated with the source instance.