static ip address

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 netsh int ipv4 show interfaces

Idx     Met         MTU          状态                名称
---  ----------  ----------  ------------  ---------------------------
  1          75  4294967295  connected     Loopback Pseudo-Interface 1
 10          50        1500  disconnected  WLAN
  3          35        1500  connected     以太网
 14          25        1500  disconnected  本地连接* 1
 12          25        1500  disconnected  本地连接* 2
 44          15        1500  connected     vEthernet (WSL (Hyper-V firewall))

setup static ip address:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@echo off

REM credits: https://sites.google.com/site/eneerge/scripts/batchgotadmin
REM Stored here in case that site goes down some day
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------

wsl -d  Ubuntu-22.04  -u root ip addr add 192.168.8.8/24 broadcast 192.168.8.255 dev eth0 label eth0:1

netsh interface ip add address "vEthernet (WSL (Hyper-V firewall))" 192.168.8.9 255.255.255.0