Friday, August 06, 2021

Bring up internet on WSL2

I try install kali in WSL.
For WSL1, after install can online directly, but for WSL2, there is no internet, so here i show the step i fix it.

Solution for my case:
1) Need to enable hyper-v feature, and after bring up the kali instance, set the vEthernet(WSL) virtual switch to external.
2) Share LAN/WIFI internet for vEthernet(WSL). WSL ip will probably change to 192.168.137.1
3) in kali:
- add IP (eg 192.168.137.2) to eth0.
- bring up the eth0 and lo adapter
- add default route (to 192.168.137.1)
4) /etc/resolv.conf:
nameserver 192.168.137.1
5) add /etc/wsl.conf
[network]
generateResolvConf = false

* everytime you shutdown the kali or restart your windows, those setting will reset.
you will need to re-do the step (2) and (3),