Files
nexus/wiki/sources/wsl2-启动与网络配置指南.md

43 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "WSL2 启动与网络配置指南"
type: source
tags: []
date: 2026-04-17
---
## Source File
- [[raw/Home Office/WSL2 启动与网络配置指南.md]]
## Summary用中文描述
- 核心主题WSL2Windows Subsystem for Linux 2的安装启动与网络配置实操指南
- 问题域Windows 环境下 Linux 开发环境搭建,重点解决 WSL2 网络隔离导致的 GitHub/海外资源访问障碍
- 方法/机制:① `wsl --install` 快速安装;② `.wslconfig` 启用镜像网络模式mirrored mode实现 WSL2 与 Windows 共享网络堆栈;③ 终端代理环境变量手动配置;④ ghproxy.com 反向代理绕过网络限制
- 结论/价值:提供从零安装到生产可用的完整 WSL2 配置路径,镜像网络模式是最稳妥的解决方案,避免 NAT 模式下的 localhost 代理失效问题
## Key Claims用中文描述
- WSL2 默认使用 NAT 模式,导致 Windows 宿主机 localhost 代理无法被 WSL2 内部正确访问,这是 GitHub/海外资源连接失败的根本原因
-`.wslconfig` 中设置 `networkingMode=mirrored` + `dnsTunneling=true` + `autoProxy=true` 可使 WSL2 与 Windows 共享网络堆栈,是解决网络问题的推荐方案
- 使用 `ghproxy.com` 反向代理可绕过 GitHub 访问限制,适用于 uv 安装器、Hermes Agent 等工具的下载场景
## Key Quotes
> "WSL2 默认使用 NAT 模式,常会出现'localhost 代理无法镜像'或无法访问海外资源的情况。" — 背景说明
> "在 PowerShell 执行 `wsl --shutdown` 后重启 WSL。" — 镜像模式生效操作
## Key Concepts
- [[WSL2]]Windows Subsystem for Linux 2Windows 10/11 内置的 Linux 虚拟机环境,默认使用 NAT 网络模式
- [[镜像网络模式]]Mirrored Network ModeWSL2 与 Windows 共享网络堆栈的配置模式,使 WSL2 能直接访问 Windows 代理
- [[NAT模式]]WSL2 默认网络模式WSL2 拥有独立 IPlocalhost 代理不可用
- [[ghproxy]]ghproxy.com反向代理服务将 GitHub 资源 URL 替换为代理地址以绕过网络限制
## Key Entities
- [[Ubuntu]]WSL2 默认安装的 Linux 分发版
- [[Windows]]宿主操作系统WSL2 运行其上
- [[PowerShell]]Windows 命令行环境,用于执行 wsl 管理命令
## Connections
- [[Ubuntu Server]] ← related_to ← [[WSL2]]WSL2 是 Ubuntu 在 Windows 上的轻量运行方式)
- [[ubuntu-server科学上网]] ← related_to ← [[WSL2 网络配置]](均涉及 Linux 环境代理配置)
## Contradictions
- (无已知冲突)