-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
VMWare Workstation Secondary Network Adapters on Windows #5000
Comments
To set the IP address for a private network, maybe this could help: http://professionalvmware.com/2008/12/vmware-vix-changing-ips-of-a-guest-vm/
|
@mitchellh I just made a test from my Mac spinning up a Windows 10 VM in VMware Fusion with an additional private network with a static ip # -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "windows_10"
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
config.vm.network :private_network, ip: "192.168.33.15", gateway: "192.168.33.1"
config.vm.communicator = "winrm"
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.windows.halt_timeout = 15
["vmware_fusion", "vmware_workstation"].each do |provider|
config.vm.provider provider do |v, override|
v.gui = true
end
end
end Spinning up the Vagrant VM shows the warning for that second network card:
Inside the Windows 10 VM the network addresses are configured as follows:
The second network has DHCP enabled and has to be changed to the fixed IP address given in the
Afterwards the networks in the Windows 10 VM shows the correct settings:
The only difficulty with this approach is to get the interface name "Ethernet 2" from the host as it seems that vmrun doesn't show the stdout of the program in the VM. But this could also be done with the winrm communicator to run the I've tried it in a small provision script and came up to this workaround: # -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "windows_10"
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
config.vm.network :private_network, ip: "192.168.33.15", gateway: "192.168.33.1"
config.vm.communicator = "winrm"
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.windows.halt_timeout = 15
config.vm.provision "shell", inline: <<-SHELL
netsh.exe int ip show addresses
netsh.exe int ip set address "Ethernet 2" static 192.168.33.15 255.255.255.0 192.168.33.1
SHELL
["vmware_fusion", "vmware_workstation"].each do |provider|
config.vm.provider provider do |v, override|
v.gui = true
end
end
end Can this small part be done by the vagrant-vmware-fusion as well? |
Is the blocker here the lack of nic_mac_addresses capability in the vmware provider? |
This should be relabeled It's disappointing that paid products like the vmware providers are less featured than their free open-source counterpart. And the problem has been reported...over a year ago...with no response. The whole experience of using open-source vagrant with closed-source vmware providers is frustrating. You find a bug in vagrant and want to fix it? Ok but good luck getting your self-compiled vagrant to work with your vmware provider because of vagrant's "DRM". I feel like a less empowered second-rate citizen as a paying customer than people who are using only the free open-source parts of vagrant. |
Well after a few hours of tinkering, I was able to add the |
@bsuh Wow, great approach. Might be some inspiration for the Hashicorp team 🙏 |
Fixed hanging while configuring network adapters inside the VM. At first, vagrant tries to connect to WinRM on the IP address of the first ethernet interface, but later tries to connect to WinRM on the IP address of the second ethernet interface to set the static ip address. Setting the static ip address of the interface that is holding the WinRM connection destroys the WinRM connection causing it to hang. Instead of always requesting the WinRM address to connect to using |
+1 for getting this enhancement into Vagrant. I've attempted to add
and receive the same message. RDPing into the machine shows that it has not received an extra, DHCP'd address as expected. Manually configuring bridged mode after a |
To patch the IP address of a second network card I wrote a small PowerShell script cfg.vm.network :private_network, ip: "192.168.33.2", gateway: "192.168.33.1"
["vmware_fusion", "vmware_workstation"].each do |provider|
cfg.vm.provision "shell", path: "scripts/fix-second-network.ps1", privileged: false, args: "192.168.33.2"
end and the script looks like this. It searches for the network interface with the given subnet and sets the fixed IP address. This script might be a basis for a PR to get this into Vagrants core. param ([String] $ip)
$subnet = $ip -replace "\.\d+$", ""
$name = (Get-NetIPAddress -AddressFamily IPv4 `
| Where-Object -FilterScript { ($_.IPAddress).StartsWith($subnet) } `
).InterfaceAlias
if ($name) {
Write-Host "Set IP address to $ip of interface $name"
& netsh.exe int ip set address "$name" static $ip 255.255.255.0 "$subnet.1"
} |
@StefanScherer I am trying to do the same thing as the remote vmware |
Any of the examples here for using a provisioning script to set the interface configuration didn't work for me - it causes the provisioning step to hang. This is what I ended up doing as the last step. Note that even calling Start-ScheduledTask would cause the hang because the network config would be set while WinRM was connected. This step must be last for the same reason. If you need the IP to set for provisioning to continue, I suspect you could set the schedule task to start in 5 seconds, sleep for 10, and then continue. Hope it helps!
|
When a secondary NIC is configured for VMWare Vagrant issues the following error:
However, I can still configure a secondary NIC by doing:
Why doesn't Vagrant configure this by default when these same values are present in the
vmx
file?Base Box VMX File
The text was updated successfully, but these errors were encountered: