Set up WSL2 on windows
Chun-Jie Liu · 2022-05-19
Prerequisites
You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11, here.
WSL install
wsl --install
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --install -d Ubuntu
wsl --set-default-version 2
# then restart computer.
Install Ubuntu WSL will take few minutes. After installation finished, it requires username and password for sudo privileges.
Chagne the default Linux distribution installed
wsl -l -v
wsl -l -o
.wslconfig
[wsl2]
processor=8
memory=8G
localhostForwarding=true
Install Docker WSL2 backend
Instruction refer to here
wsl -l -v
wsl --set-default-version 2
wsl --set-default Ubuntu
Manual installation steps for older version of WSL
refer to here
- Enable the Windows Subsystem for Linux (WSL) feature
- Check requirements for running WLS 2
- Enable Virtual Machine feature
- Download the Linux kernel update package
- Set WSL 2 as your default version
WSL and Cisco Anyconnect VPN internet issue, here and here.
Step 1
Open powershell as Admin and run the following commands, and take nots of DNS/namesever
Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses
Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList
Step 2
Open WSL and run the following commands with previous DNS and nameservers.
sudo unlink /etc/resolv.conf
#prevent wsl2 from overwritting the resolve.conf file everytime you start wsl2
cat <<EOF | sudo tee -a /etc/wsl.conf
[network]
generateResolvConf = false
EOF
cat <<EOF | sudo tee -a /etc/resolv.conf
nameserver *.*.*.* # The company DNS/nameserver from the command in step 1
nameserver *.*.*.* # The company DNS/nameserver from the command in step 1
nameserver *.*.*.* # The company DNS/nameserver from the command in step 1
nameserver 8.8.8.8
nameserver 8.8.4.4
search domain.com # The search domain that we got from step 2
EOF
Step 3
Change Cisco Anyconnect metric from default 1 to 6000 in powershell.
Changing the Interface Metric 1 -> 6000 for AnyConnect VPN Adapter resolves the connection issue, but this has to be done after each time the VPN connects.
By default, the Interface Metrics for AnyConnect are:
- IPv6: 6000
- IPv4: 1 ping times out from WSL Shell.
Changing the Interface Metrics for AnyConnect to:
- IPv6: 6000
- IPv4: 6000 ping to IP Addresses succeed, but still no DNS Resolution.
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
Step 4
Restart WSL2 on the same powershell.
Restart-Service LxssManager