Make Rails 4.2 server listens to all interfaces

on Rails 4.2, Rails, Rails Server, Rails 4.2 Remote Access

After upgrading Rails to 4.2, 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
=> 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: '')

A full stack developer with Ruby on Rails as the main framework. Eager to learn and share.