39

I installed WSL2 and I want to access WSL2 GUI apps from Windows 10. For this, I installed Xming and start it in "No client" mode. Xming startes, ok. After I open the WSL2 terminal and there execute these commands

export DISPLAY=:0

And after

xeyes

And get error

Error: Can't open display: :0

X11Forwarding checked, yes.

Sizuji
  • 979

4 Answers4

47

Solved problem with executing this command

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

This command can also be added in shell initialization files, for example, .bashrc, .zshrc etc.

Also make sure to allow public access of X server running in Windows 10. For VcXsrv, -ac option is most important because it allows public access. For Xming, run through XLaunch and in the part "Specify parameter settings" select "No Access Control".

For more see this discussion Microsoft/WSL: Can't use X-Server in WSL2.

Tapuzi
  • 125
Sizuji
  • 979
13

I encountered this issue after changing the version of my WSL Ubuntu distribution from 1 to 2. Using

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

was not sufficient. According to https://github.com/microsoft/WSL/issues/6181 I needed to reconfigure the firewall. This can be done by

  • going to Advanced Security -> Inbound rules (admin permissions required)
  • delete all rules for Vcxsvr
  • restarting Vcxsvr, which prompts you to set Windows Firewall for this program
  • allow all (or enough) access

After these 2 changes, the problem was solved.

Josja
  • 131
3

Follow these steps:

  1. Open PowerShell as Administrator and run: New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

  2. Now open WSL2 and run: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0

  3. Now xeyes

0

For coLinux using eth0=slirp with the default configuration, Xming on the Windows host can be accessed using export DISPLAY=10.0.2.2:0 (or 0.0). Using biswapriyo's solution would not work in this case because slirp sets the resolver IP to 10.0.2.3, but his answer made me realize what I was doing wrong.

jcomeau_ictx
  • 859
  • 10
  • 15