如何在WSL2上设置工作的X11转发 [英] How to set up working X11 forwarding on WSL2
问题描述
从WSL1迁移到WSL2时,许多事情发生了变化.显然,这也适用于X11转发.
与在Windows 10上使用WSL1一样,要在Windows 10上将X11转发与WSL2一起使用,我需要采取什么步骤?
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:
将以下内容添加到您的~/.bashrc
:
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
在Windows的X11服务器上
启用公共访问.*
Enable Public Access on your X11 server for Windows.*
为 TCP端口6000 添加一个单独的入站规则到Windows防火墙,以允许WSL访问X服务器,如
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.
正如WSL_subreddit_mod在Reddit上指出的, 阅读
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.
在有关WSL的Ubuntu Wiki页面上,您已经可以在运行图形应用程序.上述Reddit用户还建议使用类似的配置,该用户还贡献了解决方案的另一部分:在Windows下的X11服务器上启用公共访问.
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.
这意味着将以下内容添加到您的~/.bashrc
:
This means add the following to your ~/.bashrc
:
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
在Windows的X11服务器上
并启用公共访问.*
And Enable Public Access on your X11 server for Windows.*
仍然缺少在Windows 10上为WSL2启用X11转发的最重要部分:Windows防火墙默认通过为WSL配置的网络接口阻止连接.
需要单独的入站规则(用于 TCP端口6000 ),以允许WSL访问X服务器.按照 wsl-windows-toolbar-启动器人员,则可以在新创建的规则的设置中,在作用域: 172.16.0.0/12 下,将IP地址范围限制为WSL子网.
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.
*:如果您使用 VcXSrv ,则可以通过禁用访问控制来启用X服务器的公共访问在附加设置"上:
或直接用ac
标志调用vcxsrv.exe
:vcxsrv.exe -ac
由
*: 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.
这篇关于如何在WSL2上设置工作的X11转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!