How to change the default binding ip of Rails 4.2 development server?

I'm having the same issue here and I found today a better solution. Just append this code to your config/boot.rb and it should work with vagrant.

require 'rails/commands/server'
module Rails
  class Server
    def default_options
      super.merge(Host:  '0.0.0.0', Port: 3000)
    end
  end
end

ps: Its based on: this answer


You can use foreman to run a Procfile with your custom commands:

# Procfile in Rails application root
web:     bundle exec rails s -b 0.0.0.0

Now start your Rails application with:

foreman start

The good thing about foreman is that you can add other applications to the Procfile (like sidekiq, mailcatcher).

The bad thing about foreman is that you have to train your team to run foreman start instead of rails s.


For Rails 5.1.7 with Puma 3.12.1 the selected answer does not work, but I accomplished it by adding the following to my config/puma.rb file:

set_default_host '0.0.0.0' # Note: Must come BEFORE defining the port

port ENV.fetch('PORT') { 3000 }

I determined this by inspecting the dsl file. It uses instance_eval on that file, so there are probably other ways to do it, but this seemed the most reasonable to me.


Met the same problem. Found the blog Make Rails 4.2 server listens to all interfaces.

Add the following to config/boot.rb

require 'rails/commands/server'

module Rails
  class Server
    alias :default_options_bk :default_options
    def default_options
      default_options_bk.merge!(Host: '0.0.0.0')
    end
  end
end