Quantcast
Channel: Node cannot access network inside ubuntu multipass - Super User
Viewing all articles
Browse latest Browse all 2

Node cannot access network inside ubuntu multipass

$
0
0

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 medium2401:4900:1c2b:d225::/64 dev enp0s8 proto ra metric 200 expires 86143sec pref medium2401:4900:1c2b:d225::/64 via fe80::1 dev enp0s8 proto ra metric 200 expires 86143sec pref highfe80::/64 dev enp0s8 proto kernel metric 256 pref mediumfe80::/64 dev enp0s3 proto kernel metric 256 pref mediumdefault via fe80::1 dev enp0s8 proto ra metric 200 expires 1543sec pref low

It does have a default route set here.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images