Connecting to a Hyper-V VM on Windows Server 2022 using the Host's IP Address without a Public IP
Windows Server 2022 comes with the Hyper-V role, which allows you to create and manage virtual machines (VMs) seamlessly. By default, VMs use the host's IP address to communicate with the external network. However, connecting to a Hyper-V VM on Windows Server 2022 using the host's IP address can be challenging if the server has no public IP.
Prerequisites
Ensure you have the following before you begin:
- A Windows Server 2022 system with Hyper-V role installed.
- A VM created and configured in Hyper-V Manager.
- Access to the host system with administrative privileges.
Configuring the Hyper-V VM Network Adapter
The first step is to configure the network adapter of the Hyper-V VM to use the host's IP address.
Follow these simple steps:
- Shut down the VM you want to connect to via Remote Desktop Protocol (RDP).
- Open the Hyper-V Manager and select the VM. Click
Settings. - In the settings window, navigate to the
Network Adaptersection. - Configure the
Virtual SwitchtoExternaland choose the physical network adapter to use.
// Example PowerShell Script
Get-VM "MyVM" | Set-VMNetworkAdapter -SwitchName "ExternalSwitch"
Enabling RDP on Windows Server 2022
RDP must be enabled on both the host and guest operating systems.
To enable RDP on Windows Server 2022:
- Launch the Server Manager.
- Select
Local Serverfrom the left pane. - Scroll down to find
Remote Desktopand clickEnable Remote Desktop.
Configuring Firewall Rules for RDP
You will need to configure the Windows Firewall on both the host and guest systems to allow RDP connections.
To configure the Windows Firewall for RDP:
- Launch the Windows Defender Firewall with Advanced Security from the Start Menu.
- Create a new
Inbound Rulefor RDP (TCP 3389). - Set the rule's
ActiontoAllow the connection. - Add the necessary exceptions and profiles for your environment.
Connecting to a Hyper-V VM using the Host's IP Address
With RDP enabled and the network configured on both the host and VM, follow these steps to connect:
- Find the host's IP address using
ipconfigin an elevated command prompt or PowerShell. - Launch the Remote Desktop Connection application from the Start Menu.
- Type the host's IP address and click
Connect. - Input the credentials for the Hyper-V VM and click
OK.
- Configure the Hyper-V VM network adapter to use an external virtual switch.
- Enable RDP and configure firewall rules on both the host and guest systems.
- Connect to the Hyper-V VM using the host's IP address via RDP.