Forum Discussion
Bala Sundaram
Sep 24, 2018Brass Contributor
Hyper-V Default switch IP address range change. Ver 1809 Build 17763.1
Can one confirm IP address range changed to 192.168.X.Y Subnet 255.255.255.240 from 172.X.X.X Also changes the subnet randomly on every Hyper-V services startup. 192.168.X.Y . X can change from 5...
southernprogrammer
Feb 27, 2020Copper Contributor
If you just need to access resources on your guest from the host, you could just have a powershell script that you can run on the host after launching the VM.
Replace 'BryanDev' with the name of your VM and replace "weirdalvm.3-gis.com" with your desired url you want to access the resource with.
Run as administrator
$result = get-vm -Name BryanDev | Select -ExpandProperty Networkadapters | Select IPAddresses | ft -hidetableheaders | Out-String
$result = $result.Split(",")[0].Trim().Replace("{", "").Replace("}", "")
function setHostEntries([hashtable] $entries) {
$hostsFile = "$env:windir\System32\drivers\etc\hosts"
$newLines = @()
$c = Get-Content -Path $hostsFile
foreach ($line in $c) {
$bits = [regex]::Split($line, "\s+")
if ($bits.count -eq 2) {
$match = $NULL
ForEach($entry in $entries.GetEnumerator()) {
if($bits[1] -eq $entry.Key) {
$newLines += ($entry.Value + ' ' + $entry.Key)
Write-Host Replacing HOSTS entry for $entry.Key
$match = $entry.Key
break
}
}
if($match -eq $NULL) {
$newLines += $line
} else {
$entries.Remove($match)
}
} else {
$newLines += $line
}
}
foreach($entry in $entries.GetEnumerator()) {
Write-Host Adding HOSTS entry for $entry.Key
$newLines += $entry.Value + ' ' + $entry.Key
}
Write-Host Saving $hostsFile
Clear-Content $hostsFile
foreach ($line in $newLines) {
$line | Out-File -encoding ASCII -append $hostsFile
}
}
$entries = @{
'weirdalvm.3-gis.com' = $result
};
setHostEntries($entries)
Lisendra
May 11, 2020Copper Contributor
southernprogrammer Thanks, gived myself permission to tweak a litlle you script to update all my vmdomains's ip also, work like a charm.
I also think the behavior of the default adapter is not logical, and i personaly see it as a bug, i hope it get fixed since i am migrating from VmWare to Hypre-V, streamlining my setup accross multiple device is better without scripts...