Install WSL
Run Powershell as admin and run this command:
1
2
|
wsl --install
wsl --install -d Debian
|
Or, you can search for “Debian” in the Microsoft Store and click “Get” to install.
Install Docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
sudo apt update && sudo apt upgrade
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt install --no-instport-https ca-certificates curl gnupg2
update-alternatives --config iptables # And select iptables-legacy
. /etc/os-release
curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo tee /etc/apt/trusted.gpg.d/docker.asc
echo "deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
|
Reference: Install Docker on Windows WSL without Docker Desktop
AutoStart Docker
Run this to start Docker daemon automatically when logging in if not running
1
2
3
4
5
6
|
echo '# Start Docker daemon automatically when logging in if not running.' >> ~/.bashrc
echo 'RUNNING=`ps aux | grep dockerd | grep -v grep`' >> ~/.bashrc
echo 'if [ -z "$RUNNING" ]; then' >> ~/.bashrc
echo ' sudo dockerd > /dev/null 2>&1 &' >> ~/.bashrc
echo ' disown' >> ~/.bashrc
echo 'fi' >> ~/.bashrc
|
Also create or edit /etc/wsl.conf with:
1
2
|
[boot]
command= service docker start
|
WSL Port Forwarding
First install net-tools:
1
|
sudo apt install net-tools
|
Mode 1
In Windows:
1
|
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=(wsl hostname -I).split(" ")[0]
|
Create rtorrent.ps1:
1
2
3
|
$wsl_ip = (wsl hostname -I).split(" ")[0]
Write-Host "WSL Machine IP: ""$wsl_ip"""
netsh interface portproxy add v4tov4 listenport=8080 connectport=8080 connectaddress=$wsl_ip
|
Then in Admin PowerShell:
1
2
|
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:15
Register-ScheduledJob -Trigger $trigger -FilePath C:\Users\marti\rtorrent.ps1 -Name RouteRTorrent
|
Mode 2
Create network.ps1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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 = @(80,9696,7878,5055,8989,8081,8191);
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";
|
Run the script with Admin PowerShell:
Autostart WSL
- Press Win + R and type
shell:common startup
- Create a file.vbs with:
1
2
|
set ws=wscript.CreateObject("wscript.shell")
ws.run "wsl -d Debian", 0
|
(Replace “Debian” with your distro name)
Alternatively, create a deb.bat file with:
SSH Configuration
In Admin PowerShell:
1
2
3
|
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent
|