Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to server on Windows from WSL #11720

Open
1 of 2 tasks
BlackStar7713 opened this issue Jun 20, 2024 · 3 comments
Open
1 of 2 tasks

Unable to connect to server on Windows from WSL #11720

BlackStar7713 opened this issue Jun 20, 2024 · 3 comments

Comments

@BlackStar7713
Copy link

Windows Version

Microsoft Windows [Version 10.0.22631.3737]

WSL Version

WSL version: 2.2.4.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.153.1-microsoft-standard-WSL2

Distro Version

Ubuntu 22.04

Other Software

nodejs v20.15.0

Repro Steps

I have an issue connecting to a server, and during debugging I created this minimal example:
Follow instructions in https://learn.microsoft.com/en-us/windows/wsl/networking under Accessing Windows networking apps from Linux (host IP).
I created a simple nodejs server like follows;

const http = require('http');

// Define the port to listen on
const port = 5000;

// Create an HTTP server
const server = http.createServer((req, res) => {
  console.log('Received an HTTP request.');

  // Send a response
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, world!\n');
});

// Make the server listen on the specified port
server.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

When using curl http://127.0.0.1:5000 I get the expected response, and output in the server console
On WSL i checked /etc/resolv.conf for the nameserver ip (10.255.255.254 in my case) and called curl http://10.255.255.254:5000

Expected Behavior

I expect the response Hello World and a http request to be received by the server

Actual Behavior

The command fails:
curl: (7) Failed to connect to 10.255.255.254 port 5000 after 0 ms: Connection refused

Diagnostic Logs

WslLogs-2024-06-21_00-16-49.zip

Copy link

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Diagnostic information
Detected appx version: 2.2.4.0

@osamakhanedu
Copy link

osamakhanedu commented Jun 21, 2024

Hi, @BlackStar7713 can you try following steps and check if its work:

Step 1: Getting IP address of windows machine using following command.
ip route show | grep -i default | awk '{ print $3}'

Step 2: Try curl with the IP address you got in step 1 and port with your given port.

@BlackStar7713
Copy link
Author

BlackStar7713 commented Jun 21, 2024

Hi @osamakhanedu
the iproute command gave me 172.24.32.1 as an ip.
When using curl with it it times out:
curl: (28) Failed to connect to 172.24.32.1 port 5000 after 129745 ms: Connection timed out
I tried to attach a new log file but the zip is 45MB, more than GitHub allows. I'll try to put it on a file share and edit in a link soon
edit: https://drive.google.com/file/d/1kCccgGZEbG_oFKwoyF-VHyJqSfyGuAQl/view?usp=drive_link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants