Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runx doesn't set correct Hostip in case of multiple Virtual Switches on Windows #6

Closed
CptnGreen opened this issue Jan 3, 2021 · 17 comments
Labels
bug Something isn't working

Comments

@CptnGreen
Copy link

Environment: Win10, WSL2.

runx bash script goes through ipconfig.exe output and sets Hostip var (needed for the DISPLAY envvar) to the value from the first found "IPv4"-containing string.
But when there are multiple Virtual Switches the first found value may be not correct (my case) so runx doesn't work because DISPLAY is not set correctly.
Disabling additional Virtual Switches solves the problem but it took about an hour for me (not mentioning reading through code) to find the reason of the problem.

Please take this situation into account.
Thanks.

@mviereck mviereck added the bug Something isn't working label Jan 3, 2021
@mviereck
Copy link
Owner

mviereck commented Jan 3, 2021

Thank you for the bug report and for digging that far into the root cause!

I currently don't have a working Windows VM. It would be nice if you could help me with some information and checks.

Can you show me the output of ipconfig.exe?
In the output is there a hint which Virtual Switch(es) might work?

Maybe the Host Name entry of ipconfig.exe /all would work.
Replacing the IP check code with this hostname check is worth a try:

 Hostip="$(ipconfig.exe | rmcr | grep 'Host Name' | rev | awk '{print $1}' | rev)"

Current runx IP check:

  Hostip="$(ipconfig.exe | rmcr | grep -A6 'DockerNAT' | grep 'IPv4' | rev | cut -d' ' -f1 | rev)"
  [ "$Hostip" ] || Hostip="$(ipconfig.exe | rmcr | grep 'IPv4' | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | grep "^10\.0\.*" )"
  [ "$Hostip" ] || Hostip="$(ipconfig.exe | rmcr | grep 'IPv4' | head -n1 | rev | cut -d' ' -f1 | rev)"

@CptnGreen
Copy link
Author

C:\Users\ak>ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Unknown adapter OpenVPN Wintun:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::e125:9adb:c8e5:b352%32
   IPv4 Address. . . . . . . . . . . : 172.21.224.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (Bridge):

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Unknown adapter OpenVPN TAP-Windows6:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : IGD_Rostelecom
   Link-local IPv6 Address . . . . . : fe80::356f:74c:4a23:530d%17
   IPv4 Address. . . . . . . . . . . : 192.168.1.113
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Mobile Broadband adapter Cellular:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::300c:10fa:8b93:ab97%80
   IPv4 Address. . . . . . . . . . . : 172.21.0.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

@mviereck
Copy link
Owner

mviereck commented Jan 4, 2021

Thank you!
I wonder which adapter might be a good choice.

  • Maybe Ethernet adapter vEthernet (Default Switch):? x11docker could parse for Default Switch.
  • Even better sounds Ethernet adapter vEthernet (WSL):. x11docker could parse for WSL.

Which one did work for you after disabling additional Virtual Switches in your first research?

@CptnGreen
Copy link
Author

CptnGreen commented Jan 4, 2021

I am going to investigate now.

But I think it may be better to adapt powershell approach as described here.

Another approach (for WSL) is to use

Hostip="$(awk ' /nameserver/{ print $2 } ' < /etc/resolv.conf)"

@mviereck
Copy link
Owner

mviereck commented Jan 5, 2021

Thank you for the investigation!
Points to consider:

  • The final solution should work on MSYS2, Cygwin, WSL1 and WSL2 as well.
  • I'd say it should work on Windows 7, too, because I believe it is still often in use.

For the powershell solution I doubt that it will fulfill this. Though, I am not sure. Wikipedia says that Poweshell 2.0 is included in Win7. Furthermore, the stackoverflow comments suggest that calling it is very slow.

The attempt with resolv.conf fails on my Linux system. It gives the IP of my DSL modem, not of the host system.

The command hostname -I might work on all noted systems. Could you check that, at least for WSL2?

          Hostip="$(hostname -I | cut -d' ' -f1)"

@eine Could you please have a look at this, too?

@eine
Copy link

eine commented Jan 5, 2021

On MSYS2 (MINGW64):

# Hostip="$(hostname -I | cut -d' ' -f1)"
hostname: unknown option -- I
Try 'hostname --help' for more information.

@eine
Copy link

eine commented Jan 5, 2021

On Cygwin, it works and Hostip contains the public IP (which does not match any of IPv4 addresses of the adapters).

$ Hostip="$(hostname -I | cut -d' ' -f1)"

$ echo $Hostip
158.x.x.x

$ ipconfig

Windows IP Configuration


Ethernet adapter Ethernet 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : Home
   Link-local IPv6 Address . . . . . : fe80::a464:f05b:a69c:7cff%11
   IPv4 Address. . . . . . . . . . . : 192.x.x.x
   Subnet Mask . . . . . . . . . . . : 255.x.x.x
   Default Gateway . . . . . . . . . : 192.x.x.x

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter WiFi 5:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : Home

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::45be:1119:d090:5b00%57
   IPv4 Address. . . . . . . . . . . : 172.x.x.x
   Subnet Mask . . . . . . . . . . . : 255.x.x.0
   Default Gateway . . . . . . . . . :

@eine
Copy link

