WSL: Can't use X-Server in WSL 2
-
Your Windows build number: (Type
verat 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 © 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_commandis failing, then runstrace -o some_command.strace -f some_command some_args, and link the contents ofsome_command.stracein 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 +++
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 12
- Comments: 142 (9 by maintainers)
Links to this issue
Commits related to this issue
- WSL1 and WSL2 makes whole different changes. Reference: https://github.com/microsoft/WSL/issues/4106 — committed to KangDroid/ROS_WIKI by KangDroid 7 years ago
- VcXsrvに接続できない問題を修正 ref: https://github.com/microsoft/WSL/issues/4106 — committed to chupaaaaaaan/desktop by chupaaaaaaan 4 years ago
- [WSL] WSL側IPアドレスの取得方法を変更 See: https://github.com/microsoft/WSL/issues/4106#issuecomment-803607362 — committed to umi-uyura/mydotfiles by umi-uyura 2 years ago
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:
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.
You could combine into:
thanks a lot, @shortpoet.
It took my whole day to make GUI working on WSL2+Ubuntu. Tried so many answers but no luck. Finally, @shortpoet answer worked for me.
Steps, I followed (Assuming, installed WSL2 + Ubuntu)
Install vcxsrv on Windows
Start XLaunch on Windows
C:\Users\"YOUR_USERNAME"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup(don’t forget to place YOUR_USERNAME)Open Ubuntu app, run command
export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0(as mentioend by @shortpoet ), also put the command in~/.bashrcrun
sudo apt install x11-apps -yrun
xeyesVoila!
I hope your GUI applications are running fine now.
PS: I am able run ROS Neotic (Gazebo and Rviz GUIs) on WSL2+Ubuntu 20.04.
Thanks, K
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.
New solution I found after working on this for hours 😀
https://stackoverflow.com/questions/61860208/wsl-2-run-graphical-linux-desktop-applications-from-windows-10-bash-shell-erro/66398613#66398613
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 have the same issue as @sithlord2 . Below is my configuration of VcXsrv:
When I tried to launch gedit by
DISPLAY=172.17.104.241:0.0 gedit, the command got stuck:My systeminfo is:
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}'):0to my.bashrcand running VcSrv with “Disable Access Control”.I followed these steps and it worked for me:
Hope this helps others.
If you’re still having trouble even after all of the above answers (like I was), this worked for me.
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.
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.
Putting it here in case it helps someone.
grepcan get the FILE parameter,catis useless.And even simpler
@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.
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.
-ac is most important because it allows public access. Wsl2 is a VM with a different IP address
Yes in the bash shell you can run:
export DISPLAY=$(ipconfig.exe | grep -A1 fade.local | grep -Po '([0-9]{1,3}\.){3}[0-9]{1,3}'):0Should work 😃
How it works
-A1will print one line after the match.-Powill only output what matches the Perl-like regexp([0-9]{1,3}\.){3}[0-9]{1,3}is a simple regexp for matching IPv4 addresses, there are much more complicated like^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$that can be used to validate untrusted user input.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.
@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):
Also make sure your windows firewall is not blocking the connections
None of the solutions that I tried worked. What worked for me is to put my computer’s local IP address
192.168.0.30which can be found by typingipconfigin powershell and getting the IP address of your network adapter. I then addedDISPLAY=$192.168.0.30:0to my .zshrc (if you’re using bash instead of zsh, add this to your .bashrc or switch to zsh because it’s better), set this to your local IP address. I loaded up XLaunch with My display number as 0, and “disable access control” turned on. Also make sure x11 forwarding is set to yes in your/etc/ssh/sshd_configand everything should work fine. This took me 3 days to fix and i’m annoyed the solution was so simple, but i couldn’t find it anywhere 😦I am using WSL 2 (Ubuntu ) on Windows 10- Here are the steps which I did for gui apps work in wsl2-
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.
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
If you are still not able to run, try opening
vcxsrvand have a look at the titlebar, it should mention where the Display server is listening on. For me, it was running as my system name (forgot what this is called).then inside wsl, I did:
export DISPLAY=ASUS-TUF-F15:0.0and it started working.I ended up writing a function and putting it in
~/.profilewhich utilizes the fact that one can callipconfig.exefrom inside WSL. From that I can extract the IPv4 of the VPN adapter. I’m sure it’s a very non-optimal solution since I’m not good with grep, awk and sed, but it kinda works for me.I haven’t found any way to make it work without being connected to my VPN.
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0does 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
-fromparameter and there is no further documentation so I am not sure how to debug that.It will not work on WSL 2, use:
export DISPLAY=$(/sbin/ip route | awk '/default/ { print $3 }'):0This solution will work even if you disabled auto-generation of ResolveConf by:
I made a “Run as Administrator” shortcut on my desktop for turning off the Windows firewall. The “Target:” is
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?
Example of my case that doesn’t work
/etc/resolv.conf
ip route
ipconfig in Windows
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.
Thanks guys, this works.
I think vcxarv needs -ac argument to work
Hi folks, maybe you can give me some hints, because I followed these steps and it did not worked for me:
grep -oP "(?<=nameserver ).+" /etc/resolv.conf:0.07 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,
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:
This assumes you’ve already configure windows firewall to allow connections to the X server.
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
PS1but this is what I have started to use to work around the dynamic IP thing in my bashrc if it helps anyone:To get the local network IP instead of the IP in
/etc/resolv.confwhich I have never gotten to work.With my setup, the nameserver is different, I ended up by using the default gateway:
export DISPLAY=$(ip r l default | cut -d\ -f3):0Thanks, but unfortunately that didn’t resolve the issue for me. Running
ip route show default | awk '{print $3 }'will return the IPv4 ofEthernet adapter vEthernet (WSL), whereas the only address I have gotten to work forDISPLAY(via manual trial and error) is the IPv4 associated withEthernet adapter Local Area Connection* 11which in my case is the corporate VPN connection.I’ll continue troubleshooting, but it seems like I might have a fairly uncommon problem.
I had to try a lot of things, but in the end I managed to fully automate the whole thing. Add the following to the end of your
.bashrc(fix paths as needed):config.xlaunch
Edit: After switching to zsh, I noticed that my path to config.xlaunch was wrong. I fixed it here.
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" >> ~/.bashrcthen the following to restart/reload the bash:
. ~/.bashrcbtw since I created a env, so after restart, I use this command to go into my env:
conda activate myenvnameTest by running this command:
xeyesI’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.confyou can useexport DISPLAY=$(ip route | awk '/default via / {print $3; exit}' 2>/dev/null):0which grabs your ip usingip routeinstead.added this in .bashrc:
work.
None of these solutions mentioned worked for me. The contents of
/etc/resolv.confinclude multiple addresses (some IPv6), none of which work. I’m able to get things working by using IP found usingip routein the192.168.1.0/24address space.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.
With Xming on Windows, don’t forget to add internal IP address of WSL2 machine to
C:\Program Files (x86)\Xming\X0.hostsTo allow connect xming DISPLAY from non localhost IPs 😉 Nevertheless, this works perfectly https://github.com/microsoft/WSL/issues/4106#issuecomment-501532834For anyone who did this:
export DISPLAY="$(awk '/nameserver/ { print $2 }' < /etc/resolv.conf)":0but 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’my firewall rules for Public networks:
the above, plus “disable access control” in my config.xlaunch
plus the “nameserver” trick
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…
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
You might try using the following command to set the firewall rule.
This one took me a few hours: I added a new Windows Firewall rule to allow access from the WSL 2 subnet on port 6000, and things weren’t working. I eventually found another rule with the name “VcXsrv windows xserver” that was blocking all TCP traffic on Public networks. I needed to disable that one in order for my targetted Allow rule to work.
I’m using WSL 2 (Ubuntu) on Windows 10 2004 VcXsrc X Server 1.20.8.1
I use:
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.
Just wanted to share how I got this working:
-acto the end OR Secure mode: go to the installation directory and add the WSL ip inX0.hostsexport DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0in WSLshould you happen to have the docker desktop with wsl2 support up, it looks like you can
Hey @AlexWil, it seems like I did have following rule for vcxsrv.exe:
I have also added xlaunch.exe for exceptions
,
however, that still did not resolve the issue 😦
UPD: One of the 2 things fixed this for me:
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.
Actually with the latest updates and on Win11 a separate Xserver is not required anymore. It is still needed if you ssh somewhere, but for WSL2 it is not needed. In addition now one can go back to usin xming with default setup, the special settings are not needed anymore.
This helped out a lot for me, but I had to make a slight change to make calling
route.exework. I was getting this error at first:If you are too, change the command to
For some reason I needed to
cdinto the C:\ drive forroute.exeto workActivating Cisco VPN broke both ethernet access to the world and the X11 server in WSL2 for me. I tried many fixes, all failed. Make sure that your ethernet and X11 work before turning on the VPN, then consider these ideas. Leave WSL closed for a moment.
About VPN. Problem is Linux has wrong IP for DNS. In Windows, connect with Cisco VPN. In Windows, the Cisco VPN client is running and if you click the VPN icon in the tray, you’ll see a menu pop up and there’s a “hamburger menu” where you’ll see the IPV4 address info. The VPN changes both your IP and the nameserver. That will be same IP as you see in PowerShell running
look under the stanza that says Description… Cisco AnyConnect Secure Mobility Client. Should see same IPV4 address.
After you start WSL2, you’ll see that the value of nameserver in
/etc/resolv.confis probably wrong and you will not have ethernet access nor will X11 apps work. To fix the X11 apps, runexport DISPLAY=xxx.xxx.xxx.xxx:0.0, where xxx is the IPV4 address you see for the Cisco AnyConnect Device. If your X11 worked without VPN, it will work now.It is harder to understand is fixing internet access. The problem is that the DNS server name is wrong. In my case, I have to manually edit /etc/resolv.conf EVERY TIME WSL2 starts, adding the nameservers at the end of the file. The Name servers are the “DNS Servers…” from the ipconfig output in windows. Appears now that reconfiguring /etc/wsl.conf to stop resolv.conf from resetting has no effect, must fix resolv.conf manually.
You may need to liberalize your firewall setting. In either X410 or VcxSrv, there’s an option to allow public access.
If you still have network trouble, you may hit a problem that I hit at my company. The Cisco VPN not only restricts access but also does a sort of SSL-certificate manipulation. They installed a non-standard company certificate in Windows. I had to get the Windows certificate for my company and copy into WSL /usr/local/share/ca-certificate and run a re-configurator.
The big idea is to pull the certificate from the installed Windows system and use it in the Linux side.
EXTRACT THE CERTIFICATE
In Windows, run the program called “mmc” (type that after clicking on the Start button).
In MMC, You see “Console1”.
Expand the left menu to show all of the Certificates.
In the left, under “Trusted Root Certification Authorities”, click “Certificates”. In the Right panel, scroll down to the special “root certificate for your company”. If you can’t find one, it probably means you don’t need to bother with this.
Select the “Your Company Root Certificate Authority”.
You are greeted by a Wizard.
There are 3 choices, choose #2.
On the WSL Ubuntu side
Copy the cer file into target folder, cd into that folder
Run following to convert the .cer file to .crt.
That creates a new “.crt” file. The evidence of victory is in the output from the next step
If you don’t see a cert added, then this failed.
I’m mostly overcomed all that problems, but can’t make an auto launch of xfce4 window with VBS script.
In WSL version 1 that worked fine:
WScript.CreateObject("Shell.Application").ShellExecute "wsl", "cd /home/ershov; DISPLAY=:0 LANG=ru_RU.UTF-8 su ershov -c xfce4-session", "", "open", 0But now in WSL2 I can’t launch the same:
WScript.CreateObject("Shell.Application").ShellExecute "wsl", "cd /home/ershov; LANG=ru_RU.UTF-8 su ershov -c xfce4-session", "", "open", 0Although manual typing works:
cmdcd /home/ershovWhat i’m doing wrong?
*my user ‘ershov’ haven’t any password
I am glad I found this thread. VcXsrv with ‘-ac’ option and ‘export DISPLAY=<IP>:0’ worked for me. BUT… here is a question. I have another machine where I installed ubuntu bash few years ago and everything simply worked (and still does) with Xming and ‘export DISPLAY=localhost:0.0’. So what is really different? Why did it stop working?
ip route show default | awk '{print $3 }'Got the same thing. I made it work using:
export DISPLAY=localhost:0.0I think I love you
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 !
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:
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.
Another way (I think cleaner) of getting the two addresses:
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).
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.0in your ~/.bashrc so that you don’t have to run it every timeYou can get the IP address for the firewall rule by typing
hostname -Iin your linux terminal.export DISPLAY=“$(awk ‘/nameserver/ { print $2 }’ < /etc/resolv.conf)”:0
Thanks, @a-schaefers , that worked for me
Don’t use /etc/resolve.conf which need to add firewall rules. Use this.
This type of code:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0can be shortened considerably to just:export DISPLAY=$(/etc/resolv.conf < awk '/nameserver/ {print $2}'):0I am not sure how big of an optimization that is (it depends on how often that is executed), however, now only the shell andawkare forked (removing the need to forkcatandgrep). 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):0but methinksawkis cleaner.nice!
but this leaves us with
So, then you can basically just use
export DISPLAY=`grep -oP “(?<=nameserver ).+” /etc/resolv.conf`:0in 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.
Oh I had the firewall set to the wrong type of network. I apologise.