Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shaunakv1/37b513c86d95393b18904b7c55bd8ce2 to your computer and use it in GitHub Desktop.
Save shaunakv1/37b513c86d95393b18904b7c55bd8ce2 to your computer and use it in GitHub Desktop.
How to install WSL 2 and Ubuntu on windows 10 and setup network access for VPN

(optional but recommended) Install Windows Terminal Application using one of the three Options:

  1. Windows App Store
  2. NOAA Users should use Software Center Windows Terminal
  3. Install from Github Releases

We will use the new Windows windows terminal app for the rest of the steps. If you chose not to install it. then you may use Windows Powershell Application. For WSL commands, have another PowerShell window logged into wsl using (wsl) command once you have wsl installed.

Open Powershell in Admin mode

wsl --install

#verify you have wsl version 2  
wsl -l -v
You should have Ubuntu at this point. But if not install it with next step. Else skip to next step

#install ubuntu 
wsl.exe --install -d Ubuntu-22.04

#Setup a username and password for your WSL

Note: if Ubuntu was installed by default for you when you installed WSL, note that the default name for "distro" used for -d flags in the tutorial will be Ubuntu. If you installed it manually it will be Ubuntu-22.04.

Fix for DNS resoluction when connected to VPN using CISCO

  1. (go to etc folder in WSL).
 cd ~/../../etc 
  1. Create wsl.conf file and add content to it with the following commands
   echo "[network]" | sudo tee wsl.conf 
   echo "generateResolvConf = false" | sudo tee -a wsl.conf
  1. Delete resolve.conf from /etc
   sudo rm -Rf /etc/resolv.conf	
  1. In CMD Prompt Run
ipconfig /all | findstr /R "DNS\ Servers"

you should see output like so. Copy the (hopefully first) DNS from the output that belons to your vpn network adapter.If you are not sure then check windows network adapter properties for the right vpn connection and copy the dns server from there.

image

  1. Create resolv.conf and append the line
    echo "nameserver <dns copied in last step>" | sudo tee -a resolv.conf
    echo "nameserver 8.8.8.8" | sudo tee -a resolv.conf

At this point your /etc/resolv.conf should look like so

image

  1. Lock resolve.conf for future changes
    sudo chattr +i resolv.conf
  1. Restart WSL in Powershell Admin Mode
   wsl --terminate Ubuntu
   wsl -d Ubuntu
  1. And finally in windows cmd, ps or terminal:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
  1. If upon updates you run into permission issues with WSL, restart WSL engine
Get-Service vmcompute | Restart-Service

Install Docker Desktop (or not, but please do)

  1. Download Docker Desktop from docker site
  2. Install it with default options
  3. Open Docker desktop settings and verify the following
    • Click resources > WSL Integration
    • Check "Enable integration with my default WESL distro"
    • Check Ubuntu 22.04

Generate a SSH key so we can use it to authenticate with Github and other servers

  1. Follow instructions on github docs here

  2. All set! Build something awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment