microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.89k stars 797 forks source link

Unable to connect to server on Windows from WSL #11720

Open BlackStar7713 opened 1 week ago

BlackStar7713 commented 1 week ago

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?

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

github-actions[bot] commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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