Reputation: 61
So I can get X11 forwarding working in WSL2 following e.g., How to set up working X11 forwarding on WSL2. Then I had issues getting networking to function after connecting to a Cisco AnyConnect server, but I solved that using, e.g., WSL 2 Cisco AnyConnect Networking Workaround. This included manually setting up /etc/resolv.conf to include the DNS nameservers I need, although the DISPLAY variable for X11 should then be set via this answer to the X11 question.
But as soon as I connect to AnyConnect, I can no longer forward X11 apps, which even includes vim unless I add the -X
argument (seemed odd, but what do I know). The apps don't show an error in display setting, they just don't show up. The same commands work fine as soon as I disconnect from the VPN. This happens regardless of the networking settings that need to happen, so I think it's only related to the AnyConnect itself, but perhaps there are additional Powershell commands I need to run so the display works? Any ideas?
Upvotes: 4
Views: 2040
Reputation: 328
I had the same concern in my WSL2 environment. Once I opened a VPN connection via Cisco AnyConnect, the default network interface I had set within DISPLAY environment variable for X11 forwarding (which I retrieved from /etc/resolv.conf - same method as the one you pointed out) wasn't accessible anymore.
I looked then for any Windows network interface ping-able from WSL2 side and with a 6000 port reachable (since this port seems to be the one used by default to establish X11 connections with X servers like VcXsrv). And by luck, I found the virtual network interface opened for the Windows host on the VPN, which matches these criteria:
Name : Ethernet 2
InterfaceDescription : Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64
InterfaceIndex : 4
MacAddress : [...]
MediaType : 802.3
PhysicalMediaType : Unspecified
InterfaceOperationalStatus : Up
AdminStatus : Up
LinkSpeed(Mbps) : 862.4
MediaConnectionState : Connected
ConnectorPresent : False
DriverInformation : [...]
To be able to use it from WSL2 side, I used the following Powershell command to retrieve the interface's IP address:
Get-NetAdapter |
Where-Object InterfaceDescription -like "*AnyConnect*Virtual*Adapter*" |
Get-NetIPAddress -AddressFamily IPv4 |
Select-Object -ExpandProperty IPAddress
which can be wrapped into a Powershell call from WSL2, like following:
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '<the_command_above>'
Once I got this IP address, I only had left to re-export my DISPLAY environment variable with it:
export DISPLAY="<vpn_ip_address>:0"
And that was it, I could enjoy X11 forwarding back again!
Upvotes: 1