microsoft/WSL

Can't use X-Server in WSL 2

toml12953 opened this issue ยท 140 comments

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.18917.1000] with Ubuntu 18.04, WSL 2.
    VcXsrv X Server Version 1.20.1.4

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

Trying to run z80pack, a Z-80 CPU simulator.
Before update to WSL 2, z80pack would open a graphical representation of an IMSAI computer. Now, I get the following error:
FrontPanel Simulator v2.1 Copyright (C) 2007-2015 by John Kichury
Can't connect to display ":0"
Segmentation fault

  • What's wrong / what should be happening instead:
    A picture of an IMSAI computer should appear in a separate window.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

tom@TOM-HOME-PC:~/z80pack/imsaisim$ strace ./cpm22
execve("./cpm22", ["./cpm22"], 0x7ffd01082fd0 /* 23 vars */) = 0
brk(NULL)                               = 0x55675a8f8000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
openat(AT_FDCWD, "tls/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=63323, ...}) = 0
mmap(NULL, 63323, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd3e1cea000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd3e1ce8000
mmap(NULL, 4131552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd3e16e2000
mprotect(0x7fd3e18c9000, 2097152, PROT_NONE) = 0
mmap(0x7fd3e1ac9000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7fd3e1ac9000
mmap(0x7fd3e1acf000, 15072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd3e1acf000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7fd3e1ce9540) = 0
mprotect(0x7fd3e1ac9000, 16384, PROT_READ) = 0
mprotect(0x55675a19a000, 8192, PROT_READ) = 0
mprotect(0x7fd3e1cfa000, 4096, PROT_READ) = 0
munmap(0x7fd3e1cea000, 63323)           = 0
getuid()                                = 1000
getgid()                                = 1000
getpid()                                = 33
rt_sigaction(SIGCHLD, {sa_handler=0x556759f91200, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
geteuid()                               = 1000
brk(NULL)                               = 0x55675a8f8000
brk(0x55675a919000)                     = 0x55675a919000
getppid()                               = 31
stat("/home/tom/z80pack/imsaisim", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
openat(AT_FDCWD, "./cpm22", O_RDONLY)   = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
geteuid()                               = 1000
getegid()                               = 1000
rt_sigaction(SIGINT, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x556759f91200, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=SIG_DFL, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
read(10, "#!/bin/sh\n\nrm -f disks/drivea.ds"..., 8192) = 108
stat("/home/tom/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/home/tom/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/rm", 0x7ffe267a5cd0)    = -1 ENOENT (No such file or directory)
stat("/usr/bin/rm", 0x7ffe267a5cd0)     = -1 ENOENT (No such file or directory)
stat("/sbin/rm", 0x7ffe267a5cd0)        = -1 ENOENT (No such file or directory)
stat("/bin/rm", {st_mode=S_IFREG|0755, st_size=63704, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 34
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 34
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=34, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 34
stat("/home/tom/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/home/tom/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/ln", 0x7ffe267a5cd0)    = -1 ENOENT (No such file or directory)
stat("/usr/bin/ln", 0x7ffe267a5cd0)     = -1 ENOENT (No such file or directory)
stat("/sbin/ln", 0x7ffe267a5cd0)        = -1 ENOENT (No such file or directory)
stat("/bin/ln", {st_mode=S_IFREG|0755, st_size=67808, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 35
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 35
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=35, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 35
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 36
wait4(-1,
 #####    ###     #####    ###            #####    ###   #     #
#     #  #   #   #     #  #   #          #     #    #    ##   ##
#     # #     #  #     # #     #         #          #    # # # #
 #####  #     #   #####  #     #  #####   #####     #    #  #  #
#     # #     #  #     # #     #               #    #    #     #
#     #  #   #   #     #  #   #          #     #    #    #     #
 #####    ###     #####    ###            #####    ###   #     #

Release 1.36, Copyright (C) 1987-2017 by Udo Munk
IMSAI 8080 Simulation Release 1.17, Copyright (C) 2008-2017 by Udo Munk

CPU speed is 2 MHz
RAM size is 54 KB

Loader statistics for file bootrom.hex:
START : d800H
END   : df7fH
LOADED: 0780H (1920)

FrontPanel Simulator v2.1 Copyright (C) 2007-2015 by John Kichury
Can't connect to display ":0"
[{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 36
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=36, si_uid=1000, si_status=SIGSEGV, si_utime=3, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 36
write(2, "Segmentation fault\n", 19Segmentation fault
)    = 19
read(10, "", 8192)                      = 0
exit_group(139)                         = ?
+++ exited with 139 +++

How are you seeing your DISPLAY variable in your Linux environment? Currently you will need to specify the IP address of the host, you can easily find this by looking at your /etc/resolv.conf file:

root@BENHILL-DELL:/mnt/c/Users/benhill# cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.110.177

Then you'll run:

export DISPLAY=192.168.110.117:0

You may also need to launch vcxsrv with the -ac argument.

This is an area that we are working on improving in an update soon.

Thank you! I added -ac to the vcxsrv command line and changed the export statement to use the IP address and now I can run GUI programs again.

is there a command i can use to return this IP address only? (not the comments or the word nameserver, jus tthe IP itself

Yes in the bash shell you can run:

cat /etc/resolv.conf | grep nameserver | awk '{print $2}' 

You could combine into:

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

Thanks guys, this works.

I think vcxarv needs -ac argument to work

i have the same issue, I tried to do what you are saying guys but no luck I cant launch any GUI with wsl2 in my X Server

and I forgot , the only thing I didn't tried is to launch vcxsrv with -ac argument if you can explain beter how to do it, that will be helpful cause I cant with export DISPLAY=my host ip:0 I got the message that xfce4-session cant display

I have the same issue as @sithlord2 . Below is my configuration of VcXsrv:
01

02

03

When I tried to launch gedit by DISPLAY=172.17.104.241:0.0 gedit, the command got stuck:

PS C:\Users\simon> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Stopped         2
  Ubuntu-18.04    Stopped         1
PS C:\Users\simon> wsl
simon@QGHRP0C:/mnt/c/Users/simon$ cd
simon@QGHRP0C:~$ sudo apt install gedit
simon@QGHRP0C:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.17.104.241
simon@QGHRP0C:~$ ifconfig | grep 'inet '
        inet 172.17.104.249  netmask 255.255.0.0  broadcast 172.17.255.255
        inet 127.0.0.1  netmask 255.0.0.0
simon@QGHRP0C:~$ DISPLAY=172.17.104.241:0.0 gedit

My systeminfo is:

PS C:\Users\simon> systeminfo

Host Name:                 QGHRP0C
OS Name:                   Microsoft Windows 10 Enterprise Insider Preview
OS Version:                10.0.18922 N/A Build 18922
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Original Install Date:     6/17/2019, 5:59:54 AM
System Boot Time:          6/18/2019, 1:39:58 AM
System Manufacturer:       HP
System Model:              HP Z4 G4 Workstation
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 4 GenuineIntel ~3600 Mhz
BIOS Version:              HP P61 v01.76, 4/22/2019
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Total Physical Memory:     32,488 MB
Available Physical Memory: 24,802 MB
Virtual Memory: Max Size:  37,608 MB
Virtual Memory: Available: 27,712 MB
Virtual Memory: In Use:    9,896 MB
Page File Location(s):     C:\pagefile.sys
Hotfix(s):                 N/A
Network Card(s):           6 NIC(s) Installed.
                           [01]: Intel(R) Ethernet Connection (2) I219-LM
                                 Connection Name: Ethernet
                                 Status:          Media disconnected
                           [02]: PANGP Virtual Ethernet Adapter
                                 Connection Name: Ethernet 8
                                 Status:          Media disconnected
                           [03]: Intel(R) I210 Gigabit Network Connection
                                 Connection Name: Ethernet 2
                                 DHCP Enabled:    Yes
                                 DHCP Server:     N/A
                                 IP address(es)
                           [04]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (Default Switch)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.41.241
                                 [02]: fe80::44dc:a5ae:5762:d831
                           [05]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (New Virtual Switch)
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.222.220.4
                                 IP address(es)
                                 [01]: 10.168.2.39
                                 [02]: fe40::f496:a4cd:e4dc:4f0a
                                 [03]: 2444:f501:58:45c:f576:b551:b5f8:35b8
                                 [04]: 2464:f861:46:46c:f696:a16d:e6dc:a60a
                           [06]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (WSL)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.104.241
                                 [02]: fe90::692b:f95c:9bcd:690
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

-ac is most important because it allows public access. Wsl2 is a VM with a different IP address

Hi @ameeno, is -ac equivalent to checking 'Disable access control' in the configuration above? If yes, I still cannot make GUI apps shown in Windows. If not, then where should I put -ac?

I think -ac is equivalent but best to try the flag. Right click on the shortcut to the application and select properties. On the box where it is the path to the app, append -ac.

Make sure you have closed the app and exited from the taskbar icon.

And launch using the shortcut you just edited

Also make sure your windows firewall is not blocking the connections

Thank you very much @ameeno. I think you are right, though I have no permission to turn off the firewall of Windows to prove it.

Simonzhaoms , if you in powers hell type systeminfo at the bottom of all your gonna get an ip which is your ip address just export DISPLAY=THAT IP ADDRESS :0 AN YOU CAN LAUGH YOU APPS ON YOUR X SERVER :)

I did that an worked for me

I've tried to do all of the instructions but now I'm just stuck at X server already running on display IP:0.

Oh I had the firewall set to the wrong type of network. I apologise.

is any body here that ,have the problem of getting DC of the internet every 5 o 15 minutes after launching xserver since i download and install the 18917 and yesterday 18922 that says ,it fixes bugs and other staff but still getting DC is because the linux kernel on the subsystem is stiil as test kernel or both the NT kernel and the linux kernel are run by hyper-v , cause since i upgrade and register in windows insider ,i'm having that problem of DC my internet ,before that i didnt have any of that problem.

is any body here that ,have the problem of getting DC of the internet every 5 o 15 minutes after launching xserver since i download and install the 18917 and yesterday 18922 that says ,it fixes bugs and other staff but still getting DC is because the linux kernel on the subsystem is stiil as test kernel or both the NT kernel and the linux kernel are run by hyper-v , cause since i upgrade and register in windows insider ,i'm having that problem of DC my internet ,before that i didnt have any of that problem, and im really getting tired of it.

i hope mscraiglowen can answer me, if not a problem ,with my post above this, cause that problem started when i change from wsl1 to wsl2 een before making work now my x-server i started getting Disconnected from internet ,i ask cause before changing to wsl2 i havent had that problem, thats why i asked about if both kernels are run by hyper-v , i mean the NT kernel and theNew wsl linux kernel or only the windows subsystem kernel.

for got my real name is enrique

Hi @sithlord2 , if you're getting disconnected every 5 to 15 minutes when running an X server please open up a new issue describing that problem, this issue is already resolved as it's focused on how to connect to an X server in the first place.

As far as your questions about kernels, WSL 2 doesn't have a test kernel, and I would be hard pressed to get why the kernel might be affecting your X server connection.

Again, please open up a new issue on this repo describing your problem with steps for us on how we can reproduce it and we will gladly take a look! Thank you.

Yes in the bash shell you can run:

cat /etc/resolv.conf | grep nameserver | awk '{print $2}' 

grep can get the FILE parameter, cat is useless.

grep nameserver /etc/resolv.conf | awk '{print $2}'

And even simpler

grep -oP "(?<=nameserver ).+" /etc/resolv.conf

That's something I had some issues to get working recently but finally managed to work out, I put some notes what I did on my Ubuntu 18.04 WSL2 installation, in case it's useful to others
https://community.ubuntu.com/t/getting-graphical-applications-to-work-on-wsl2/11868

Note that I had to disable the firewall to get those to work which is not a recommended solution, I would welcome help in figuring out what rules are required and how to set them up in the windows defender config if someone has a clue about that.

I got this working, but I also had to allow the process through the Windows Firewall and my screen number or whatever it's called was a different number than 0, so my display value was IP:XXX.0 (where XXX was my screen number). I saw this value in the server log and it also shows if you hover over the icon in the tray.

Agree with @seb128, would be good to know the firewall rules that have to be in place since disabling firewall is just a horrible idea

@L1ghtman2k For me it is working just fine without any custom firewall rules. However I can see vcxserv in the list of allowed apps in my firewall configuration. That entry was added automatically by the installation. No further firewall configuration was required.

Update: Ok, the above is not true at all. The installation creates an active vcxserv rule for private networks. But network interface over which WSL2 accesses the host is regarded as a public network!
So the existing rule needs to be enabled for public networks as well.

Hey @Alexwil, it seems like I did have following rule for vcxsrv.exe:
image
I have also added xlaunch.exe for exceptions
image,
however, that still did not resolve the issue :(

UPD:
One of the 2 things fixed this for me:

  • Reinstall Kali Linux from Microsoft store
  • use vcxsrv.exe -ac instead of xlaunch with -ac as an additional argument

So, then you can basically just use

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0

in your .bashrc?

That's working for me, btw. I also am just checking the box to disable access control, I can't figure out where you all are putting the -ac bit that actually works.

my firewall rules for Public networks:
image
image
the above, plus "disable access control" in my config.xlaunch
image
plus the "nameserver" trick

export DISPLAY=$(awk '/nameserver/ {print $2}' /etc/resolv.conf):0.0

Has me launching xterms from a Windows desktop icon that connect to vcxsrv.

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

it'd be nice if the 'localhost' hack worked both ways...

my /etc/resolv.conf did not have the correct IP address. I used the ipconfig command in powershell to show my correct local IP address. It is located under the "Ethernet adapter vEthernet (WSL)" section

should you happen to have the docker desktop with wsl2 support up, it looks like you can

cat /etc/hosts | grep host.docker.internal | awk '{print $1}'    

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs.
image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs.
image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

nice!

but this leaves us with
image

For me I had to enable all 4 options only then it is working.

  1. put the "-ac" option
  2. select "Disable access control"
  3. vi ~/.bashrc
    export DISPLAY=cat /etc/resolv.conf | grep nameserver | awk '{print $2}':0
  4. disable "firewall" (was using Nod32 firewall), switched to windows firewall and it by self asks whether to allow this application over the firewall and just select 'yes' for that.

I had Vcxsrv working for few apps like sublime text, eclipse. However, if I try to open "firefox", "VcXsrv" icon in the tray is hanged/freezed and now previously working apps also do nothing. How can I resolve the same?

With my setup, the nameserver is different, I ended up by using the default gateway:

export DISPLAY=$(ip r l default | cut -d\ -f3):0

FWIW, I didn't like to give everyone permission to my display with vcxsrv. Turns out that MobaXterm has a build-in X-server that asks permission every time a WSL app tries to open a window. I like that better than vcxsrv's open-for-all model (which seems to be equivalent to xhost -).

Just wanted to share how I got this working:

  1. Install Xming https://sourceforge.net/projects/xming/
  2. Insecure mode: edit the desktop shortcut and add the option -ac to the end OR Secure mode: go to the installation directory and add the WSL ip in X0.hosts
  3. Run export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 in WSL
Uzume commented

This type of code:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
can be shortened considerably to just:
export DISPLAY=$(/etc/resolv.conf < awk '/nameserver/ {print $2}'):0
I am not sure how big of an optimization that is (it depends on how often that is executed), however, now only the shell and awk are forked (removing the need to fork cat and grep).
It might be possible to do the parsing directly in the shell reducing the need to fork at all (but shell parsing is sort of painful).
Of course @tcztzy also mentioned using:
export DISPLAY=$(grep -oP "(?<=nameserver ).+" /etc/resolv.conf):0
but methinks awk is cleaner.

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs.
image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

After I restart my Windows, this configuration will fail. In fact, after windows restart, WSL Interface will not be created untill WSL is first started. And the new WSL Interface is different from the previous. So, the firewall must be reconfigured after restarting and running WSL.

@Discreater that's sadly the case indeed. To automate the clicks you can at least use this Powershell command (needs to be run as administrator):

Set-NetFirewallProfile -Name public -DisabledInterfaceAliases "vEthernet (WSL)"

I was able to use graphic applications in WSL using XMING and Export DISPLAY=:0.0

However, once I upgraded to WSL2 and switching to Export DISPLAY = 172.28.801:0 (my host#) it failed to connect

Things tried:

downloading VcXsrv
switching to another graphics application
running vcxsrv -ac from bash (command not recognized)
running vcxsrv -ac from powershell (command not recognized)
turning firewall off
My Windows 10 build: 19041.1

Here is a typical error message

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-lw' qt.qpa.screen: QXcbConnection:
Authorization required, but no authorization protocol specified
Could not connect to any X display.

In #4106 you advise to run "vcxsrv -ac" from the bash command line and at least one user accepted that as a solution. I downloaded vcxsrv.exe from sourceforge as an .exe outside of bash, and I see no way to execute it from bash

Many thanks

I made a "Run as Administrator" shortcut on my desktop for turning off the Windows firewall. The "Target:" is

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command " Set-NetFirewallProfile -DisabledInterfaceAliases 'vEthernet (WSL)'"

Why do I have to turn off the Windows firewall?

Linux X clients can't connect to a Windows X server unless you disable the firewall for the WSL interface

Thanks @rob-solana I see. And your script only disables it for that interface. I am observing another problem. If the network connection is interrupted for any reason, the X clients are killed. This is a terrible user experience. Why does it not work to set the DISPLAY to 127.0.0.1:0.0 ?

Yeah, just for that internal interface that (I hope) only Linux and Windows can see.

I'd guess that 127.0.0.1 doesn't work because the Windows' side 127.0.0.1 interface isn't route-able from the Linux side.

The loss of clients when you change networks is a well known annoyance. Dunno if there's a github issue for it.

Still a bit irritating and if really wanted you could embed something along these lines into PS1 but this is what I have started to use to work around the dynamic IP thing in my bashrc if it helps anyone:

export WSL_HOST=$(dig +noall +answer $(hostname -s) | tail -1 | cut -f 6)
export DISPLAY=$WSL_HOST:0.0

To get the local network IP instead of the IP in /etc/resolv.conf which I have never gotten to work.

I use:

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0

But again, if the IP changes or the network is disrupted, all the X clients are silently killed. This is terrible with Emacs. You don't even get an autosave file out of it.

Uzume commented

Why does it not work to set the DISPLAY to 127.0.0.1:0.0 ?

@edburns This is because despite the name (WSL=Windows Subsystem for Linux), WSL2 is not a Windows subsystem like WSL1 and Interix were but rather now WSL2 is an entire virtual machine with its own separate network interfaces and IP addresses, etc. 127.0.0.1 and localhost are host local references and now you have more than one host and they refer to different things in Windows host and Linux guest host.

The best solution I believe is to use X11 forwarding to forward the X server socket to the Linux guest allowing the guest to then believe and refer to the X server as if it were local to the Linux guest host. Then you can use locahost:0 again. I would like to be able to set that up using a virtual machine specific socket system like that used by wslbridge2 but it currently does not support such. The repeated network disruptions will still be an issue however.

this resolved it for me #4793 (comment) thanks @fredericseiler

Don't use /etc/resolve.conf which need to add firewall rules.
Use this.

What is the recommended way to modify the .bashrc so I dont have to redo EXPORT DISPLAY every time I change networks. I tried @fquinner 's approach and $WSL_HOST = "A"
with @edburns approach it returns null.

Do most WSL2 users simply go into Powershell and run ipconfig followed by a bespoke EXPORT DISPLAY command whenever they are away from their home network?

Just use VIM or another text editor to add the export DISPLAY=:0 to .bashrc. The next time you start WSL2 it will be executed automatically.

@toml12953 what you described worked in WSL1 In WSL2, I find it is necessary to look up the ipv4 config and insert that before the :0

You can scroll through this issue @numeric-lee and see several suggestions. Look at replies with many likes. Use whatever works for you, that's what we all did. And educate yourself by trying to understand why some suggestions work and some don't. I don't think there is a canonical recommendation; the thumbs-up are the best you can go on.

Landing zone #4619

were commented

OK. I leave a secure way of doing this.
Suppose you are using McAfee, you can just set the Hyper-V Ethernet IP range to "Home".

msaio commented

For anyone who did this:
export DISPLAY="$(awk '/nameserver/ { print $2 }' < /etc/resolv.conf)":0
but it did not work.
I found out that the IP from "$(awk '/nameserver/ { print $2 }' < /etc/resolv.conf)" not actually the one you need.
You should get the real IP of your computer with : ipconfig (in cmd, powershell,...)
In my case, it came with 2 different IPs.
Of course, you still need x-server with 'Disable access control'

The DISPLAY nameserver IP will probably work OK for you with the right firewall settings - I didn't realize this at the time but when you install an app, not checking "public" actually adds a block rule for public networks which you then need to actively disable disable before adding an allow rule. I documented some of the woes that I faced here:

https://github.com/cascadium/wsl-windows-toolbar-launcher#firewall-rules

This has the advantage that it will work without exposing your X server to potentially unsecured wireless networks (if you're on a laptop).

Still a bit irritating and if really wanted you could embed something along these lines into PS1 but this is what I have started to use to work around the dynamic IP thing in my bashrc if it helps anyone:

export WSL_HOST=$(dig +noall +answer $(hostname -s) | tail -1 | cut -f 6)
export DISPLAY=$WSL_HOST:0.0

To get the local network IP instead of the IP in /etc/resolv.conf which I have never gotten to work.

this worked for me!! I was having major using MobaXTerm since I couldn't figure out why the DISPLAY kept changing, but now I think this provides me answers. stuff from etc/resolve.conf was not working for me either. Thank you for providing this answer!!

If you're still having trouble even after all of the above answers (like I was), this worked for me.


  1. @simonzhaoms VcXsrv configuration:

I have the same issue as @sithlord2 . Below is my configuration of VcXsrv:
01

02

03

When I tried to launch gedit by DISPLAY=172.17.104.241:0.0 gedit, the command got stuck:

PS C:\Users\simon> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Stopped         2
  Ubuntu-18.04    Stopped         1
PS C:\Users\simon> wsl
simon@QGHRP0C:/mnt/c/Users/simon$ cd
simon@QGHRP0C:~$ sudo apt install gedit
simon@QGHRP0C:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.17.104.241
simon@QGHRP0C:~$ ifconfig | grep 'inet '
        inet 172.17.104.249  netmask 255.255.0.0  broadcast 172.17.255.255
        inet 127.0.0.1  netmask 255.0.0.0
simon@QGHRP0C:~$ DISPLAY=172.17.104.241:0.0 gedit

My systeminfo is:

PS C:\Users\simon> systeminfo

Host Name:                 QGHRP0C
OS Name:                   Microsoft Windows 10 Enterprise Insider Preview
OS Version:                10.0.18922 N/A Build 18922
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Original Install Date:     6/17/2019, 5:59:54 AM
System Boot Time:          6/18/2019, 1:39:58 AM
System Manufacturer:       HP
System Model:              HP Z4 G4 Workstation
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 4 GenuineIntel ~3600 Mhz
BIOS Version:              HP P61 v01.76, 4/22/2019
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Total Physical Memory:     32,488 MB
Available Physical Memory: 24,802 MB
Virtual Memory: Max Size:  37,608 MB
Virtual Memory: Available: 27,712 MB
Virtual Memory: In Use:    9,896 MB
Page File Location(s):     C:\pagefile.sys
Hotfix(s):                 N/A
Network Card(s):           6 NIC(s) Installed.
                           [01]: Intel(R) Ethernet Connection (2) I219-LM
                                 Connection Name: Ethernet
                                 Status:          Media disconnected
                           [02]: PANGP Virtual Ethernet Adapter
                                 Connection Name: Ethernet 8
                                 Status:          Media disconnected
                           [03]: Intel(R) I210 Gigabit Network Connection
                                 Connection Name: Ethernet 2
                                 DHCP Enabled:    Yes
                                 DHCP Server:     N/A
                                 IP address(es)
                           [04]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (Default Switch)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.41.241
                                 [02]: fe80::44dc:a5ae:5762:d831
                           [05]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (New Virtual Switch)
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.222.220.4
                                 IP address(es)
                                 [01]: 10.168.2.39
                                 [02]: fe40::f496:a4cd:e4dc:4f0a
                                 [03]: 2444:f501:58:45c:f576:b551:b5f8:35b8
                                 [04]: 2464:f861:46:46c:f696:a16d:e6dc:a60a
                           [06]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (WSL)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.104.241
                                 [02]: fe90::692b:f95c:9bcd:690
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

  1. @edburns zshrc script:

I use:

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0

But again, if the IP changes or the network is disrupted, all the X clients are silently killed. This is terrible with Emacs. You don't even get an autosave file out of it.


  1. @fquinner firewall rules:

The DISPLAY nameserver IP will probably work OK for you with the right firewall settings - I didn't realize this at the time but when you install an app, not checking "public" actually adds a block rule for public networks which you then need to actively disable disable before adding an allow rule. I documented some of the woes that I faced here:

https://github.com/cascadium/wsl-windows-toolbar-launcher#firewall-rules

This has the advantage that it will work without exposing your X server to potentially unsecured wireless networks (if you're on a laptop).


My issue was the Windows Firewall block mentioned by @fquinner which is created 'allow on Public Networks' is not enabled. I selected 'disable rule' for VcxSrv Public in Windows Defender Firewall -> Advanced Settings -> Inbound Rules and now my X-server works fine.

image

rdmolony's solution is the only one that worked for me.

pr0mr commented

export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0

With Xming on Windows, don't forget to add internal IP address of WSL2 machine to C:\Program Files (x86)\Xming\X0.hosts To allow connect xming DISPLAY from non localhost IPs ;)
Nevertheless, this works perfectly #4106 (comment)

export DISPLAY=0.0.0.0:0 is even simpler

export DISPLAY=0.0.0.0:0 is even simpler

It will not work on WSL 2, use:
export DISPLAY=$(/sbin/ip route | awk '/default/ { print $3 }'):0

This solution will work even if you disabled auto-generation of ResolveConf by:

[network]
generateResolvConf = false

I'm using WSL 2 (Ubuntu) on Windows 10 2004
VcXsrc X Server 1.20.8.1

  • Install app
  • $ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
  • Disable firewall (Windows defender,McAfee,...)
  • run app

rdmolony's solution seems to be the best way to solve this issue for now.
To add to his post:

  • You can put export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0 in your ~/.bashrc so that you don't have to run it every time

  • You can get the IP address for the firewall rule by typing hostname -I in your linux terminal.

I used sushovan's method successfully to run xeyes on Win 10 2004 19041.264 WSL 2 Ubuntu-20.04
I used Xlaunch (component of Xming 7.7.0.9) on the third page of which (Additional Parameters) I set
Disable Server Access Control ie "No Access Control" box clicked then
export DISPLAY=$(/sbin/ip route | awk '/default/ { print $3 }'):0
xeyes (previously installed as part of X11-apps).

anyone who's having trouble despite having the correct IP address is most likely fighting with windows firewall. you also need to add a firewall entry allowing the WSL ip address through. at this point it's safe to turn off access control. this does give a performance penalty, because it has to go across the LAN, and the x server can't bind to the loopback interface of the virtual network card.

that said once it's running you can actually finally get yourself an xterm running bash.

I am using WSL 2 (Ubuntu ) on Windows 10-
Here are the steps which I did for gui apps work in wsl2-

  1. Install VcXsrv
  2. Launch X server using X Launch, make sure you are selected option "disable access control" so it can accept request from wsl2.
  3. export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
  4. export LIBGL_ALWAYS_INDIRECT=1

Now you can launch gui apps.

Open ~/.bashrc in your favorite editor and add above two lines in that script, so you don't have to do it every time you launch wsl2.

My resolv.conf nameserver is pointing to 'vEthernet (WSL)' Hyper-V adapter on my PC and doesn't work with that.

It doesn't make sense anyway as that is pointing back to itself. In my case I used the IP of the PC in Windows, using ipconfig. In my case with Hyper-V installed, 'vEthernet (External Virtual Switch)' is the one I want.

On setting DISPLAY to the PC's IP it works.

My resolv.conf nameserver is pointing to 'vEthernet (WSL)' Hyper-V adapter on my PC and doesn't work with that.

It doesn't make sense anyway as that is pointing back to itself. In my case I used the IP of the PC in Windows, using ipconfig. In my case with Hyper-V installed, 'vEthernet (External Virtual Switch)' is the one I want.

On setting DISPLAY to the PC's IP it works.

Have you checked #4106 (comment)

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 does not work for me.
Instead I have to use the IP address of my physical Ethernet device.
This is not a firewall problem, it doesn't work even if I deactivate the firewall.

I am using VcXsrv 1.20.8.,1 on Windows 10. I believe there might be a problem because the X server listens to the wrong network interface. However, I tried the -from parameter and there is no further documentation so I am not sure how to debug that.

Have you checked #4106 (comment)

Yes, doesn't work either. /sbin/ip route provides the same IP address as /etc/resolv.conf and again it's the IP of the virtual adapter for WSL. The nameserver in my set up is WSL virtual adapter.

Maybe it's because I've got Hyper-V installed.

This comment may be the same. Physical IP of the host is fine, not the nameserver, but as said that's 'vEthernet (WSL)' adapter in my case whereas VcXsrv isn't going to be listening on that (and I wouldn't expect it to by default).

I followed these steps and it worked for me:

  1. Windows Security -> Firewall & network protection -> Allow an app through firewall -> make sure VcXsrv has both public and private checked
  2. Launch VcXsrv with "Disable access control" ticked
  3. DISPLAY variable:
export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0

Hope this helps others.

None of these solutions mentioned worked for me. The contents of /etc/resolv.conf include multiple addresses (some IPv6), none of which work. I'm able to get things working by using IP found using ip route in the 192.168.1.0/24 address space.

Rather than disable access control, this starts the X server from the WSL2 prompt and configures it to allow connections from only the WSL2 ip:

#!/bin/bash
HOST=$(ip address show dev eth0 | awk -F '[ /]+' '/inet / { print $3 }')
# xhost.exe needs this
export DISPLAY=127.0.0.1:0
WSLENV="$WSLENV:DISPLAY"
# Start the server
powershell.exe -Command '& "C:\Program Files\VcXsrv\vcxsrv.exe" -multiwindow -wgl'
# Tell the server to let me in
powershell.exe -Command '& "C:\Program Files\VcXsrv\xhost.exe" '+$HOST

This assumes you've already configure windows firewall to allow connections to the X server.

Rather than disable access control, this starts the X server from the WSL2 prompt and configures it to allow connections from only the WSL2 ip:

#!/bin/bash
HOST=$(ip address show dev eth0 | awk -F '[ /]+' '/inet / { print $3 }')
# xhost.exe needs this
export DISPLAY=127.0.0.1:0
WSLENV="$WSLENV:DISPLAY"
# Start the server
powershell.exe -Command '& "C:\Program Files\VcXsrv\vcxsrv.exe" -multiwindow -wgl'
# Tell the server to let me in
powershell.exe -Command '& "C:\Program Files\VcXsrv\xhost.exe" '+$HOST

This assumes you've already configure windows firewall to allow connections to the X server.

This worked for me, but I had to use the display variable from above:

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0

instead of the localhost address 127.0.0.1. Would also be nice to test if the xserver is already running in the script. Currently, you can't reopen wsl without getting en error when the xserver has not been closed before reopening.

I wasn't clear. That snippet is a script and sets DISPLAY=127.0.0.1 solely for xhost.exe to use. The script caller still must have DISPLAY set correctly, the firewall configured, etc.

./myscript.sh
# Probably just have this in .bashrc:
export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0
# Whatever X app you like:
gnome-terminal &

Another way (I think cleaner) of getting the two addresses:

user@host$ ip route get 8.8.8.8 | awk '{ print ("host: " $3 " guest: " $7); exit}'
host: 172.30.240.1 guest: 172.30.244.112

Hi folks, maybe you can give me some hints, because I followed these steps and it did not worked for me:

  1. Windows Firewall & network protection -> Allow VcXsrv on Domain / Public / Private checked
  2. Launch VcXsrv with "Disable access control" ticked and -ac at variables
  3. DISPLAY variable: export DISPLAY=grep -oP "(?<=nameserver ).+" /etc/resolv.conf:0.0
  4. export LIBGL_ALWAYS_INDIRECT=1
  5. when i run ipconfig on my windows machine i got 2 IP addresses (domain ip and Ethernet adapter vEthernet (WSL) ( 172.30.224.1)
  6. cat /etc/resolv.conf
    # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
    #[network]
    #generateResolvConf = false
    nameserver 172.30.224.1

7 if I try to $ startlxde i receive the following:

** Message: 08:45:03.244: main.vala:102: Session is LXDE
** Message: 08:45:03.244: main.vala:103: DE is LXDE
(lxsession:46): Gtk-WARNING **: 08:45:35.238: cannot open display: 172.30.224.1:0

Regards,

Hi folks, maybe you can give me some hints, because I followed these steps and it did not worked for me:

  1. Windows Firewall & network protection -> Allow VcXsrv on Domain / Public / Private checked
  2. Launch VcXsrv with "Disable access control" ticked and -ac at variables
  3. DISPLAY variable: export DISPLAY=grep -oP "(?<=nameserver ).+" /etc/resolv.conf:0.0
  4. export LIBGL_ALWAYS_INDIRECT=1
  5. when i run ipconfig on my windows machine i got 2 IP addresses (domain ip and Ethernet adapter vEthernet (WSL) ( 172.30.224.1)
  6. cat /etc/resolv.conf
    # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
    #[network]
    #generateResolvConf = false
    nameserver 172.30.224.1

7 if I try to $ startlxde i receive the following:

** Message: 08:45:03.244: main.vala:102: Session is LXDE
** Message: 08:45:03.244: main.vala:103: DE is LXDE
(lxsession:46): Gtk-WARNING **: 08:45:35.238: cannot open display: 172.30.224.1:0

Regards,

Hi everybody,
I have the same issue as @aziraal and tried same things (and even more).
I don't have authorization's issues anymore so I think I "won" against firewall. I just have "cannot open display: IP_ADRESS" error.
I use VcXsrv too.
I'm totally stuck with this....

Thank you for you help

When you run Xlaunch, is display number set to 0 in the first dialog? This will prevent you from accidentally running multiple X servers.

This is what my inbound rules look like:
inbound

Thank you it eventually works.
I think I touched to firewall to much. I deleted special rules created for the occasion as it is indicated in some forum and set back to default inbound rules. Then I modify them following your snapshot and... it works ! Thank you again !

Thank you it eventually works.
I think I touched to firewall to much. I deleted special rules created for the occasion as it is indicated in some forum and set back to default inbound rules. Then I modify them following your snapshot and... it works ! Thank you again !

Unfortunately I had no luck (and this is my first attempt with Linux after 15 years :) )
Bellow is what I did, step by step:

  • uninstall everything :)

  • install Ubuntu 20.04 LTS from https://www.microsoft.com/store/apps/9n6svws3rx71

  • configure proxy: sudo nano apt.conf -> Acquire::http::Proxy "http://proxyaddress:proxyport";

  • sudo apt upgrade

  • sudo apt update
    image

  • sudo apt install openbox-lxde-session

  • display
    image
    image

  • ifconfig
    image

  • VcXsrv configuration: Multiple windows, display number 0, check Disabled Access Control, aditional parameters -ac

  • windows firewall - delete everything related to VcXsrv and put (to be on the safe side :) )
    image

  • windows wsl ip
    image

  • startlxde
    image

Any ideas?

Best Regards,

How are you seeing your DISPLAY variable in your Linux environment? Currently you will need to specify the IP address of the host, you can easily find this by looking at your /etc/resolv.conf file:

root@BENHILL-DELL:/mnt/c/Users/benhill# cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.110.177

Then you'll run:

export DISPLAY=192.168.110.117:0

You may also need to launch vcxsrv with the -ac argument.

This is an area that we are working on improving in an update soon.

I think I love you

Example of my case that doesn't work

/etc/resolv.conf

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.31.48.1

ip route

default via 172.31.48.1 dev eth0
172.31.48.0/20 dev eth0 proto kernel scope link src 172.31.51.14

ipconfig in Windows

Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::f9db:35a1:4969:2408%22
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (External Virtual Switch):

   Connection-specific DNS Suffix  . : lan
   Link-local IPv6 Address . . . . . : fe80::647a:ebc7:4821:4be2%9
   IPv4 Address. . . . . . . . . . . : 192.168.1.175
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.254

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::3d60:cf88:86f6:98ab%17
   IPv4 Address. . . . . . . . . . . : 172.21.160.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5969:96d1:eaa0:cb8a%32
   IPv4 Address. . . . . . . . . . . : 172.31.48.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

resolv.conf is mapping to the IP of Ethernet adapter vEthernet (WSL), i.e. 172.31.48.1

If I set DISPLAY to 172.31.48.1:0 it doesn't work.

I can only get it to work setting it to the IP of Ethernet adapter vEthernet (External Virtual Switch), i.e. 192.168.1.175.

I've even set VcXsrv to disable access control.

Ah, worked it out. It's a firewall issue related to private/public networks.

Windows sticks the external switch on a network that is set to private, but all the other vEthernet adapters are bundled in a network called Unidentified network, and this is set to public.

VcXsrv server has two sets of firewall rules. The ones for private networks are all open, but the public ones deny access.

So I can solve this with a PowerShell command (as administrator)...

Set-NetConnectionProfile -Name "Unidentified network" -NetworkCategory "Private"

Although be careful if you actually have genuinely public facing adapters in there and/or you use a laptop etc on public networks. Setting to private means you trust the network and firewall rules may be more relaxed. Any new network connections will be treated as unidentified but will be trusted doing this.

So there's a security risk in this.

I don't know how to create a new network profile and assign/trust the adapters to that, rather than it sitting under unidentified. However my PC sits purely on a private network.

efa commented

added this in .bashrc:

export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"

work.

Not working unfortunately.

Windows 10 Pro
Version 10.0.19042 Build 19042

I've had more success using MobaXterm. It doesn't require any special configuration and seems to integrate with firewalls more smoothly. Just launch and leave it running in the background.

If for whatever reason you've modified /etc/resolv.conf you can use export DISPLAY=$(ip route | awk '/default via / {print $3; exit}' 2>/dev/null):0 which grabs your ip using ip route instead.

I'm using VcXsrv ( -ac mode is necessary.. OR when you use Xlaunch program, it will ask configurations each time, on last page, make sure to have 'Disable Access Control' box checked)

https://sourceforge.net/projects/vcxsrv/

For me the following worked:
echo "export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}':0" >> ~/.bashrc

then the following to restart/reload the bash:
. ~/.bashrc

btw since I created a env, so after restart, I use this command to go into my env:
conda activate myenvname

Test by running this command:
xeyes

pllim commented

Not as user friendly as I would like but https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2 mostly works. The firewall part depends on which software you are using.

image

On multiple different computers I couldn't get it to work, ultimately due to firewall issues. Even though I allowed C:\Program Files\VcXsrv\vcxsrv.exe through the firewall (public and private), it still didn't work.

On two computers the solution was to run the troubleshooter shown in the figure. It would pop up a list of options, one was "Allow other computers to connect to VcXsrv windows xserver". I followed the troubleshooter, it asked me to switch to administrator mode, then it fixed the issue.

...first time a Windows troubleshooter has been useful.

This was the final step I needed after adding export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 to my .bashrc and running VcSrv with "Disable Access Control".

I followed everything people have said but in vain, until I finally found what was the problem.

Under Settings -> Firewall & Network Protection -> Allow an app through firewall_, I hadn't checked the leftmost box as well. Once I did this, and setting the DISPLAY environment variable, everything is peachy.

Capture

Putting it here in case it helps someone.