windows:wsl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
windows:wsl [2021/09/02 10:51] – [WSL2 port forwarding] adminwindows:wsl [2022/12/27 17:56] (current) – [WSL2 port forwarding high cpu] admin
Line 1: Line 1:
-====== wsl vhdx compact, method ====== +====== wsl vhdx compact, method, reclaim  ====== 
-  * https://fiddley.wordpress.com/2014/01/27/dynamically-expanding-vhd-not-compacting-in-hyper-v/+  * diskpart https://fiddley.wordpress.com/2014/01/27/dynamically-expanding-vhd-not-compacting-in-hyper-v/ 
 +++++ Diskpart | 
 +<code BASH> 
 +select vdisk File=”I:\path\to\your.vhd” 
 +attach vdisk readonly 
 +compact vdisk 
 +detach vdisk 
 +</code> 
 +++++ 
 + 
 +====== WSL2 high cpu ====== 
 +<code> 
 +taskkill -IM "wslservice.exe" /F 
 +wsl --shutdown 
 +</code>
  
 ====== WSL2 port forwarding ====== ====== WSL2 port forwarding ======
-<code BASH> netsh interface portproxy add v4tov4 listenport=$PORT listenaddress=0.0.0.0 connectport=$PORT connectaddress=127.0.0.1 </code> 
  
   * https://www.tune-it.ru/web/alenet/blog/-/blogs/windows-wsl2-docker-zizn-posle-linux   * https://www.tune-it.ru/web/alenet/blog/-/blogs/windows-wsl2-docker-zizn-posle-linux
   * https://www.williamjbowman.com/blog/2020/04/25/running-a-public-server-from-wsl-2/   * https://www.williamjbowman.com/blog/2020/04/25/running-a-public-server-from-wsl-2/
 +
 +<code BASH> netsh interface portproxy add v4tov4 listenport=$PORT listenaddress=0.0.0.0 connectport=$PORT connectaddress=127.0.0.1 </code>
 +:!:
 +++++  PowerShell Script for tcp port forward|
 +<code bash>
 +
 +# Run on unprivileged user with WSL2
 +$remoteport = bash.exe -c "ip a s eth0 | grep 'inet '"
 +$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;
 +}
 +
 +Write-Host @remoteport
 +
 +
 +
 +# !!!! On privileged user !!!!
 +#[Ports]
 +#All the ports you want to forward separated by coma
 +$ports=@(1433,1434);
 +
 +# from previous step
 +$remoteport='172.31.28.155';
 + 
 +#[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 'WSL 2 Firewall Unlock' "
 +
 +#adding Exception Rules for inbound and outbound Rules
 +iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
 +iex "New-NetFireWallRule -DisplayName 'WSL 2 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";
 +}
 +
 +
 +# Show rules
 +netsh interface portproxy show all
 +
 +# Reset all
 +netsh interface portproxy reset
 +
 +</code>
 +++++
 +++++  PowerShell Script for udp port forward socat|
 +<code bash>
 +# https://serverfault.com/questions/1051667/forward-incoming-udp-packets-on-windows-server-to-client-on-different-interface
 +# udp forward https://mattryall.net/blog/udp-port-forwarding-with-socat
 +# distr https://sourceforge.net/projects/unix-utils/files/socat/1.7.3.2/
 +socat UDP4-RECVFROM:161,fork UDP4-SENDTO:localhost:10161
 +</code>
 +++++
 +
 +
 ====== Windows system linux ====== ====== Windows system linux ======
   * Шрифты git clone https://github.com/powerline/fonts.git   * Шрифты git clone https://github.com/powerline/fonts.git
  • windows/wsl.1630579893.txt.gz
  • Last modified: 2021/09/02 10:51
  • by admin