9

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?

Vasili Syrakis
  • 4,435
  • 3
  • 21
  • 29
jwerre
  • 748
  • 3
  • 11
  • 26

2 Answers2

7

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.

Michael - sqlbot
  • 21,988
  • 1
  • 57
  • 81
  • I am also facing same issue.I want to use public ip of openstack vm instead of private ip i.e. eth0 ip. – Vikram Ranabhatt Mar 27 '16 at 11:50
  • @Chris_vr this question is about AWS, where binding to the wildcard or private IP specifically is the correct (and only) option. Openstack, I have no idea, but if you only see the private IP bound to the stack, the answer is probably similar, and if so, then trying to bind a socket to the public IP is the wrong way to accomplish what you are trying to do. – Michael - sqlbot Mar 27 '16 at 11:59
1

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.

jwerre
  • 748
  • 3
  • 11
  • 26