参照这篇文章方法更好
wsl 设置静态ip遇到的一些问题 (安装好后不能联网)-CSDN博客
wsl2 安装后用 wifi 共享是能联网,问题出在公司网络限制 wsl2 IP 访问网络,但是主机可以上网。
解决办法,在主机用 nginx 设置代理,可能需要开端口权限
server {
listen 9000;
server_name localhost;
location /ubuntu/ {
# 阿里源镜像地址
proxy_pass https://mirrors.aliyun.com/ubuntu/; # 前端地址和端口
}
}
/etc/apt/sources.list
# 阿里源镜像地址
deb http://192.168.5.116:9000/ubuntu/ focal main restricted universe multiverse
deb http://192.168.5.116:9000/ubuntu/ focal-security main restricted universe multiverse
deb http://192.168.5.116:9000/ubuntu/ focal-updates main restricted universe multiverse
deb http://192.168.5.116:9000/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://192.168.5.116:9000/ubuntu/ focal main restricted universe multiverse
deb-src http://192.168.5.116:9000/ubuntu/ focal-security main restricted universe multiverse
deb-src http://192.168.5.116:9000/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://192.168.5.116:9000/ubuntu/ focal-backports main restricted universe multiverse
sudo apt update
酸爽