How to bind WEBrick to any IP address

I found several and somewhat complex solutions for this particular problem but actually it’s a no-brainer once you know. Simply type:

hukl$ script/server -h
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
Usage: server [options]
    -p, --port=port                  Runs Rails on the specified port.
                                     Default: 3000
    -b, --binding=ip                 Binds Rails to the specified ip.
                                     Default: 0.0.0.0
    -d, --daemon                     Make server run as a Daemon.
    -e, --environment=name           Specifies the environment to run
                                     this server under
                                     (test/development/production).
                                     Default: development

    -h, --help                       Show this help message.

The magic trick is to use sudo to start WEBrick, else the bind might not work and the webserver is unreachable for virtual machines or other hosts.

sudo script/server -b 10.0.2.1 -p 80

Yippeeh! Now I can test my Ruby on Rails projects, which are running on OS X, from my WinXP Paralles virtual machine using IE6 and IE7.

Main entry continued

6 Responses to How to bind WEBrick to any IP address

    • Oh wow – 6 years later somebody finally corrects that mistake. I feel a bit embarrassed but thanks for pointing it out. Not sure though if its worth correcting by now or if I should just delete it now 🙂

  1. sudo script/server -b 10.0.2.1 -p 80

    I am using a gemset inside my rvm like $ rvm use 1.8.7@mygemset

    it is working perfect in script/server. but shows error sudo script/server -b 10.0.2.1 -p 80. it shows no rails 2.3.5 installed.. yes ichecked it is there in my gemset

Leave a Reply

Your email address will not be published. Required fields are marked *