1. Start ssh service
1.1. Open WSL
1.2. Type: sudo service ssh start
2. Get Windows (WSL net) IP
2.1. Open Powershell
2.2. Type: (ipconfig | Select-String -Pattern 'WSL' -Context 1, 5).Context.PostContext | Select-String -Pattern 'IPv4'
2.3. Get the received IP
3. Set environment variable
3.1. In WSL2 terminal type: export DISPLAY=172.23.64.1:0.0 with the IP of the windows entity (2.3) instead of the place holder
4. Launch Xming
4.1. Open Xlaunch and go with the defaults In Specify parameter settings: Check No Access Control
5. Good luck!
在 Windows 上,使用以下命令,将 E:\VcXsrv改为安装位置,并将其保存为 xxx.bat,在 Windows 启动文件夹中,例如 C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup,如果愿意,可以让它在启动时运行:
@ECHO OFF
REM Start WSL once to create WSL network interface
wsl exit
REM Find IP for WSL network interface
SET WSL_IF_IP=
CALL :GetIp "vEthernet (WSL)" WSL_IF_IP
ECHO WSL_IF_IP=%WSL_IF_IP%
setx "WSL_IF_IP" "%WSL_IF_IP%"
setx "WSLENV" "WSL_IF_IP/u"
REM Change E:\VcXsrv to your VcXsrv installation folder
START /D "E:\VcXsrv" /B vcxsrv.exe -multiwindow -clipboard -nowgl -ac -displayfd 720
GOTO :EOF
:GetIp ( aInterface , aIp )
(
SETLOCAL EnableExtensions EnableDelayedExpansion
FOR /f "tokens=3 delims=: " %%i IN ('netsh interface ip show address "%~1" ^| findstr IP') DO (
SET RET=%%i
)
)
(
ENDLOCAL
SET "%~2=%RET%"
EXIT /B
)
我这样做的方式,并确保我得到 X11转发,无论我是使用静态 IP 地址或 DHCP 在 Windows 主机上,甚至无论我的主机名或网络位置改变,我添加以下到我的 ~/。Bashrc 文件:
# Get the IP Address of the Windows 10 Host and use it in Environment.
HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=$HOST_IP:0.0
export NO_AT_BRIDGE=1
export PULSE_SERVER=tcp:$HOST_IP
用途: 它使用主机命令从输出中提取与主机名相关联的 IPv4地址,抓取与包含 Windows Host IPv4地址的行相匹配的地址,除了 IP 地址外剥离其余信息,然后运行该地址并将其打印到变量中,输出被修剪。然后,使用它作为字符串提供必要的 IP 地址,以便在允许转发 X11和声音输出的环境变量中使用。