create-react-native-app icon indicating copy to clipboard operation
create-react-native-app copied to clipboard

Virtualbox related issue - multiple networks

Open xingjianpan opened this issue 9 years ago • 24 comments

Hi,

I have virtual box installed on my system and there are multiple networks available in additional to my WIFI network (i.e VirtualBox Host-Only Network, VirtualBox Host-Only Network #2, VirtualBox Host-Only Network #3 , etc..).

After running the command yarn start, i got below messsage:

Or enter this address in the Expo app's search bar:

exp://192.168.56.12:19000

Initially i was not able to connect to this address using Expo App. After quite some time investigating this issue, i noticed it's because 192.168.56.12 belongs to one of the network created by VirtualBox.

After disabling all the networks created by Virtual Box, I am able to connect Expo with my project. and the message become this. Note 192.168.1.12 belongs to my WIFI network which my phone can connect.

Or enter this address in the Expo app's search bar:

exp://192.168.1.12:19000

So, is this a bug? or is there a place where i can set which network to use?

xingjianpan avatar Mar 14 '17 13:03 xingjianpan

I think this is probably a bug. What OS are you using? I suspect that our detection for "default network device" is not producing the correct result here. We currently use https://www.npmjs.com/package/ip to detect IP addresses, but it might be worth trying with https://www.npmjs.com/package/address or another package.

cc @jesseruder, relevant xdl line: https://github.com/exponent/xdl/blob/43f29f10ea1641a5ab1808af93bedb8ee683a6b8/src/UrlUtils.js#L148

anp avatar Mar 14 '17 17:03 anp

my system is Windows 10 Home Edition.

xingjianpan avatar Mar 15 '17 03:03 xingjianpan

This issue has been open for a while https://github.com/indutny/node-ip/issues/21. I'm going to see if I can repro this and will check if the address package works better in this scenario.

anp avatar Mar 15 '17 21:03 anp

Can you tell me what the output of this command is in a node REPL when running virtualbox on this machine?

Object.keys(require('os').networkInterfaces()).reduce((results, name) => results.concat(interfaces[name]), []).filter((iface) => iface.family === 'IPv4' && !iface.internal).map((iface) => iface.address)

anp avatar Mar 16 '17 00:03 anp

I got below error when running your command:

ReferenceError: interfaces is not defined at Object.keys.reduce (repl:1:89) at Array.reduce (native) at repl:1:48 at sigintHandlersWrap (vm.js:22:35) at sigintHandlersWrap (vm.js:96:12) at ContextifyScript.Script.runInThisContext (vm.js:21:12) at REPLServer.defaultEval (repl.js:346:29) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer. (repl.js:545:10)

However, if i just run the first part of your command:

require('os').networkInterfaces()

I got below results:

{ 'VirtualBox Host-Only Network': [ { address: 'fe80::787d:2d70:287f:b786', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '0a:00:27:00:00:06', scopeid: 6, internal: false }, { address: '192.168.56.1', netmask: '255.255.255.0', family: 'IPv4', mac: '0a:00:27:00:00:06', internal: false } ], 'VirtualBox Host-Only Network #2': [ { address: 'fe80::84af:8a25:b53a:67f9', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '0a:00:27:00:00:17', scopeid: 23, internal: false }, { address: '192.168.25.2', netmask: '255.255.255.0', family: 'IPv4', mac: '0a:00:27:00:00:17', internal: false } ], 'VirtualBox Host-Only Network #3': [ { address: 'fe80::b9e5:1022:96dc:3786', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '0a:00:27:00:00:15', scopeid: 21, internal: false }, { address: '192.168.99.1', netmask: '255.255.255.0', family: 'IPv4', mac: '0a:00:27:00:00:15', internal: false } ], MyWLAN: [ { address: 'fe80::55f8:45e1:8a5e:a510', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '34:f3:9a:64:28:5f', scopeid: 8, internal: false }, { address: '192.168.1.11', netmask: '255.255.255.0', family: 'IPv4', mac: '----removed----', internal: false } ], 'Loopback Pseudo-Interface 1': [ { address: '::1', netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', family: 'IPv6', mac: '00:00:00:00:00:00', scopeid: 0, internal: true }, { address: '127.0.0.1', netmask: '255.0.0.0', family: 'IPv4', mac: '00:00:00:00:00:00', internal: true } ] }

xingjianpan avatar Mar 16 '17 12:03 xingjianpan

@xingjianpan I was having the same problem. Assigning interface matric (priority) for your Wifi adapter and any other network adapters solves the problem for me. The order of IP used in https://www.npmjs.com/package/ip seems to be the first one you can see when running ipconfig.

This link shows how: https://answers.microsoft.com/en-us/windows/forum/windows_10-networking/adapter-priority-setting-unavailable-in-windows-10/d2b63caa-e77c-4b46-88b5-eeeaee00c306

Hope this helps

smiled0g avatar Mar 16 '17 14:03 smiled0g

@smiled0g , many thanks! I will try it out.

@smiled0g , this method works for me! Thanks!

xingjianpan avatar Mar 17 '17 09:03 xingjianpan

Hi guys,

I think the proper way to address this issue is simply to be able to specify IP and port at launch (options, environment variables).

Here is the problem that I have related to this open issue:

  • My expo App runs in a Docker container => many options possible for the interfaces (bridges, overlay networks...)
  • My server running the docker has a virtual public IP (behind load balancer) => Neither the container nor the server is 'aware' of this IP

=> The only way to address this and ALL the other possible networking configurations is to be able to setup the IP+Port at the application level (Expo)

Cheers,

digital-stoic avatar Mar 19 '17 03:03 digital-stoic

adapter ordering is a work around, a solution would be to be able to configure.

pstanton avatar Jun 22 '17 09:06 pstanton

The following steps will definitely help. I had the same problem and was able to solve it in my Windows 10 OS. I had Virtual Box installed on my computer and I was not able to run CRNA in my android expo client. So,

  1. first I connected my laptop through my mobile hotspot.
  2. Then Control Panel > (search for 'network connections') > network connections
  3. Right-Click on 'Wifi' > select 'Properties' > 'Internet Protocol Version 4 (TCP/IPv4)' [don't uncheck the mark]
  4. Go to "Properties" > "Advanced..." > (Uncheck 'Automatic Metric') > Type in the text-box below that (Interface Metric) : 10.
  5. Click OK and OK and OK :)
  6. Then do the same for the other "Virtual Box-xxxxx" networks. But instead put 20 in the Interface Metric text-box.
  7. Click OK, OK and OK.
  8. Try restarting your app on Expo. It must work now!

Himujjal avatar Jul 21 '17 20:07 Himujjal

I had a similar issue as @Himujjal . I had VMWare installed. Going to network connections and deactivating all of them solved the problem.

rottenoats avatar Sep 25 '17 18:09 rottenoats

I couldn't get the above items to work. Although my problem is running Hyper-V. I just disabled the Ethernet connection for Hyper-V while running react-native.

clarkgrg avatar Oct 17 '17 05:10 clarkgrg

If you set env var REACT_NATIVE_PACKAGER_HOSTNAME to desired IP, then it will use that address. More info here https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md#configuring-packager-ip-address

andriy-f avatar Jan 11 '18 10:01 andriy-f

For info, other tools like Ionic let you choose which network interface to serve from.

For windows, running SET REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.5 in the terminal (or permanently in the environment variable settings) is the best option, much more so that messing with your adapter settings.

webprofusion-chrisc avatar Jan 19 '18 09:01 webprofusion-chrisc

Hey all and thxn @smiled0g i think this comment should be added in docs many of us using windows and we have problem tnx again my problem is solved too

spyp avatar Jan 20 '18 11:01 spyp

@webprofusion-chrisc Even though I have updated both the current CMD session and the registry by using set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.0.96 and setx REACT_NATIVE_PACKAGER_HOSTNAME 192.168.0.96. Doing a yarn start displays the ip exp://192.168.56.1:19000 which is my VirtualBox Ip.

Additionally, doing a ls env: on PowerShell shows me -> image

Also, here is my ipconfig image

Are there any additional settings that need to be changed?

EDIT Was a restart issue. Now, yarn start was picking up the new environment variable value.

Bryze avatar Feb 19 '18 13:02 Bryze

@Bryze actually I haven't seen 'setx' before, you learn something new every day. The conventional way is to go to Control Panel\System and Security\System > Advanced system settings, then Environment Variables, you can then set the variable at the user or system level. You then need to close and reopen the command window you're working in (or any other dependant processes which spawned before you changed it).

webprofusion-chrisc avatar Feb 19 '18 23:02 webprofusion-chrisc

@webprofusion-chrisc yes indeed that's the conventional way. I had some doubts settings environment variables as all I could see in it were paths. So that confused me a little bit.

However, FYI when we do setx places them in the environment variables section. So, after using setx, if you head over to the same window via the conventional way, you'll see your newly set variable there! :)

Bryze avatar Feb 20 '18 10:02 Bryze

Don't forget to open the required firewall ports too on your laptop; in my case, seems to be 19000 and 19001. (Right?)

kajmagnus avatar Feb 24 '18 14:02 kajmagnus

In my case (Ubuntu) the problem was always the ports.

To open them, these are the commands:

sudo ufw enable

sudo ufw allow 19000

sudo ufw allow 19001

GBurgardt avatar Mar 26 '18 23:03 GBurgardt