51

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?

Andrew Nesbitt
  • 5,976
  • 1
  • 32
  • 36
andy4thehuynh
  • 2,042
  • 3
  • 27
  • 37

2 Answers2

87

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.

smathy
  • 26,283
  • 5
  • 48
  • 68
  • 7
    You're welcome, it was a nasty (poorly publicized) gotcha for a lot of people. – smathy Mar 16 '15 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. – Levi Nunnink Dec 10 '16 at 07:06
0

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

jmdeamer
  • 337
  • 2
  • 16
  • 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 '23 at 18:06