2

Update 1

If I package the code as a Docker image & run it, the curl commands work from inside WSL2 and from the Windows command line, so this is a Quarkus-specific issue.

Original

I have Ubuntu 20.04 installed on WSL2 on my Windows Home laptop.

Following the Quarkus Getting Started example (just up to step 5: Running the application), I have the code (server) running on my WSL2 bash command line, & calling it with curl gives the expected output:

user@computer:/path$ curl -w '\n' http://localhost:8080/hello
Hello RESTEasy

However, I can't access that server from the host Windows computer's command line (cmd):

C:\Users\username>curl -w "\n" http://localhost:8080/hello

curl: (56) Recv failure: Connection was reset

Unlike this WSL 2 Networking video, I am not trying to access the running server from outside my Windows host. I can't even reach the server running inside WSL2 Ubuntu from the Windows host.

Nonetheless, I tried this slightly modified script from an issue on Github:

#$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$remoteport = bash.exe -c "ip addr | grep -Ee 'inet.*eth0'"

$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";
  exit;
}

#[Ports]

#All the ports you want to forward separated by coma
$ports=@(8080);


#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";


#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL2-Firewall-Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL2-Firewall-Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL2-Firewall-Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}

The script ran fine after some settings changes, but I still couldn't reach the server running on WSL2. Couldn't reach it via browser (Vivaldi) either (see screenshot).

Can't reach WSL2 server via browser either

In desperation I tried the following, but none worked:

C:\Users\username>curl -w "\n" http://192.168.1.6:8080/hello

curl: (56) Recv failure: Connection was reset

C:\Users\username>curl -w "\n" http://172.21.240.1:8080/hello

curl: (56) Recv failure: Connection was reset

C:\Users\username>curl -w "\n" http://172.21.251.69:8080/hello

curl: (7) Failed to connect to 172.21.251.69 port 8080: Connection refused

where,

  • 192.168.1.6 is the IP address of my Windows host
  • 172.21.240.1 is the IP address of the vEthernet (WSL) adapter
  • 172.21.251.69 is the IP address of the Ubuntu 20.04 running inside WSL2 (obtained by running ip addr | grep eth0). I can ping 172.21.251.69 from cmd.

What am I doing wrong? I thought curl -w "\n" http://localhost:8080/hello would just work from the Windows host.

Winver reports Windows version as Version 2004 (OS Build 19041.1110).

markvgti
  • 4,321
  • 7
  • 40
  • 62

2 Answers2

4

I'm not familiar with Quarkus, but my "go to answer" for localhost forwarding not working in WSL is to try a wsl --shutdown and, if that works, disable Windows Fast Startup.

But in this case, you also aren't able to access it on the WSL2 instance's eth0 address, so something more might be going on. That could also be explained if the Quarkus boilerplate config is just binding to localhost or 127.0.0.1. You'd need it to bind to 0.0.0.0 in order for both to work.

Update for others looking at this answer in the future: Quarkus automatically binding to 127.0.0.1 or localhost did turn out to be the problem in this case. From @markvgti's research in the comments, the setting for this is to add quarkus.http.host=0.0.0.0 to the application.properties.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
0

As suggested in the update of NotTheDr01ds answer:

Add quarkus.http.host=0.0.0.0 to the application.properties worked for me

Joker
  • 2,304
  • 25
  • 36