Connection to amazon-ec2 VPC instance fails - amazon-ec2

I have the following setup:
- a VPC, with several subnets, and an access gateway and a NAT instance having public addresses that I can connect to,
- I create a Linux instance in a subnet of the VPC, that has NO public IP address or DNS name (I want that only the Load Balancer be known on the internet).
I want to connect to my Linux instance to install and configure software.
How do you connect to that instance? All the documentation I have seen mentions that you connect using "ec2-user#".
Since I have no public DNS, i have tried to connect from the access gateway via putty with the private DNS of my linux instance but it fails ("host does not exist").
I am obviously missing something ... in the NAT?
Thanks, Laurent

You need to have a hosts in the public subnet which you can access. Once you access this host, then you can connect to your other hosts in VPC using their private IP address.
Your instance in question has only private IP address so connecting it from your workstation is not going to work.
The host I am referring to is usually called Bastion Host. read the Tip in Scenario 2: VPC with Public and Private Subnets documentation.
Also, read first few results of this Google Search to gain overall understanding on use-cases for Bastion hosts.

Related

Two similar instances with different internet access availabilities

I have created one ec2 centos instance and then launched another one from that but in the second one , I have disables the public IP so it doesn't have a public IP address.
The instances are in same subnet having the same security group, and roles. The first instance have ínternet access but the second one doesn't have. Is this related to assigning a public IP?
How can I have internet access in an instance without a public IP?
You have two options here:
[1] The first option is to use Elastic IP: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html
[2] If you want to have an Internet access without public IP, you need to provision a NAT Gateway and configure route to it.
People generally do this, they create a VPC, create two subnet in it (one Public and One Private), in the Private subnet they launch their instances, and in the public subnet they create a NAT Gateway, and configure the route in the route table so that the instances in the private subnet have a route to internet via NAT Gateway.
[1] NAT Gateway: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html
Instances without public IP addresses can access the Internet in one of two ways:
Instances without public IP addresses can route their traffic through a NAT gateway or a NAT instance to access the Internet. These instances use the public IP address of the NAT gateway or NAT instance to traverse the Internet. The NAT gateway or NAT instance allows outbound communication but doesn’t allow machines on the Internet to initiate a connection to the privately addressed instances.
For VPCs with a hardware VPN connection or Direct Connect connection, instances can route their Internet traffic down the virtual private gateway to your existing datacenter. From there, it can access the Internet via your existing egress points and network security/monitoring devices.

Should an AWS EC2 instance connect using only IPv4 Public IP?

