Install Clash First

  • WSL2 + Ubuntu
  • Incorporate the following into your shell profile, such as .bashrc or .zshrc
host_ip=$(cat /etc/resolv.conf | grep "nameserver" | cut -f 2 -d " ")
export all_proxy=http://$host_ip:7890
export http_proxy=http://$host_ip:7890
export https_proxy=http://$host_ip:7890

Alternate Method

  • Recognize that /etc/resolv.conf is auto-generated by WSL
  • To manage this, create a file /etc/wsl.conf and insert:
[network]
generateResolvConf = false
  • Execute wsl --shutdown and restart WSL2
  • Unlink resolv.conf unlink /etc/resolv.conf

Thanks