Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does binding a Rails Server to 0.0.0.0 buy you?

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?

like image 474
andy4thehuynh Avatar asked Mar 16 '15 18:03

andy4thehuynh


2 Answers

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.

like image 170
smathy Avatar answered Nov 10 '22 22:11

smathy


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

like image 1
jmdeamer Avatar answered Nov 10 '22 22:11

jmdeamer