55

I am using "www.xip.io" as a DNS wildcard for testing on different devices. I set my primary domain to my IP address. I fire up a rails server with bundle exec rails server and I go here www.<ip_address>.xip.io:3000 and notice my rails server doesn't respond.

However, if I bind my rails server to 0.0.0.0 like so bundle exec rails server -b 0.0.0.0, it works! I don't understand what 0.0.0.0 is telling my server for this to work. Can someone make sense of this?

0

2 Answers 2

90

Binding to 0.0.0.0 tells the service to bind to all IP addresses on your machine. Rails server used to do this by default, but with 4.2 changed to binding only to localhost.

Basically if it's only bound to localhost then it will only respond locally to either localhost or 127.0.0.1 which can't work through a DNS service because it's not a public IP address.

When you use 0.0.0.0 it will bind to localhost and to your routable IP address.

4
  • 7
    You're welcome, it was a nasty (poorly publicized) gotcha for a lot of people.
    – smathy
    Mar 16, 2015 at 18:36
  • 5
    Oh man, this had me going absolutely crazy. If you're trying to run rails from a docker container and you don't specify this option, the docker container does not respond, no matter what you do. This is a lifesaver. Dec 10, 2016 at 7:06
  • Isnt' binding to only localhost better ? Especially if you are behind a proxy and want your site example.com to forward to localhost:3000 internally ?
    – Piccolo
    Nov 13, 2023 at 22:02
  • I mean yes, if you have a reverse proxy that means Rails only needs to know about localhost, then you'd just run rails s without any binding (which binds to localhost). That's not what OP had.
    – smathy
    Nov 16, 2023 at 20:32
0

I think you need to use binding any time you're in a guest/virtual machine.

1
  • 1
    It's true that binding to a non-localhost address is important in that context... it would be useful to say a lot more than this if you're wanting this answer to stand on its own, though. (And indeed, it's binding either way, it's just a question of whether it's binding to the wildcard (0.0.0.0) or localhost or what.) Downvoting for both lack of precision and lack of a full answer to the original question, though I'd be happy to re-visit given an update to the answer, because I definitely do think there's something useful in this.
    – lindes
    Aug 14, 2023 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.