WSL无法ping外网怎么办?

508 阅读1分钟

WSL无法ping外网怎么办?

  1. 在 Windows 的文件资源管理器中的文件路径中输入 %USERPROFILE%

  2. 在此目录下新建 .wslconfig 文件,然后将以下内容添加到文件中:

    # Settings apply across all Linux distros running on WSL 2
    [wsl2]
    
    # Limits VM memory to use no more than 8 GB, this can be set as whole numbers using GB or MB
    memory=8GB
    
    # Sets the VM to use eight virtual processors
    processors=8
    
    [experimental]
    autoMemoryReclaim=gradual    # 开启自动回收内存,可在 gradual, dropcache, disabled 之间选择
    networkingMode=mirrored      # 开启镜像网络
    dnsTunneling=true            # 开启 DNS Tunneling
    firewall=true                # 开启 Windows 防火墙
    autoProxy=true               # 开启自动同步代理
    sparseVhd=true               # 开启自动释放 WSL2 虚拟硬盘空间
    
  3. 重新启动 WSL
    在终端中输入命令:

    wsl --shutdown
    

    重启后,应该就能 ping 外网了。