wsl2에서 ubuntu port를 외부컴퓨터에서 접근하려면 port가 막혀서 접근이 안된다.
예로, wsl2실행하는 컴퓨터에서 127.0.0.1:8080 (0.0.0.0:8080)로 code-server를 실행하면 정상적으로 작동하지만 외부접속을 하려고 실제 IP 주소로 접근하면 port가 막혀서 접속이 불가하다. wsl2를 실행하는 컴퓨터와 동일한 port를 사용하게끔 하는 명령어, 설정이다.
sudo apt install net-tools
# Make network.ps1 And Run in powershell as Admin with - .\network.ps1 -
./network.ps1
# Refer to https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723
# port 3000, 5000 flask, 8080 code-server, 4389 for RDS
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if ($found) {
$remoteport = $matches[0];
}
else {
Write-Output "IP address could not be found";
exit;
}
$ports = @(4389, 3000, 5000, 8080);
$connectports= @(3389, 3000, 5000, 8080)
for ($i = 0; $i -lt $ports.length; $i++) {
$port = $ports[$i];
Invoke-Expression "netsh interface portproxy delete v4tov4 listenport=$port";
Invoke-Expression "netsh advfirewall firewall delete rule name=$port";
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteport";
Invoke-Expression "netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port";
}
Invoke-Expression "netsh interface portproxy show v4tov4";
#
https://dev.to/vishnumohanrk/wsl-port-forwarding-2e22
WSL Port Forwarding
When you start a server in WSL, both Windows and Linux share the same local host. When using a WSL 1...
dev.to
_
반응형