Search code examples
virtualboxgenymotionnativescript

Connecting to localhost from Genymotion (Virtualbox)


This question has been asked and answered many times, but none of those answers have worked for me.

Few days ago my nativescript app (emulated in Genymotion device) worked perfectly connecting to my local rails server (localhost:3000) if I remember correctly by using 10.0.3.2:3000/v1/ in Genymotion.

Today I am trying to make it work again to no avail :(

DETAILS:

  • My Genymotion device is at 192.168.56.101
  • My ifconfig vboxnet0 says 192.168.56.1

I tried:

  • these IPs since many ppl. mention them in various posts

"http://10.0.2.2", "http://10.0.2.2:3000", "http://10.0.3.2", "http://10.0.3.2:3000", "http://10.0.3.2:8080", "http://10.0.3.3", "http://10.0.3.3:3000", "http://192.168.56.1:3000", "http://192.168.56.1"

  • Putting my virtualbox instance network into NAT mode from Host-only didn't help either

  • Putting the virtualbox network into bridge mode (Promiscuous mode).

What I get when I try to fetch these IPs is TypeError: Network request failed

If I try fetching something like google.com I get a response so I guess that virtual box network mode is wrong or my Mac has some firewall I'm unaware of

EDIT

I should've mentioned it earlier, but I forgot. I have nginx running on my machine for some other projects

If the nginx is OFF I get TypeError: Network request failed for all the IPs

If I turn the nginx on I get 502 Bad gateway from it for the following IPs:

"http://10.0.3.2", "http://10.0.3.3", "http://10.0.3.2:8080", "http://192.168.56.1:8080", "http://192.168.56.1"

My rails server which is running on the port 3000 receives no requests, though. Please note that I do try to hit all the above at port 3000 thousand too, both with nginx ON and OFF.

EDIT 2

FIXED

The whole problem in my case came from my PUMA server that due to some changes in the new version doesn't listen 0.0.0.0 (all interfaces) anymore, but localhost and 127.0.0.1. This is why localhost on the host machine would work and from the virtualbox (Geny.) wouldn't

TL;DR;

If you are using Puma server and cannot connect from other machines to your localhost, start you rails server using this:

rails server -b 0.0.0.0


Solution

  • The whole problem in my case came from my PUMA server that due to some changes in the new version doesn't listen 0.0.0.0 (all interfaces) anymore, but localhost and 127.0.0.1. This is why localhost on the host machine would work and from the virtualbox (Geny.) wouldn't

    TL;DR;

    If you are using Puma server and cannot connect from other machines to your localhost, start you rails server using this:

    rails server -b 0.0.0.0