Could not resolve host: github.com (on ubuntu wsl2)

As the title, when I type  $ git push   in command line, it returns error message " could not resolve host: github.com. "

Then I find out I also cannot ping google.com or github.com, so it's a network problem. (people say it's  DNS error)

After trying editing /etc/wsl.conf and /etc/resolv.conf to use nameserver 8.8.8.8 as many people suggest, the problem is still not fixed.

I eventually find out when I type $ ifconfig  , it returns nothing. So there is completely no network available.

Anyway, I find out the solution is to disable swap.
In cmd: type $ notepad %UserProfile%\.wslconfig to open .wslconfig and then add swap=0 in this file.
Still not understanding the reason but it magically fixes the problem.

留言