How to connect to Rails server on Ubuntu 18.04 VirtualBox VM from within Windows 10 host?

Notebook connected to Wi-Fi, hosting Windows 10. Guest: VirtualBox VM running Ubuntu 18.04.

Configured VM adapter 1 to bridged mode ("Placa em modo bridge"). I assume that way is simpler than configuring NAT with port forwarding.

Invoking ipconfig on Windows 10 host includes the following information:

 Adaptador Ethernet VirtualBox Host-Only Network:

   Endereço IPv4. . . . . . . .  . . . . . . . : 192.168.56.1
   Máscara de Sub-rede . . . . . . . . . . . . : 255.255.255.0

Adaptador de Rede sem Fio Wi-Fi:

   Endereço IPv4. . . . . . . .  . . . . . . . : 192.168.15.5
   Máscara de Sub-rede . . . . . . . . . . . . : 255.255.255.0

Invoking ifconfig on guest includes the following information:

enp0s3: inet 192.168.15.6  netmask 255.255.255.0

lo: 
        inet 127.0.0.1  netmask 255.0.0.0

Rails running on guest with the following command:

$ rails s
(...)
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

When I try to access URL http://0.0.0.0:3000 from within guest it works OK. However, when I try from within host it does not, neither does http://192.168.56.1:3000 or anything else.

I've read up this question, but could not make it run on port 80 (sudo rails s -p 80 shows sudo: rails: command not found).

What am I missing to make accessing server from within host to work?


Solution 1:

Check your firewall on Windows, open Windows Defender Firewall with Advanced Security and click on Inbound Rules and create a rule that allows port 3000. You may also have to allow it though the Ubuntu firewall.