苦逼前端

WSL2 配置 V2rayN 代理

Javascript2025-12-07 01:50:15proxy

Windows: v2rayN客户端开启“允许来自局域网的连接”

配置WSL2 DNS

WSL2: 关闭自动更新dns
新建配置文件
vim /etc/wsl.conf
写入以下内容

[network]
generateResolvConf = false

编辑以下文件的nameserver为 8.8.8.8 1.1.1.1等常用不受污染的dns服务器
vim /etc/resolv.conf

打开bash配置文件
vim ~/.bashrc
加入以下内容

export hostip=$(ip route | grep default | awk '{print $3}')
export hostport=10811
alias proxy='
    export https_proxy="http://${hostip}:${hostport}";
    export http_proxy="http://${hostip}:${hostport}";
    export all_proxy="http://${hostip}:${hostport}";
    echo -e "Acquire::http::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
    echo -e "Acquire::https::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias unproxy='
    unset https_proxy;
    unset http_proxy;
    unset all_proxy;
    sudo sed -i -e '/Acquire::http::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
    sudo sed -i -e '/Acquire::https::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
'
讨论(2)
  • 邢文亮1个月前

    你好

  • 邢文亮16天前

    最新的 WSL2 已经支持了「镜像模式(Mirrored Mode)」,开启镜像模式后,WSL2 将直接使用 Windows 的网络接口,两者的 IP 完全一致,可以直接通过 localhost 互访。需要 Windows 11 22H2 以及 WSL 2.0.4

还可输入2000个字
京公网安备 11011202003202号 鲁ICP备 13027548号-1