EADDRNOTAVAIL while using EC2 instance only - node.js

My node application is listening to port 8080. When I add
app.listen(port,'50.30.217.289');
I can access the application from the browser. But when I replace the IP address with the Elastic IP address of my EC2 instance, I get an error :
EADDRNOTAVAIL
How do I fix this ?

What you are trying to do is not how it works in EC2.
The public IP address is mapped to the primary private IP address through network address translation (NAT).
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
If you examine your network interfaces on the machine, you won't find any public IP addresses on them. The public IP addresses are translated onto the private addresses at the Internet gateway. This is done automatically with no configuration needed, for instances with public IP addresses.
To bind a service to a specific public address, you bind it to the matching private IP address on the instance itself.

EADDRNOTAVAIL means your EC2 instance does not have a network interface that has that IP address assigned, so you cannot start listening on it.

Related

Sticky Elastic IP on AWS EC2

A specific 'Elastic IP' is always associated with the EC2 instance launched from one of my custom AWS AMI.
ubuntu#ip-:~$ sudo ip addr show lo
inet 157.XX.XX.235/32 scope global lo
It is also persistent across server restarts. Can't find any configuration for the elastic IP in /etc/network/interfaces.
Is this setting coming from EC2 instance metadata and cloud-init? Couldn't find anything in /var/log/ as well. There is no user supplied user_data.
Elastic IP addresses exist within the VPC networking layer and are used by Internet Gateways.
When traffic enters a VPC with an Elastic IP address as the destination, the Internet Gateway performs a reverse NAT and translates the public IP address into a private IP address within the VPC. The EC2 instance receives the request on its public IP.
When traffic sent from an instance with an Elastic IP, the traffic comes 'from' the private IP address, but it is translated into the public IP address when it goes through the Internet Gateway.
So, an Amazon EC2 instance is never actually aware of its public IP address. It only sees traffic via its private IP address. This has the benefit that the Elastic IP address can be reassociated with another EC2 instance and no configuration changes are required on the old or new instances. It's magic!
I'm not familiar with the command you are using. When I run it on an Amazon Linux instance that has an Elastic IP address, the command does not show the public IP address of the instance. Perhaps this is different on Ubuntu, so somebody has configured it somewhere on the instance (which they should not do, since it could change through reassociation).

vpn and mproto proxy assign their access to azure private ip and not public ip

