侧边栏壁纸
博主头像
乌拉队长博主等级

你只管努力,其余的交给命运

  • 累计撰写 125 篇文章
  • 累计创建 34 个标签
  • 累计收到 31 条评论

目 录CONTENT

文章目录

WSL2划分虚拟局域网并启动docker脚本

乌拉队长
2021-07-18 / 0 评论 / 0 点赞 / 1,298 阅读 / 924 字

WSL2划分虚拟局域网并启动docker脚本

  1. 将下面脚本保存为 WSL2划分虚拟局域网并启动docker脚本.bat
  2. 将该bat脚本复制到 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup目录下
  3. 重启系统。
@echo off
setlocal enabledelayedexpansion

wsl -u root service docker start | findstr "Starting Docker" > nul
if !errorlevel! equ 0 (
    echo docker start success
    :: set wsl2 ip
    wsl -u root ip addr | findstr "192.168.169.2" > nul
    if !errorlevel! equ 0 (
        echo wsl ip has set
    ) else (
        wsl -u root ip addr add 192.168.169.2/28 broadcast 192.168.169.15 dev eth0 label eth0:1
        echo set wsl ip success: 192.168.169.2
    )


    :: set windows ip
    ipconfig | findstr "192.168.169.1" > nul
    if !errorlevel! equ 0 (
        echo windows ip has set
    ) else (
        netsh interface ip add address "vEthernet (WSL)" 192.168.169.1 255.255.255.240
        echo set windows ip success: 192.168.169.1
    )
)
pause
0

评论区