2

I have a multipass virtual machine (ubuntu 22.04.1) on my windows 10 laptop. I installed node v18.13.0 (now v19.5.0) through nvm on it. My node installation is not able to access the network at all.

It first started with npm. npm install kept hanging up. After a long time, it finally timed out. Then I wrote a simple script that just fetched example.org and that too timed out. Then I started a simple python server on the same vm and tried to access that using node. I got an ECONNREFUSED at the connect call.

In all of this, curl has been working perfectly fine. It could reach out to registry.npmjs.org, example.org and localhost just fine.

I do not have any firewalls or vpns (at least as far as I am aware) and I am on my home internet, if that matters.


UPDATE: I changed localhost to 127.0.0.1 and then node.js was able to make the connection! I also retrieved the ip address for example.org and tried that. It gave a 404 but the connection did get made! Trying to use fetch with domain names still fails but giving it explicit ip address and port works. Curl still works with both ip addresses and domain names of course.


UPDATE: Ok, I figured out the problem with localhost at least. The python http.server I was using default bound itself only to IPv4 but nodejs was trying to connect to the IPv6 address. Starting the python server with --bind :: got that part working. I still don't know anything about external domains though.


UPDATE: I tried running a python proxy on localhost (using proxypy) and setting npm config set proxy http://localhost:8899. In the logs, I saw that the first few CONNECT did return some data but after a little while, every CONNECT call started outputting 0 bytes. There was no response to the requests.

Just to be clear, I have had this virtual machine for quite some time now and I have been able to access internet from it just fine. I can use curl, git, apt, cargo, etc and they can all download stuff easily. It is only with npm / node that I am facing this problem.


UPDATE: So I figured out the problem! Node.js does not fallback to IPv4 if IPv6 was unreachable. curl, python etc do do this so I did not face any problem there. Running curl with an explicit v6 ip caused it to hang up like npm as well. Apparently, IPv6 is not enabled on multipass vms by default.

I think it looks enabled on mine though. Here is the output of ip -6 route show:

::1 dev lo proto kernel metric 256 pref medium
2401:4900:1c2b:d225::/64 dev enp0s8 proto ra metric 200 expires 86143sec pref medium
2401:4900:1c2b:d225::/64 via fe80::1 dev enp0s8 proto ra metric 200 expires 86143sec pref high
fe80::/64 dev enp0s8 proto kernel metric 256 pref medium
fe80::/64 dev enp0s3 proto kernel metric 256 pref medium
default via fe80::1 dev enp0s8 proto ra metric 200 expires 1543sec pref low

It does have a default route set here.

1 Answers1

3

I think the explanation of the problem is found in the post IPv6 not working on VMs created using multipass.

I quote here the answer by "dummyuser" (his moniker) :

Multipass uses a separate network between client and host called mpqemubr0 (you may have a different interface name). This network does not provide IPv6 info via dhcpdv6 or radvd (or both). Your IPv6 routing table can be seen with ip -6 route show Guess your client does not have a default route for IPv6.

Your Options:

  1. Add radvd/dhcpdv6 to the host providing IPV6 Info on the Multipass interface. Your host acts as a IPv6 router, maybe you will need some more ip6tables rules for masquerading, IPv6 forwarding must be enabled

  2. Change the type on the multipass interface towards a bridged network instead of routing. See Multipass documentation

  3. Switch to docker if your use case allows it, even here IPv6 does not work out of the box, but it much faster

A similar post is Interface name needed in IPv6 address from multipass VM (but not from host or non multipass VM), where the author gave up on his multipass VM and moved on to Docker. Detailed instructions can be found in this post for setting up Docker with IPv6.

harrymc
  • 498,455