i want to set mtproto on my ubuntu AZURE but everytime make mtproto it only run in private ip and not public ip Started as [privateip:-****:***:**********] how can i delete private ip in azure and only use public ip or solve this problem thanks
You can not remove the private IP but you can assign a public IP for your Azure VM to make traffic go inside or outside of azure.
Firstly, you could assign a public IP via this flow on the portal: virtual machine-networking-network interface-IP configurations-click the IP version-enable the public IP for this NIC, then save it.
Secondly, edit the configuration options.txt file, set it to listen to all interfaces:
--address <public_ip_here> -- set IP address got from ifconfig OR set to 0.0.0.0 which means to listen to all interfaces
Finally, if you have NSG associated with your NIC or subnet, you can allow these ports from your client to access in the inbound rules. see How to open ports to a virtual machine with the Azure portal
-H 6968,6669 -- on which PORTS to listen for connections (You can set multiple ports using comma to split [see more](https://github.com/TelegramMessenger/MTProxy/issues/84#issuecomment-401022826))
For more details, you could follow this tutorial.

How do I configure an IIS site on an Azure VM to accept requests from an additional external IP Address?

I'm hoping someone can help with this.
I have an existing Azure Virtual Machine which has been running fine for ages. It has a single NIC with both a static Private and static Public IP Address.
I have been hosting a site in IIS for a long time bound to the (only) private IP Address on the machine, and everything has been dandy.
However, I wanted to add a second site, and because I'm using SSL and different certificates I wanted to use an alternative public IP Address.
I have created a new Public IP (static private and public address) and associated it with a new NIC. I have then added that NIC to my virtual machine.
I ALSO added Inbound rules on the Virtual Machine Networking settings to accept inbound traffic on ports 80 and 443 for BOTH NICs.
When I login to the VM I can see the new network adapter, and IPCONFIG is showing it has the correct static private IP address which I specified. So I setup the new IIS site, and added the bindings. For this "Hello World" proof of concept I have left the hostname and SSL bindings out. I just basically have it bound to the Private IP Address on Port 80.
Note - the "site" itself at this point is just a static "Hello World" HTML page. There is no managed code or any server-side or client-side funkiness of any kind.
So I basically have the following setup:
NIC 1
Private IP: 10.0.1.4
Public IP: X.X.X.X
NIC 2
Private IP: 10.0.1.5
Public IP: Y.Y.Y.Y
IIS Site 1
Bindings: 10.0.1.4 : 80
IIS Site 2
Bindings: 10.0.1.5 : 80
I can happily access BOTH sites locally on the machine (using http://10.0.1.4 and http://10.0.1.5 respectively).
However, accessing from the internet (i.e. from my home or work computers) if I try to access the original site on http://X.X.X.X it works fine.
But trying to access http://Y.Y.Y.Y just times out. I never get any kind of response.
I have tried using host name binding (with local HOSTS entries) but still get the same problem.
Phew .. ok I know that was a long(ish) post but is there some secret setting I'm missing somewhere? Or being stupid about this?
I always assumed that for a single NIC that the Public IP would route directly to the corresponding Private IP. Is this not the case??
Thanks in advance!!
EDIT
Moving the public IP to a second IP Configuration on the first NIC seemed to do the trick.
As I don't have any real need to have more than one NIC this did the trick, although it did require me to manually add both fixed IP addresses to the IPv4 configuration of the network adapter in Windows
Here a article about assign multiple IP addresses to VM, please refer to it.
Follow this article step by step, you can use two public IP addresses to RDP that VM.
Here is the screenshot of that VM, I can RDP that VM with two public IPs:
Maybe you can use this to achieve it.

Amazon EC2 - What is private DNS and private IP?

The details of Amazon EC2 mentions Public DNS, private DNS and private IP. I know public DNS can be used to reach the instance after configuring the security group.
I am not able to understand
What is private DNS?
What is private IP?
Why do we need these number these two when we have public DNS to reach the instance?
EC2 instances are connected to a private local area network and given IP addresses on that network. Those are the 10.x.x.x addresses you see as the "private IP". Amazon provides a DNS service that associates names with those private IP addresses. That's the private DNS.
Unless you are on a VPC, Amazon also connects those private IP addresses to regular routable IP addresses, and gives DNS names that resolve to those public IPs. As near as I can tell, this is pretty much just like an Elastic IP address except that each time you shut the machine down and restart it, you'll get a different one instead of the same one each time.
A neat trick with the public DNS is that the same name will resolve to different addresses depending on who is asking. Machines on Amazon's private network (that is, other EC2 machines in the same AZ, maybe the same region) will have the public DNS resolve to the private IP. That way, traffic between machines inside EC2 stays inside EC2. Machines on the regular internet will have the public DNS resolve to the public IP.

Using Route53 as private DNS

I would like to use Route53 as private DNS in order to map hosts to AWS private IP addresses.
The hosted zone we are using for testing is not declared in any registrar (company-test.com.).
The ActiveMQ server url is activemq.company-test.com and it maps to (A record) private IP address of the AMQ server. This url is only reachable by other ec2 owned by the same aws account.
My question is how to configure ec2 instances so they could reach the ActiveMQ server WITHOUT having to buy a new domain company-test.com ?
Thank you!
You could assign an Elastic IP to your ActiveMQ instance.
Elastic IP addresses are static IP addresses designed for dynamic
cloud computing. An Elastic IP address is associated with your
account, not a particular instance, and you control that address until
you choose to explicitly release it. Unlike traditional static IP
addresses, however, Elastic IP addresses allow you to mask instance or
availability zone failures by programmatically remapping your public
IP addresses to any instance associated with your account.
Another option is to set up a Virtual Private Cloud (VPC), and launch your ActiveMQ instance there. Your private IP address will not change on reboot. Another feature of VPC is the use of Elastic Network Interfaces (ENI). You can move the interface between different instances if needed.

Resources