Hi,
I am trying to spin up a Windows box using the following fairly basic Vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
# Disable default port forwarding rules (We will define custom ones per host later)
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", disabled: "true"
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: "true"
config.vm.network :forwarded_port, guest: 5895, host: 55895, id: "winrm", disabled: "true"
config.vm.network :forwarded_port, guest: 5896, host: 55896, id: "winrm-ssl", disabled: "true"
# Create custom forwarding ports
config.vm.network :forwarded_port, guest: 5985, host: 58951, id: "winrm-wsl2", auto_correct: true
config.vm.network :forwarded_port, guest: 3389, host: 33891, id: "rdp-wsl2", auto_correct: true
config.vm.guest = :windows
config.vm.communicator = "winrm"
config.winrm.retry_limit = 10
config.winrm.retry_delay = 5
config.winrm.username = "redacted"
config.winrm.password = "redacted"
config.vm.box = "StefanScherer/windows_2022"
config.vm.hostname = "dc01"
config.vm.network "private_network", ip: "192.168.100.10"
# 172.30.192.1 is the gateway of the WSL2 device which will get NATed to the Windows host, after which it will reach virtualbox where it is NATed again to the guest
config.winrm.host = "172.30.192.1"
config.winrm.port = 58951
# Tried this as well, did not work either
#config.winrm.guest_port = 5985
The issue is with the WinRM port. For some reason, Vagrant refuses to utilize the custom port I set with the config.winrm.port = 58951
setting. The reason I want to use a custom port is that I want to run multiple boxes using WinRM and want to keep it a little bit cleaner by specifying increasing port numbers (58951, 58952, …). I also need a predictable WinRM port so it can be defined in the Ansible configuration. Regardless of the reason, it should work the way I am implementing it currently, but I don’t see why it is not taking it.
As you can see on the following screenshot, it uses the winrm.host
option just fine, but no matter what I try, it keeps using the default port 5985 instead of the custom port I configured.
A WireShark capture also shows that it is actually trying to connect on port 5985, and not on port 59851.
If I just let it use port 5985 without and add a port forwarding rule for that, then vagrant successfully connects to the box with WinRM. (Which is fine for one box, but not for multiple. And I don’t want to rely on the auto_correct feature for all of the boxes. The config.winrm.port
setting is there for a reason, so there should be a way to make this work right?)