Rails CLI server bind host defaults to 127.0.0.1, is there a way to make it default to 0.0.0.0?

71 views
Skip to first unread message

Lee Olayvar

unread,
Apr 9, 2015, 5:23:51 PM4/9/15
to rubyonra...@googlegroups.com
I'm trying to make the rails CLI server bind host default to 0.0.0.0 on some machines i manage. Currently, it binds to localhost/127.0.0.1, and it seems to keep catching new developers who are unaware of this.

Currently, i'm wrapping the rails command with a shell script, automatically injecting the `-b 0.0.0.0` flag if it is not provided. This is rather hacky though, and gems has issues with it (it won't uninstall rails apparently, but that's besides the point).

Do you have any recommendations for defaulting to 0.0.0.0?

Any thoughts would be appreciated. Thanks,

botp

unread,
Apr 10, 2015, 11:17:11 PM4/10/15
to rubyonra...@googlegroups.com
On Fri, Apr 10, 2015 at 5:06 AM, Lee Olayvar <leeol...@gmail.com> wrote:
> I'm trying to make the rails CLI server bind host default to 0.0.0.0 on some
> machines i manage. Currently, it binds to localhost/127.0.0.1, and it seems
> to keep catching new developers who are unaware of this.

that is fine. they are new developers and the default localhost is
safe for them : )

> Currently, i'm wrapping the rails command with a shell script, automatically
> injecting the `-b 0.0.0.0` flag if it is not provided. This is rather hacky
> though, and gems has issues with it (it won't uninstall rails apparently,
> but that's besides the point).
>
> Do you have any recommendations for defaulting to 0.0.0.0?

you can override Rails::Server#default_options and merge this hash
{Host: "0.0.0.0", Port:3000}

changing defaults is not my habit so i wont recommend it.
i would prefer instead creating a new rake task that start rails w the
default options i want

kind regards
--botp

Lee Olayvar

unread,
Apr 13, 2015, 1:54:38 PM4/13/15
to rubyonra...@googlegroups.com
that is fine.  they are new developers and the default localhost is
safe  for them  : )

Generally i agree, but it's not really up for me to change. And regarding localhost being safe, it's actually (mostly) useless. The machines in question are not the localhost (though, on the network) - so localhost is nearly useless for them heh. One way or another, i need to do it unfortunately.. and my solution of wrapping the rails bin seems pretty bad, heh
 
you can override Rails::Server#default_options and merge this hash
{Host: "0.0.0.0", Port:3000}

To be clear, you're saying modify the command rails puts in the bin? Eg, /usr/local/bin/rails?
 
changing defaults is not my habit so i wont recommend it.
i would prefer instead creating a new rake task that start rails w the
default options i want

I would agree there, but i'm trying to implement a default option for the global rails command. You're referring to a project-local rake task, correct?

Note: Pardon any ignorant statements about rails/ruby, i'm not a ruby person. This is more of a general unix task, that i am hoping actual rails developers might have a better solution for :)
 

I appreciate your reply!

Hassan Schroeder

unread,
Apr 13, 2015, 3:55:07 PM4/13/15
to rubyonrails-talk
On Mon, Apr 13, 2015 at 10:54 AM, Lee Olayvar <leeol...@gmail.com> wrote:

> Generally i agree, but it's not really up for me to change. And regarding
> localhost being safe, it's actually (mostly) useless. The machines in
> question are not the localhost (though, on the network)

So your developers are "working on" remote machines? Unusual.

In any case, you can specify alternate port, binding, etc. options in
the config.ru file.

HTH,
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Brian Sammon

unread,
Apr 16, 2015, 1:34:48 AM4/16/15
to rubyonra...@googlegroups.com
On Mon, 13 Apr 2015 12:54:42 -0700
Hassan Schroeder <hassan.s...@gmail.com> wrote:

> On Mon, Apr 13, 2015 at 10:54 AM, Lee Olayvar <leeol...@gmail.com> wrote:
>
> > Generally i agree, but it's not really up for me to change. And regarding
> > localhost being safe, it's actually (mostly) useless. The machines in
> > question are not the localhost (though, on the network)
>
> So your developers are "working on" remote machines? Unusual.
>
> In any case, you can specify alternate port, binding, etc. options in
> the config.ru file.

Is this documented somewhere? Officially or just unofficialy?

Hassan Schroeder

unread,
Apr 16, 2015, 11:54:20 AM4/16/15
to rubyonrails-talk
On Wed, Apr 15, 2015 at 10:34 PM, Brian Sammon
<rubyonra...@brisammon.fastmail.fm> wrote:

>> In any case, you can specify alternate port, binding, etc. options in
>> the config.ru file.
>
> Is this documented somewhere? Officially or just unofficialy?

https://github.com/rack/rack/wiki/%28tutorial%29-rackup-howto

That's the only place I've seen it mentioned.
Reply all
Reply to author
Forward
0 new messages