Set up network connection in Hyper-V
The sole purpose of the Default Switch is to provide WAN access and won't provide a static IP by design:
- Microsoft made this change a few years ago to make Hyper-V VM setup simpler, as previously an External switch had to be created in Switch Manager, and provides access to the host’s network regardless of connection type
Depending on why a static IP is needed, create in Virtual Switch Manager or PowerShell:
Traffic managed by router:
-
External switch: router assigns static IP (@John's answer)
- Create one for both ethernet and WiFi, as VMs do not auto-switch between wired/wireless
- Create one for both ethernet and WiFi, as VMs do not auto-switch between wired/wireless
Traffic managed by host:
-
Internal switch: manually assign IP subnet on host and client
- Allows communication between VM ⟷ host and/or VM ⟷ VM
- Lacks DHCP server and Gateway, so only the IP and subnet mask would be set
Avoid using subnets normally used by routers [192.168.1.0/24
,2.0/24
,100.0/24
, etc.], else issues will occur when connecting to a router using the same subnet
-
Private switch: manually assign IP subnet on clients
- Allows VM ⟷ VM communication that is isolated from host's traffic
Virtual Switch Manager:
- Hyper-V Manager → Actions → Virtual Switch Manager
- New virtual network switch → Create virtual switch → <type> → Create Virtual Switch
- Create a Name → Select Connection type → OK/Apply
PowerShell:
-
+R →
powershell
→ Ctrl+Shift+OK - List existing network adapters and note the
Name
of the adapter to use:PS $ Get-NetAdapter Name InterfaceDescription ifIndex Status MacAddress LinkSpeed ---- -------------------- ------- ------ ---------- --------- vWiFi Hyper-V Virtual Ethernet Adapter #3 62 Up A0-11-22-33-44-55 10 Gbps LAN Killer E2200 Gigabit Ethernet Controll… 25 Disconnected B0-11-22-33-44-55 0 bps BT Bluetooth Device (Personal Area Networ… 23 Disconnected B1-11-22-33-44-55 3 Mbps vLAN Hyper-V Virtual Ethernet Adapter 54 Up A1-11-22-33-44-55 10 Gbps vDefault Hyper-V Virtual Ethernet Adapter #2 58 Up A2-11-22-33-44-55 10 Gbps OpenVPN TAP6 TAP-Windows Adapter V9 12 Disconnected A3-11-22-33-44-55 1 Gbps OpenVPN WinTun Wintun Userspace Tunnel 11 Disconnected 100 Gbps WiFi Intel(R) Dual Band Wireless-AC 7260 5 Up B2-11-22-33-44-55 866.7 Mbps vShare Hyper-V Virtual Ethernet Adapter #4 2 Up A4-11-22-33-44-55 10 Gbps
- Create virtual switch:
-
External:
New-VMSwitch -Name vWiFi -NetAdapterName WiFi -AllowManagementOS $true
-
Internal:
New-VMSwitch -Name vShare -SwitchType Internal
-
Private:
New-VMSwitch -Mame vPrivate -SwitchType Private
-
External:
If you need guest machines to have the same IP address using Hyper-V, then set up the guest machines to have bridged networking. That will work, and usually applies to VMware as well. This is for one network.
Consider the environment you are using.
One:
A desktop computer with a classic wired Ethernet adapter is ideal for Bridged Networking (External Switch) where the Guest gets the IP address from the Router the host machine is attached to.
You would do this if you need to access a Guest machine. Bridged Network (External Switch) is ideal for this.
Here is a complete post for accessing a Guest machine using a Bridged (External) Networking approach.
Accessing a Guest machine with Static IP
This will work on a Laptop in a fixed physical location where the Laptop has an Ethernet connection, a mainboard wireless card, and most USB wireless adapters installed into the machine.
You can never use a cellular USB wireless adapter for bridging.
Two:
Typical roaming laptops use NAT networking but then the IP address is not fixed (static). It can work, and I use it on one machine, just not guaranteed.
This is useful if you are moving a laptop around to multiple locations, say Home and Work.
The trick here is to make sure you check your Guest IP before accessing it.
To have bridged networking, you need to add that networking type to the Hyper-V Manager.
I have done this here using a Linux Guest machine (Kali) and it worked fine.
Open Hyper-V Manager and then Virtual Switch Manager and add an External (Bridged Network) Switch type. Give it a Name you will use in the Guest setup.
Once done, go to the Guest area in Hyper-V Manager, Settings and go to the Network Adapter. Add the External adapter from the prior step.
Restart any Guests you change.