0

I'm sure this is a pretty basic question, but I could not find an answer to it. I already looked at this question, this question, this question, this question, and this question and none of them helped me reach an answer.

I am using Rails 4.2. I created a very simple app to test out if I could do the following:

I wanted to see if it was possible for me to boot up my rails app on my computer, and then access the app from outside of my local network. For example: from my phone (which is not connected to the local network) I want to make a request and successfully get a response.

I assumed that I first needed to get my external/routable ip address. I realize that the IP address my ISP provides my router is not static, but just for demo purposes I wanted to see if I could just successfully make a single request.

I went to google and typed in "What is my ip" and it came back with my external ip address (let's pretend my external ip address is: 11.111.111.111).

Within my rails app: I then did the following command:

rvmsudo rails s -p 80 -b 11.111.111.111 

I want to bind to the external ip address, and I want to listen on port 80. I do the rvmsudo because, as I understand it, all ports below 1000 require higher privileges.

It errors out and says the following:

Can't assign requested address - bind(2)

I am trying to understand why this is erroring out. What am I not understanding? Am I missing a step? Is it not possible to do this? Is my ISP making it so that I cannot bind to that external IP? Do I need to do additional configuration on my router?

I realize that I could just use heroku. This is more of an experiment to see if this is even possible. Thanks in advance!

Community
  • 1
  • 1
Neil
  • 4,578
  • 14
  • 70
  • 155
  • 1
    The IP address that Google reports is the public IP address of your router assigned by your ISP. You will need to set up port forwarding on your router to allow access to your Rails application, but this site is not the place to ask how to do that. Try [superuser.com](http://superuser.com). – Mick Sep 13 '16 at 04:47
  • you could try `8080` ? – Taryn East Sep 13 '16 at 06:04
  • 1
    @TarynEast this is not a matter of port number but the public IP not being an interface of the computer the server runs on. – Pascal Sep 13 '16 at 07:16

1 Answers1

0

You can not bind the socket to your external IP. This IP is assigned to your modem (or whatever you use to connect to the internet) by your ISP. You can only bind to interfaces of your computer.

There are multiple solutions:

  • Bind to 0.0.0.0:3000 (or your computers IP, not localhost) and make sure that your network forwards your public IP to your computer on that port.
  • Use something like https://ngrok.com/ easy and simple
Pascal
  • 8,464
  • 1
  • 20
  • 31