Mustafa Abbas
Mustafa Abbas

Reputation: 39

X11 Forwarding from WSL2 fails

I followed instructions on setting up X11 forwarding from my WSL2 to the host on Windows 10 with VcXsrv based on this answer: How to set up working X11 forwarding on WSL2

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1

I allowed public access while starting up VcXsrv, and also switched off my firewall just to test if it worked.

mustafa@DESKTOP-MGJG0RL:~$ xeyes
Error: Can't open display: 172.25.32.1:0

Is there a step that I'm missing?

Upvotes: 2

Views: 8158

Answers (3)

Lordie
Lordie

Reputation: 178

instead of disabling the firewall, try adding this rule (admin PowerShell)

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

Upvotes: 1

Mustafa Abbas
Mustafa Abbas

Reputation: 39

I was able to resolve it:

  1. In the sshd_config file
X11UseLocalhost yes
X11Forwarding yes
  1. Adapted from this answer https://superuser.com/a/1476160/1014728

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

  1. Use VcXsrv. Set -ac in the additional parameters field

  2. Run xhost + if you get a no protocol found error

  3. Run an xeyes to test

Upvotes: 0

Lars
Lars

Reputation: 11

I had the same issue. In my case the problem was that I disabled the Windows Firewall for private networks assuming that the network with the WSL 2 virtual machine would be considered a private network. But actually it turned out that this network is handled as a public network and therefore disabling the firewall for private networks did not help. So the short answer is: Set up a proper firewall rule instead of trying the shortcut with disabling the firewall for a quick try.

Upvotes: 1

Related Questions