Make Rails 4.2 listens to all interfaces

After upgrading Rails to 4.2 and newer, you cannot access the development mode rails server from another computer/virtual machine (remote access) for testing. So, why can this happen and how to resolve it?


This is caused by a change in Rails 4.2, the rails s command no longer listens at (means listen on all interfaces) by default, its default is now localhost instead. It means you can only use http://localhost:3000 or to access rails server, will not work now. You can see the difference between Rails 4.1 (and ealier) and 4.2 when starting Rails server:

In Rails 4.1 and before
=> Rails 4.1.9 application starting in development on http://localhost:3000

In Rails 4.2
=> Rails 4.2.0 application starting in development on


If you need remote access, you can choose one of below methods:

  1. Apply in each start Start rails server by appending -b, so command to start rails server is: rails s -b
  2. Change default binding option Modify config/boot.rb by adding below code and start rails server with normal command rails s
require 'rubygems'
require 'rails/commands/server'

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