xv6实验:Ubuntu2004 WSL2实验环境配置(包括git clone网络问题解决方法)
基本配置参考MIT6.S081 Ubuntu22.04 WSL2实验环境配置,wsl安装配置参考本栏的另一篇文章WSL2(ubuntu20.04)+vscode联合开发(附迁移方法)
如执行:
git clone git://github.com/mit-pdos/xv6-riscv.git
出现错误,或者无法clone情况,可以挂一个代理,然后按如下方法修改网络配置,使主机Windows的代理镜像到WSL
1.获取 Windows 主机在 WSL 中的 IP:
在WSL执行:
ip route show default | awk '/default/ {print $3}'
输出WIN_IP(通常是 172.x.x.x 或 192.168.x.x,比如 172.22.1.1)
2.确认 Windows 代理如clash允许 “局域网访问”
3.验证代理端口:
在 Windows 中打开「命令提示符(CMD)」,执行 netstat -ano | findstr “代理端口”(比如代理端口是 7890,就执行 netstat -ano | findstr “7890”),确认输出中包含 0.0.0.0:7890(而非仅 127.0.0.1:7890),说明局域网访问已开启。
4.网络配置修改:
①临时修改方案:
在WSL输入:
# 1. 配置 HTTP 代理
export HTTP_PROXY=http://WIN_IP:代理端口
export http_proxy=http://WIN_IP:代理端口# 2. 配置 HTTPS 代理(大部分工具需要这个)
export HTTPS_PROXY=http://WIN_IP:代理端口
export https_proxy=http://WIN_IP:代理端口
WIN_IP是第一步获取的,代理端口在clash查看.
然后执行:ping https://www.google.com 有输出即成功.
②永久配置(所有终端生效):
如果需要每次打开 WSL 都自动生效,可将代理配置写入 WSL 的 shell 配置文件(根据你的 shell 选择,比如 bash 用 .bashrc,zsh 用 .zshrc):
# bash 用户(默认)
nano ~/.bashrc# zsh 用户(如果用 zsh)
nano ~/.zshrc
然后在文件末尾添加以下内容(替换 WIN_IP 和 代理端口):
# WSL 代理配置(替换为你的 WIN_IP 和代理端口)
export WIN_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export HTTP_PROXY=http://$WIN_IP:7890
export http_proxy=$HTTP_PROXY
export HTTPS_PROXY=http://$WIN_IP:7890
export https_proxy=$HTTPS_PROXY
# export ALL_PROXY=socks5://$WIN_IP:7890 # 如需 SOCKS5 则取消注释
保存并生效配置:
# bash 用户
source ~/.bashrc# zsh 用户
source ~/.zshrc
结成功clone:
祝贺!