Access webrick / rails from another computer on the local network

I have a rails application running on localhost: 3000. I want to access it from another computer on the same network. I feel like doing it before, but it saddens me. I can ping the IP address of the computer is just fine, but defeating ip: 3000 in the browser does not work. I also tried running rails s -b ipaddress , and no luck.

Suggestions?

+48
ruby-on-rails webrick
Sep 06 '11 at 20:19
source share
6 answers

Try starting the server on port 80 instead, your firewall will probably block port 3000.

+1
Sep 06 '11 at 20:40
source share

Once your server-side firewall is open for incoming connections on high ports (usually true, but the default is 3000, so you probably don't need anything), you should also start the server

 rails server -b 0.0.0.0 

which associates it with a universal address. It binds to localhost by default.

Using this method, you do not need to communicate with port 80, but you may like the following:

 rails server -b 0.0.0.0 -p 80 

(If you are using rvm, you may need to use rvmsudo )




To make this change more permanent, change your config/boot.rb and add the following:

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

Then you only need to use rails s

Source: stack overflow

+133
Mar 09 '15 at 17:35
source share
 rails server -b 0.0.0.0 -p 8000 

It worked for me. There is no problem with the firewall and there is no need to grant superuser rights.

+19
Sep 02 '15 at 14:29
source share

Assuming Webrick starts without problems, it is a 100% problem with the firewall. You must provide some specifications, for example, which operating system your host is running on, and whether you have administrator rights to manage the firewall.

If you are running Linux and running the iptables firewall, you need to add a rule to receive traffic through port 3000. It will look something like this:

 iptables -A INPUT -p tcp --dport 3000 -j ACCEPT 

This command will be a one-time solution, but you will need to extend your current iptables script rules to make them persistent every time your system boots up or logs in.

If you use Windows, depending on whether you use XP or Vista / 7, you need to do something similar. I assume that you are in Vista / 7 and you just need to follow the instructions in this guide http://windows.microsoft.com/en-US/windows7/Open-a-port-in-Windows- Firewall

+4
Sep 06 2018-11-11T00:
source share
  • Yes, that was a good answer in general :

     rails server -b 0.0.0.0 
  • If you are using Ubuntu , you will probably have to open the port in the firewall :

     sudo ufw allow 3000 
  • If your system is running VirtualBox , you need to check Network Settings .

    In the case of NAT network mode, you need to click on the advanced settings and there until Port Forwarding . Add a rule for TCP protocoll, host port 3000 (or any other) and guest port 3000.

+3
Dec 18 '16 at 20:32
source share

One reason is because your ip is not tied to a rails server. You can bind ip with the -b option.

 Usage: rails server [mongrel, thin etc] [options] -p, --port=port Runs Rails on the specified port. Default: 3000 -b, --binding=IP Binds Rails to the specified IP. Default: localhost 
0
Oct 21 '15 at 10:20
source share



All Articles