Thiago Peres
Thiago Peres

Reputation: 834

Cannot access local Sinatra server from another computer on same network

I have a simple Sinatra server that I run through textmate but I can't access from another computer on the same network.

I'm running Ruby 1.9.3p327 and Sinatra 1.4.1 on a Mac OS 10.8.3. Firewall is disabled.

I tested the same scenario on different networks and computers.

The computer responds to simple pings but when I try to telnet port 4567 I can't establish a connection.

Upvotes: 44

Views: 15701

Answers (3)

Jellio
Jellio

Reputation: 1481

I'm chiming in with a little extra information that may help people like me banging their heads against the wall.

I'm on a Windows machine, not a Mac, and I had to open the port I was using (default for Sinatra is 4567) to the public (even though I'm on a university network).

To do this in Windows 10:

  1. Hit the windows key
  2. Search for firewall and hit enter
  3. Go to advanced settings
  4. Click on inbound rules in the top left
  5. Click on new rule in the top right
  6. Click the port option
  7. Enter your port (probably 4567 for Sinatra)
  8. Next
  9. And now pick from domain/private/public.

Now another thing to consider is who can access your web server. If you want anyone, then pick public. I don't know for sure (and would love other's input) how to get only devices on the same public network to connect. You can also allow specific IPs through, but for that I suggest doing some research on your own.

Upvotes: 0

matt
matt

Reputation: 79783

There was a recent commit to Sinatra that changed the default listen address to localhost from 0.0.0.0 in development mode due to security concerns.

In order to explicitly allow access from the network, you need to either run your app in another mode (e.g. production), or set the bind option to 0.0.0.0.

You can do this from the command line using the built in server using the -o option:

$ ./my_sinatra_file.rb -o 0.0.0.0

Upvotes: 91

DGM
DGM

Reputation: 26979

Make sure the sinatra server is not listening on only the localhost (127.0.0.1) ip address.

Upvotes: 5

Related Questions