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

8 thoughts on "How to bind WEBrick to any IP address"

  1. Joe says:

    You are using mongrel not webrick

    1. hukl says:

      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 🙂

  2. gds says:

    Perfect, thanx a lot !

  3. Muhammed says:

    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

  4. Spss says:

    After 9 years this helped me. Thanks 🙂

  5. John says:

    It’s 2016 and this has helped me.

  6. Okan Binli says:

    It’S 2017 November and helped me, too!

    Thanks!

Leave a Reply to hukl Cancel reply

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