Unable to telnet to a VPC instance - AWS - amazon-ec2

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.

Related

Unable to ssh into private subnet using Elastic IP

I have setup a VPC with 2 subnets. One of them is public other one is private.
I am able to ssh from an instance in public subnet to an instance in private subnet using the private IP address of machine. However, if I use the elastic IP address of private instance, the connection times out.
For example, lets call EC2 instance in public subnet as "PUB" and instance in private subnet as PRV.
PRV has Elastic IP say "EIP" and private address, say PRV_IP.
When I ssh from public instance to private one using the private IP address, connection is successful, however if I use private IP, connection fails.
That is,
ssh -i private_key ec2-user#EIP (succeeds).
ssh -i private_key ec2-user#PRV_IP (fails, connection timesout).
Can someone explain me why connection is failing with elastic IP?
As you have seen, attaching Elastic IPs to an instance in private subnet is a worthless exercise. This happens because each subnet can have exactly one default route and that will either point to the igw object (public subnet) or the NAT instance/gateway(private subnet).
If you are binding an elastic IP to a machine in the private subnet, the inbound traffic would arrive at the instance, but the outbound reply traffic would be routed back through the NAT instance, which would discard it.
That's why when you are trying to do SSH, your client machine is able to send a request to the instance but the instance is not returning back the response, hence the timeout.

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!)

Can't connect to RDS from EC2 using terraform created infrastructure

I created the infrastructure manually following the steps provided in the link: connecting-to-a-database-within-an-amazon-vpc.
I could connect to RDS in private subnet from ec2 in public subnet perfectly. That is exactly what I wanted.
But when I tried to create the same exact replica using terraform, it just doesn't connect.
The command:
nslookup <my-hostname>
gives me the Private IP.
The command:
telnet x.x.x.x 5432
results in "telnet: Unable to connect to remote host: Connection timed out"
The command:
netstat -an | grep x.x.x.x
shows "SYN_SENT".
I tried allowing all the IP's in RDS security group by adding 0.0.0.0/0. That didn't work.
I tried to create RDS instance manually, but added it to terraform created VPC and tried to connect using terraform created ec2 instance. That didn't work.
Am i missing something ? Any help is much appreciated.
troubleshooting steps:
Check security group's egress (outbound rules) on your public ec2 instance,
Make sure it allows outbound rules with port 5432 to access rds (which is in private subnets)
Check security group's ingress (inbound rules) on your rds instance. Maybe sure it allows port 5432 from public ec2 instances CIDR ips or security groups.
If not, please update your terraform codes according.
The ec2 instance is in public subnet. That would mean ideally traffic would go from NAT Gateways. So I would suggest to edit the security group rule of RDS add a rule to allow public IPs of NAT Gateways to be accessible on the port 5432.

Connection to amazon-ec2 VPC instance fails

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.

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