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).
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 host172.21.240.1
is the IP address of the vEthernet (WSL) adapter172.21.251.69
is the IP address of the Ubuntu 20.04 running inside WSL2 (obtained by runningip addr | grep eth0
). I canping 172.21.251.69
fromcmd
.
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).