How to avoid a few pitfalls of WSL2 with ubuntu distribution.
Abstract
WSL2 is a very good feature which we had been waiting for long time. It gives us the ability to use Linux on Windows OS on easy and trusted manner.
Microsoft wrote good instructions for installing WSL2, though in reality things don’t go completely straightforward. There are a few pitfalls you may meet. So that I wrote this article.
Prerequisites
You have done what official instructions say and installed Ubuntu 20.04.2 LTS.
Pitfall 1: DNS resolution failed
You may encounter DNS resolution failure e.g. when you do “sudo apt-get update”. That is because the DNS server IP address in your Linux is set to the IP address of the virtual network interface attached to WSL network on your Windows host. In other words, your DNS resolution request is sent forward to your Windows host so that the request is failed.
It is a very famous problem and you can get a solution here. If you don’t know what DNS server you should use, set public DNS (e.g., 8.8.8.8 google provided) in case of private use and your corporate DNS server in the case connected to your corporate network.
My settings are following.
$ cat /etc/wsl.conf
[network]
generateResolvConf = false
$ cat /etc/resolv.conf
# Google
nameserver 8.8.8.8
nameserver 8.8.4.4
Pitfall 2: Some sites have troubles in SSL certification
Some sites including Docker hub’s registry server (https://registry-1.docker.io) use Zscaler issued certification. Though Ubuntu doesn’t have Zscaler’s Root CA certification in its trusted store so that we can’t connect Docker registry server.
We shoud get two certifications listed below and put them into the trusted store.
- Zscaler Root CA
- Zscaler Intermediate Root CA (zscalerthree.net)
How to get certifications? Access zscaler.com from Chrome browser and click address bar’s key icon. When export, chose “Base-64 encoded X.509” option. You can download certifications one by one. After downloading, change files’ extension from “.cer” to “.crt”.
Instructions for loading them into Ubuntu’s trusted store are listed below.
- put them into
/usr/local/share/ca-certificates/
- execute
update-ca-certificates --fresh
command
root$ ls /usr/local/share/ca-certificates/
zscaler.crt zscaler_intermediate.crt
root$ update-ca-certificates --fresh
Summary
Enjoy Linux life on Windows OS!