If I put the "IPv4 Public IP" of my EC2 instance in the browsers address shouldnt it connect and return an error message instead of just giving time out ?
So, it sounds like you are attempting to connect to the instance via SSH.
Things to check:
The Security Group associated with the instance needs to have port 22 open to either your Public IP address, or to 0.0.0.0/0 (which is not a good security practice)
You are on a network that is not blocking SSH traffic. Some corporate network prohibit such access (so try it from home).
The instance is running an SSH server. This is standard on Linux distributions, such as the Amazon Linux AMI. (Believe it or not, some people wonder why they can't SSH to a Windows instance.)
You should be trying to connect to a public IP address associated with the instance
The instance needs to be in a Public Subnet (which means the Route Table associated with the Subnet is pointing 0.0.0.0/0 traffic to an Internet Gateway). If you are using the Default VPC, then this is done for you.
You have the private half of the keypair that was nominated when the instance was launched. If you are using an Amazon Linux instance, the private half of the keypair would have been automatically copied to: /home/ec2-user/.ssh/authorized_keys
The fact that your connection is timing-out, as opposed to receiving an error message, most likely makes it an incorrectly configured Security Group. (Trust me, it's almost always the Security Group!)

Unable to telnet to a VPC instance - AWS

I am trying to connect to a particular port from another AWS instance. Getting connection refused.
In the AWS instance, I have added port 11626 in inboud rules under security groups. Also, I can check port 11626 is listening and I can do self telnet using localhost.
However when I do a self telnet using public/private IP, it is saying connection refused. Is the natting between Public and private IP missing? If yes How do i map these IP?
Are you connecting the AWS instance over the public Internet? Also, how are you connecting to the instance?
Basically, to be able to connect to AWS instance, you need to have the following:
A Public IP assigned to the AWS EC2 instance. You can't connect to an instance using Private IP unless you have VPN which is generally set up for an organisation.
Open the desired port (in your case port 11626). You can open this desired port for the entire public (0.0.0.0/0) or you can specify public IP address in the security group.
If you already created your EC2 instance without getting a public IP address assigned, you can request for allocation of a new Elastic IP address and assign it to your EC2 instance and connect using the Elastic IP address.

Amazon RDS Endpoint internal

How can I make ec2 instance communicate with rds instance on aws by internal ip address or dns?
I only see public dns like xxx.cehmrvc73g1g.eu-west-1.rds.amazonaws.com:3306
Will internal ipaddress will be faster than public dns?
Thanks
A note for posterity, ensure that you enable DNS on the VPC Peering link!
Enabling DNS Resolution Support for a VPC Peering Connection
To enable a VPC to resolve public IPv4 DNS hostnames to private IPv4
addresses when queried from instances in the peer VPC, you must modify
the peering connection.
Both VPCs must be enabled for DNS hostnames and DNS resolution.
To enable DNS resolution support for the peering connection
Open the Amazon VPC console at https://console.aws.amazon.com/vpc/.
In the navigation pane, choose Peering Connections.
Select the VPC peering connection, and choose Actions, Edit DNS
Settings.
To ensure that queries from the peer VPC resolve to private IP
addresses in your local VPC, choose the option to enable DNS
resolution for queries from the peer VPC.
If the peer VPC is in the same AWS account, you can choose the option
to enable DNS resolution for queries from the local VPC. This ensures
that queries from the local VPC resolve to private IP addresses in the
peer VPC. This option is not available if the peer VPC is in a
different AWS account.
Choose Save.
If the peer VPC is in a different AWS account, the owner of the peer
VPC must sign into the VPC console, perform steps 2 through 4, and
choose Save.
You can use the "Endpoint" DNS name. It will resolve to the internal IP when used within the VPC and resolves to a public ip when used outside of your AWS network. You should never use the actual IP address because the way the RDS works it could possibly change in the future.
If you ping it from your EC2 (on the same VPC) server you can verify this.
It is amazing to see the amount of down votes I've got given that my answer is the only correct answer, here is 2 other sources:
https://forums.aws.amazon.com/thread.jspa?threadID=70112
You can use the "Endpoint" DNS name. It will resolve to the internal IP when used within EC2.
https://serverfault.com/questions/601548/cant-find-the-private-ip-address-for-my-amazon-rds-instance2
The DNS endpoint provided in the AWS console will resolve to the internal IPs from within Amazon's network.
Check out the AWS EC2 docs: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#concepts-private-addresses.
It doesn't appear that this necessarily applies to RDS, however.
When resolving your RDS instance from within the same VPC the internal IP is returned by the Amazon DNS service.
If the RDS instance is externally accessible you will see the external IP from outside the VPC. However, if the EC2 instance NOT available publiclly the internal IP address is returned to external and internal lookups.
Will internal ip address will be faster than the external address supplied by public dns?
Most likely as the packets will need to be routed when using the external addresses, increasing latency.
It also requires that your EC2 instances have a public IP or NAT gateway along with appropriate security groups and routes, increasing cost, increasing complexity and reducing security.
its pretty easy, telnet your RDS endpoint using command prompt on windows or through unix terminal
for example: telnet "you RDS endpoint" "Port"
trying to connect "You get your RDS internal IP here"

Are EIP's required for internet traffic?

Sorry if this is a dumb question but I can't find any definitive answers. I setup a VPC with a private subnet and a public subnet. THe private subnet has a NAT'd instance to route for internet traffic. The public subnet is configured to go out of the IGW.
-I created a Bastion host to login into SSH
-I created Test instance on private subnet and connect from Bastion Host. Because of the route to the NAT instance and port 80/443 is allowed and ICMP, i can ping and access files on the internet.
-I create instance on public subnet without EIP. Since it has a route to the IGW, shouldn't I have internet access? I created a test security group to allow all traffic from all sources and i still can't ping or get http links.
A public subnet instance with a public DNS name should be accessible over the internet provided you have right VPC security group configured. You do not need an EIP.
Public DNS name of EC2 instance changes when you stop and start the instance. to avoid this, you can assign an EIP to the instance so that the IP address remains same across the instance stop/start cycles.
You need to answer these questions:
Does your public subnet instance has a public DNS hostname? Run curl -s http://169.254.169.254/latest/meta-data/public-hostname on your instance to see the public DNS hostname.
Do you have VPC security group configured properly to allow incoming internet access ?

Resources