如何在 WSL2 上设置工作 X11 转发 [英] How to set up working X11 forwarding on WSL2

查看:30
本文介绍了如何在 WSL2 上设置工作 X11 转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从 WSL1 迁移到 WSL2 时,很多事情都会发生变化;显然这也适用于 X11 转发.
我需要执行哪些步骤才能在 Windows 10 上使用 X11 转发和 WSL2,就像我对 WSL1 所做的那样?

解决方案

TL;DR:

将以下内容添加到您的 ~/.bashrc:

export DISPLAY=$(ip route list default | awk '{print $3}'):0导出 LIBGL_ALWAYS_INDIRECT=1

在适用于 Windows 的 X11 服务器上

启用公共访问.*

TCP 端口 6000 的单独入站规则添加到 Windows 防火墙,以允许 WSL 访问 X 服务器,如
或者直接使用 ac 标志调用 vcxsrv.exe:vcxsrv.exe -ac 正如 ameeno 关于 github 问题.

或者this SO answer展示了如何通过 .Xauthority 文件共享密钥,从而为您提供完整的访问控制.p>

When moving from WSL1 to WSL2 many things change; apparently this applies to X11 forwarding as well.
What steps do I need to make in order to use X11 forwarding with WSL2 on Windows 10 as I did with WSL1?

解决方案

TL;DR:

Add the following to your ~/.bashrc:

export DISPLAY=$(ip route list default | awk '{print $3}'):0
export LIBGL_ALWAYS_INDIRECT=1

Enable Public Access on your X11 server for Windows.*

Add a separate inbound rule for TCP port 6000 to the windows firewall in order to allow WSL access to the X server, as described by the wsl-windows-toolbar-launcher people.


As pointed out by WSL_subreddit_mod on reddit and as you can read in Microsoft's documentation on WSL2, the WSL2 architecture uses virtualized network components. This means that WSL2 has a different IP address than the host machine. This explains why the X11 forwarding settings of WSL1 cannot simply be transferred to WSL2.

On the Ubuntu Wiki page about WSL you can already find a configuration adapted for WSL2 under Running Graphical Applications. A similar configuration is also suggested by the above mentioned Reddit User, who also contributes another part of the solution: Enable Public Access on the X11 server under Windows.

This means add the following to your ~/.bashrc:

export DISPLAY=$(ip route list default | awk '{print $3}'):0
export LIBGL_ALWAYS_INDIRECT=1

And Enable Public Access on your X11 server for Windows.*

The most important part to enable X11 forwarding for WSL2 on Windows 10 is still missing: the Windows firewall blocks connections via the network interface configured for WSL by default.
A separate inbound rule for TCP port 6000 is required to allow WSL access to the X server. After the rule has been created, as described by the wsl-windows-toolbar-launcher people, the IP address range can be restricted to the WSL subnet in the settings of the newly created rule, under Scope: 172.16.0.0/12.

*: If you use VcXSrv you can enable public access for your X server by disabling Access Control on the Extra Settings:

Or by calling vcxsrv.exe directly with the ac flag: vcxsrv.exe -ac as pointed out by ameeno on the github issue.

Alternatively this SO answer shows how to share keys via .Xauthority files, leaving you with intact access control.

这篇关于如何在 WSL2 上设置工作 X11 转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