39

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,752
  • 1
  • 29
  • 36
andy4thehuynh
  • 1,790
  • 3
  • 24
  • 36

2 Answers2

70

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
  • 22,956
  • 5
  • 43
  • 66
  • 1
    Perfect. Thanks for the 4.2 nugget. – andy4thehuynh Mar 16 '15 at 18:28
  • 5
    You're welcome, it was a nasty (poorly publicized) gotcha for a lot of people. – smathy Mar 16 '15 at 18:36
  • 3
    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
1

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

jmdeamer
  • 181
  • 1
  • 13