I want to be able to ping from wsl 2 to a vagrant machine, the problem is that they are in different networks,
How can i do that.
And If a use the wsl switch It doesnt assign me an ip.
Help
You need to execute this in powershell
Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table
And select the ifIndex of Wi-Fi and Ethernet IPv4, and then execute
Set-NetIPInterface -ifindex SWITCHIDWIFI -Forwarding Enabled
Set-NetIPInterface -ifindex SWITCHIDETHERNET -Forwarding Enabled
It should work
Related
I followed instructions on setting up X11 forwarding from my WSL2 to the host on Windows 10 with VcXsrv based on this answer: How to set up working X11 forwarding on WSL2
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
I allowed public access while starting up VcXsrv, and also switched off my firewall just to test if it worked.
mustafa#DESKTOP-MGJG0RL:~$ xeyes
Error: Can't open display: 172.25.32.1:0
Is there a step that I'm missing?
I had the same issue. In my case the problem was that I disabled the Windows Firewall for private networks assuming that the network with the WSL 2 virtual machine would be considered a private network. But actually it turned out that this network is handled as a public network and therefore disabling the firewall for private networks did not help. So the short answer is: Set up a proper firewall rule instead of trying the shortcut with disabling the firewall for a quick try.
instead of disabling the firewall, try adding this rule (admin PowerShell)
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
I was able to resolve it:
In the sshd_config file
X11UseLocalhost yes
X11Forwarding yes
Adapted from this answer https://superuser.com/a/1476160/1014728
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
Use VcXsrv. Set -ac in the additional parameters field
Run xhost + if you get a no protocol found error
Run an xeyes to test
Suppose you have
Windows Server with Hyper-V and PowerShell 5.1. You can add and use any PowerShell modules such as "Hyper-V".
Linux virtual machine. It's generic so you are not allowed to install uncommon applications such as PowerShell Core.
Now you are using (1) Hyper-V where you can run a PowerShell script.
Question. How do you run Bash commands on (2) Linux VM and get the output of it using that PowerShell from Hyper-V?
I believe this question is equivalent to create and run question.ps1 that runs bash /tmp/linux.sh in the Linux VM and get the desired output 100 where /tmp/linux.sh is shown in the image.
| | Hyper-V (host) | Linux VM (guest) |
|----------|-----------------|------------------|
| IPv4 | 10.0.0.1 | 10.0.0.200 |
| hostname | hyperv | vm |
| Username | userH | userL |
| Password | passwordH | passwordL |
| Script | C:\question.ps1 | /tmp/linux.sh |
Recall. In the Linux VM, you have /tmp/linux.sh:
#!/bin/bash
val=100
echo "$val"
exit $?
Answer (Confirmed). Store PuTTY in Windows Hyper-V host.
Tips. PuTTY Portable suffices: https://portableapps.com.
Suppose you have stored PuTTY Portable in C:\PortableApps\PuTTYPortable.
Create a PowerShell script file C:\Users\userH\Desktop\question.ps1
C:\PortableApps\PuTTYPortable\App\putty\PLINK.EXE 10.0.0.200 -l userL -pw passwordL -batch bash /tmp/linux.sh
^^ Put this line somewhere in this PowerShell script file.
In PowerShell, run the script file question.ps1:
PS C:\> & "C:\Users\userH\Desktop\question.ps1"
100
PS C:\>
Im trying to automate a docker run shell script that needs to spin up an X11 app running on a docker-machine VM with virtualbox driver on OSX/mac. To get the x11 app to forward the X11 display to the desktop host i need to get the ip address of the correct vboxnet* (i assume) network interface (not the docker ip) and export that ip into the docker container.
what i am currently doing is assuming that the docker-machine VM ip is tied to the "vboxnet1" interface name and regexp'ing it out of ifconfig.
i see that the virtualbox DHCP process that spins up when i start docker-machine has a trunk name that corresponds to the interface i want - but again this seems like an assumption and i would think there is some command i could run to be certain which address it is so my docker run script will work on any machine.
/Applications/VirtualBox.app/Contents/MacOS/VBoxNetDHCP --ip-address
192.168.99.2 --lower-ip 192.168.99.100 --mac-address XXXXXXXXXXX
--netmask 255.255.255.0 --network HostInterfaceNetworking-vboxnet1
--trunk-name vboxnet1 --trunk-type netadp --upper-ip 192.168.99.254
Is there a way to definitively determine which network interface to find the ip address?
This bash script seems to work on OSX machines:
#!/bin/bash
CONFIG=$( ifconfig | grep -A 2 'vboxnet1')
regex="([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"
if [[ $CONFIG =~ $regex ]]; then
DISPLAY=${BASH_REMATCH[1]}
DISPLAY+=":0"
fi
ifconfig $(route -n get $(docker-machine ip default) | grep interface: | awk '{print $2}') | grep inet | awk '{print $2}'
Docker has a run option net=host documented here that allows you to run a virtual machine that shares the network stack with the host — for example, processes inside the docker container can connect to the host machine via localhost and vice versa.
I want to set up a Linux VM on Mac OS X that does the same thing; I've tried using Vagrant and its various networking settings without much luck.
Does Docker's VM rely on the host and guest OSes both being Linux, or is there some way to accomplish this OSX->Linux that I'm missing?
Thanks to some help from my colleagues I found a solution to this problem. This solution works with boot2docker/VirtualBox. I just created my docker VM with boot2docker init, I didn't make any specific changes to the VM configuration.
First you run the docker image with --net=host, so that it shares the network with the host VM e.g.
docker run -it --net=host ubuntu bash
Then you need to find the IP address from the VM used for the docker containers, you can do this by running boot2docker ssh the OSX host.
You can then find the IP address of the VM by finding its gateway:
$ netstat -rn | grep UG | awk '{print $2}'
10.0.2.2
So in my case it's 10.0.2.2. You can now access ports opened on the host, i.e. on a program running on OSX from your docker container by using this IP address.
To automate you could find the IP address first and then pass it into the docker command as an environment variable...
I have found another answer that works, I'll share that here so that people can choose :)
First you need to figure out what the IP address of the preferred network interface is on your OSX host is. The following shell command did this for me:
echo "show State:/Network/Global/IPv4" | scutil | grep PrimaryInterface | awk '{print $3}' | xargs ifconfig | grep inet | grep -v inet6 | awk '{print $2}'
In my case this prints out: 10.226.98.247
Then you can simply use that address inside docker, or even better give this address a hostname for inside docker:
docker run -it --add-host dockerhost:10.226.98.247 ubuntu bash
Then you can use the same dockerhost hostname in your docker container regardless of what environment you're launching your container in...
How can I create a VPN connection with an arbitrary server using an arbitrary protocol in Windows cmd?
I know this is a very old thread but I was looking for a solution to the same problem and I came across this before eventually finding the answer and I wanted to just post it here so somebody else in my shoes would have a shorter trek across the internet.
****Note that you probably have to run cmd.exe as an administrator for this to work**
So here we go, open up the prompt (as an adminstrator) and go to your System32 directory. Then run
C:\Windows\System32>cd ras
Now you'll be in the ras directory. Now it's time to create a temporary file with our connection info that we will then append onto the rasphone.pbk file that will allow us to use the rasdial command.
So to create our temp file run:
C:\Windows\System32\ras>copy con temp.txt
Now it will let you type the contents of the file, which should look like this:
[CONNECTION NAME]
MEDIA=rastapi
Port=VPN2-0
Device=WAN Miniport (IKEv2)
DEVICE=vpn
PhoneNumber=vpn.server.address.com
So replace CONNECTION NAME and vpn.server.address.com with the desired connection name and the vpn server address you want.
Make a new line and press Ctrl+Z to finish and save.
Now we will append this onto the rasphone.pbk file that may or may not exist depending on if you already have network connections configured or not. To do this we will run the following command:
C:\Windows\System32\ras>type temp.txt >> rasphone.pbk
This will append the contents of temp.txt to the end of rasphone.pbk, or if rasphone.pbk doesn't exist it will be created. Now we might as well delete our temp file:
C:\Windows\System32\ras>del temp.txt
Now we can connect to our newly configured VPN server with the following command:
C:\Windows\System32\ras>rasdial "CONNECTION NAME" myUsername myPassword
When we want to disconnect we can run:
C:\Windows\System32\ras>rasdial /DISCONNECT
That should cover it! I've included a direct copy and past from the command line of me setting up a connection for and connecting to a canadian vpn server with this method:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Windows\system32>cd ras
C:\Windows\System32\ras>copy con temp.txt
[Canada VPN Connection]
MEDIA=rastapi
Port=VPN2-0
Device=WAN Miniport (IKEv2)
DEVICE=vpn
PhoneNumber=ca.justfreevpn.com
^Z
1 file(s) copied.
C:\Windows\System32\ras>type temp.txt >> rasphone.pbk
C:\Windows\System32\ras>del temp.txt
C:\Windows\System32\ras>rasdial "Canada VPN Connection" justfreevpn 2932
Connecting to Canada VPN Connection...
Verifying username and password...
Connecting to Canada VPN Connection...
Connecting to Canada VPN Connection...
Verifying username and password...
Registering your computer on the network...
Successfully connected to Canada VPN Connection.
Command completed successfully.
C:\Windows\System32\ras>rasdial /DISCONNECT
Command completed successfully.
C:\Windows\System32\ras>
Hope this helps.
Have you looked into rasdial?
Just incase anyone wanted to do this and finds this in the future, you
can use rasdial.exe from command prompt to connect to a VPN network
ie rasdial "VPN NETWORK NAME" "Username" *
it will then prompt for a password, else you can use "username"
"password", this is however less secure
http://www.msfn.org/board/topic/113128-connect-to-vpn-from-cmdexe-vista/?p=747265
Is Powershell an option?
Start Powershell:
powershell
Create the VPN Connection: Add-VpnConnection
Add-VpnConnection [-Name] <string> [-ServerAddress] <string> [-TunnelType <string> {Pptp | L2tp | Sstp | Ikev2 | Automatic}] [-EncryptionLevel <string> {NoEncryption | Optional | Required | Maximum}] [-AuthenticationMethod <string[]> {Pap | Chap | MSChapv2 | Eap}] [-SplitTunneling] [-AllUserConnection] [-L2tpPsk <string>] [-RememberCredential] [-UseWinlogonCredential] [-EapConfigXmlStream <xml>] [-Force] [-PassThru] [-WhatIf] [-Confirm]
Edit VPN connections: Set-VpnConnection
Set-VpnConnection [-Name] <string> [[-ServerAddress] <string>] [-TunnelType <string> {Pptp | L2tp | Sstp | Ikev2 | Automatic}] [-EncryptionLevel <string> {NoEncryption | Optional | Required | Maximum}] [-AuthenticationMethod <string[]> {Pap | Chap | MSChapv2 | Eap}] [-SplitTunneling <bool>] [-AllUserConnection] [-L2tpPsk <string>] [-RememberCredential <bool>] [-UseWinlogonCredential <bool>] [-EapConfigXmlStream <xml>] [-PassThru] [-Force] [-WhatIf] [-Confirm]
Lookup VPN Connections: Get-VpnConnection
Get-VpnConnection [[-Name] <string[]>] [-AllUserConnection]
Connect: rasdial [connectionName]
rasdial connectionname [username [password | \]] [/domain:domain*] [/phone:phonenumber] [/callback:callbacknumber] [/phonebook:phonebookpath] [/prefixsuffix**]
You can manage your VPN connections with the powershell commands above, and simply use the connection name to connect via rasdial.
The results of Get-VpnConnection can be a little verbose. This can be simplified with a simple Select-Object filter:
Get-VpnConnection | Select-Object -Property Name
More information can be found here:
Manage VPN Connections in Windows 8 by Using Windows PowerShell
Rasdial
Select-Object