eine commented Jan 5, 2021

On Debian (dunno if this is WSL1 or WSL2), it works and Hostip contains the local IPv4 of one of the adapters:

$ Hostip="$(hostname -I | cut -d' ' -f1)"

$ echo $Hostip
172.x.x.x

@mviereck
Copy link
Owner

mviereck commented Jan 5, 2021

@eine Thank you!

Would have been to easy have a general solution immediately ...

hostname: unknown option -- I
On MSYS2 (and also the others?) maybe this attempt works:

Hostname=$(hostname)
nslookup "$Hostname"

On Cygwin, it works and Hostip contains the public IP (which does not match any of IPv4 addresses of the adapters).

I wonder if this IP works; it might also cause yet another firewall issue.

On debian I get valid ipv4 adresses combining hostname and nslookup (except the first one that points to the DNS server on the DSL modem):

$ Hostname=$(hostname)
$ nslookup "$Hostname" | grep Address
Address:	192.168.178.1#53
Address: 192.168.178.46
Address: fd[...]

Maybe this gives useable results in MSYS2 and Cygwin?

Edit: I've added an experimental option --ip to specify an IP address. This allows to easily check if an estimated IP is valid. (Especially it has to be checked if it works for docker container applications, too.) Example:

runx --ip=192.168.178.46 -- x11docker/check

@eine
Copy link

eine commented Jan 5, 2021

On MSYS2 (and also the others?) maybe this attempt works:

Hostname=$(hostname)
nslookup "$Hostname"

Unfortunately, it does not:

# Hostname=$(hostname)

# nslookup "$Hostname"
Server:  UnKnown
Address:  212.x.x.x

*** UnKnown can't find DESKTOP: Non-existent domain

I wonder if this IP works; it might also cause yet another firewall issue.

Even if it worked in some setups, I don't think it's desirable to use it. IMHO, the most local IP should be used.

Edit: I've added an experimental option --ip to specify an IP address. This allows to easily check if an estimated IP is valid. (Especially it has to be checked if it works for docker container applications, too.) Example:

runx --ip=192.168.178.46 -- x11docker/check

I guess that users with conflictive setups might want to setup RUNX_IP_ADDR envvar, which runx might pick automatically?

@mviereck
Copy link
Owner

mviereck commented Jan 5, 2021

What is the output of hostname in MSYS2? Maybe it works to set --ip=$(hostname). Though, using a name instead of an IP address could cause delays due to DNS resolving.
Does /etc/resolv.conf contain anything useful? On debian it only contains the IP of my DSL modem.

Even if it worked in some setups, I don't think it's desirable to use it. IMHO, the most local IP should be used.

I agree.

I guess that users with conflictive setups might want to setup RUNX_IP_ADDR envvar, which runx might pick automatically?

Why would you prefer an envvar over an option? However, I'd prefer an automatic solution that does not need either.

@eine
Copy link

eine commented Jan 5, 2021

What is the output of hostname in MSYS2? Maybe it works to set --ip=$(hostname). Though, using a name instead of an IP address could cause delays due to DNS resolving.

hostname is DESKTOP-XXXXXXX, which is the "Device name" in the 'About' page of the PC properties. That's the name that shows when browsing 'Network' in the file explorer.

Does /etc/resolv.conf contain anything useful? On debian it only contains the IP of my DSL modem.

/etc/resolv.conf does not exist.

Why would you prefer an envvar over an option? However, I'd prefer an automatic solution that does not need either.

The envvar can be set in ~/.bashrc, so that specifying --ip each time is not required. It's the closest to an automatic solution, with a minimal initial setup. I don't think it needs to be envvar or option, both can be supported.

@mviereck
Copy link
Owner

I found that ipconfig.exe likely always shows a valid local network IP starting with 192.168.*.*
This check should work on all of MSYS2/Cygwin/WSL/WSL2:

ipconfig.exe | grep 'IPv4' | grep -o '192\.168\.[0-9]*\.[0-9]*' | head -n1

@CptnGreen @eine Could you please check if this gives an IP adress everywhere and also works with runx?

@eine
Copy link

eine commented Jan 17, 2021

@mviereck I can confirm that to be acceptable. The output when calling ipconfig is the same on MSYS2, Cygwin or WSL.

FTR, that is what I used before I dropped by own script in favour of x11docker/runx: eine/hwd-ide@b716acc#diff-e5e5b287edfbf94abd53c6c6376f53f8972af68e8cfe7ea3cd3a5c2d62632ffbL4. There used to be some Docker NAT which started with 10.*. That seems not to be the case now.

@mviereck
Copy link
Owner

@eine Thank you very much! I'll set this as default now.

There used to be some Docker NAT which started with 10.*. That seems not to be the case now.

I am surprised. Is there no obvious Docker interface anymore? My intention was to prefer DockerNAT over 192.168.* if available because it is "more" local.

mviereck added a commit that referenced this issue Jan 17, 2021
@eine
Copy link

eine commented Jan 17, 2021

It seems there is no obvious interface anymore. See docker/for-win#5538.

I agree with you it would be more desirable, tho.

@mviereck
Copy link
Owner

Thank you for pointing on the related ticket. I've removed the DockerNAT check now.
I assume I can close here now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants