bind: cannot assign requested address

I've recently switch over to AWS from Rackspace and I'm setting up a simple geolocation server using freegeopip. While the following commands work perfectly on a new Rackspace serve (Ubuntu) I can't getting working on AWS (tried Red Hat and Ubuntu). Here is the code I've used to set it up:

curl -s https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | tar -C /opt -zx
export GOPATH=$HOME
export GOROOT=/opt/go
export PATH=$PATH:/opt/go/bin
go get github.com/fiorix/freegeoip/cmd/freegeoip
$GOPATH/bin/freegeoip -addr="<MY IP ADDRESS>:8080"

As I've said this works perfecectly on my Rackspace instace but AWS gives me this error:

listen tcp <MY IP ADDRESS>:8080: bind: cannot assign requested address

I've checked this port with netstat and there is nothing running on it. I have no idea why I'm getting this error. Any ideas?


Solution 1:

In many cases, binding to 0.0.0.0 is the best course of action unless you have a specific reason to bind only to a specific address.

But I assume that what you're doing isn't working, because you're trying to bind to the instance's public IP address, which you'll find (via ifconfig) your IP stack isn't aware of.

AWS instances are only natively aware of their private IP address, which is what you need to bind to.

EC2 (classic and VPC) instance public addresses associates with instances are 1:1 NAT translated to the private address by the AWS network infrastructure.

Solution 2:

AWS runs network address translation between your instance and the internet. So, the AWS instance might be reachable by the IP address 08.08.08.0808, however the server is actually configured to use 88.88.88.88. What I need to do was bind to the internal IP of the server which I found with ifconfig.