Search code examples
rubylinuxsinatravirtualboxshotgun

Virtual Box port forwarding misery with Ruby Sinatra:4567 / Shotgun:9292


I've got a VirtualBox CentOS 7.0 Guest OS on a Windows Ten Host for the purposes of development, and the port forwarding simply isn't working.

I have a NAT'd network adapter (I can't use Bridged Adapters on this network) and to be fair I am much more comfortable with Bridged Adapters. But everything else works swimmingly. Except the ports 4567 and 9292 will not forward, while port 22 and port 80 work fine.

I have

  • Added port forwarding on the client for the ports 22,80,4567,9292 in VirtualBox on the NAT'd adapter.
  • disabled the firewalld on CentOS 7.0 completely (and restarted) then ruled that out
  • all ports work fine on local host i.e. in the vm localhost:4567 is perfect as is localhost:9292
  • switched of SELINUX on guest (for good measure)
  • restarted the whole VM on host systematically every time I did a network->portforward alteration
  • tried 10.0.2.15:4567 / 10.0.2.15:9292 in a vain attempt to get purchase

all the time I am ssh'd in on port 22 and port 80 works fine

Is this a traffic issue or a firewall issue, is there some sort of network filtering on the VirtualBox interface that's hidden from me?

I'd love some help.


Solution

  • NB: THE CAUSE IS SHOTGUN/RUBY NOT VirtualBox nor Firewalls nor port forwarding

    @Matt fixed this... his link in the comments is correct, the fix to this is one of two things: (it's actually shotgun running ruby in development mode that causes it)

    CAUSE:

    • RUBY running in default set :bind, 'localhost' development mode. (link)

    SOLUTION:

    • RUBY runs with options set :bind, '0.0.0.0' (can also be in the config.ru)

    Good news is if you're looking to make localhost:4567 work this is your ticket, add the line set :bind, '0.0.0.0' to your config and you're good to go

    ANNOYINGLY IF YOU RUN SHOTGUN THIS ISN'T GOING TO BE PICKED UP

    Bad news is if you're looking to make localhost:9292 work shotgun does it's own thing here:

    • in fact shotgun won't LOOK at those ruby configs, it'll adopt it's own boot strategy, so you have to MAKE shotgun run in --host=0.0.0.0 mode: EG:
    • # shotgun --server=thin --port=9292 --host=0.0.0.0 config.ru