Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Created April 9, 2025 06:18
Show Gist options
  • Save Foadsf/f7381ddb2b13ffb5ec9e6ac50e3032cd to your computer and use it in GitHub Desktop.
Save Foadsf/f7381ddb2b13ffb5ec9e6ac50e3032cd to your computer and use it in GitHub Desktop.
Fixed Hyper‑V VM connectivity by creating an external virtual switch.

Resolving Internet Connectivity in a Hyper‑V Virtual Machine

Short Description:
Fixed Hyper‑V VM connectivity by creating an external virtual switch.


Overview

I was experiencing a loss of Internet connectivity in a Windows virtual machine running on Hyper‑V. Although the VM received an IP address via the Default Switch, it could not reach the Internet—the gateway (172.29.128.1), external IP addresses (e.g., 8.8.8.8), or HTTPS endpoints were unreachable.


Problem Identification

  1. Diagnostics from Inside the VM:

    • ipconfig /all showed an assigned IP (172.29.137.218), subnet mask, DHCP default gateway, and DNS.
    • Pinging the default gateway (172.29.128.1) and external IPs timed out.
    • tracert to 8.8.8.8 did not progress beyond the initial hops.
    • Test-NetConnection dev.azure.com -Port 443 failed, confirming no TCP connectivity.
  2. Routing and Adapter Checks:

    • The routing table contained a default route via the gateway (172.29.128.1), yet packets were not leaving the virtual network.
    • DNS resolution occurred properly (validated with nslookup), hinting that basic DHCP functions were working.

Resolution

After reviewing the network configuration inside the VM and analyzing the Hyper‑V Default Switch behavior, I opted to bypass the troublesome NAT configuration by creating an external virtual switch.

Steps Taken:

  1. Access Hyper‑V Manager on the Host:
    Open the Hyper‑V Manager and go to Virtual Switch Manager.

  2. Create a New External Virtual Switch:

    • Select External Network.
    • Choose the active physical network adapter (e.g., the one providing Wi‑Fi or wired connectivity—avoid using VPN-specific adapters unless intended).
    • Ensure that "Allow management operating system to share this network adapter" is enabled.
    • Click OK to create the switch.
  3. Reassign the VM’s Network Adapter:

    • Open the settings for the affected VM.
    • Change the network adapter’s connection from the Default Switch to the newly created external virtual switch.
    • Restart the VM.
  4. Confirm Connectivity Inside the VM:

    • Run ipconfig to verify that a new IP address appropriate for your network is assigned.
    • Use ping 8.8.8.8, tracert, and Test-NetConnection commands to confirm that the VM is now able to reach external addresses.

Conclusion

Creating an external virtual switch allowed the VM to bridge directly to the physical network adapter, bypassing the NAT limitations of the Default Switch. This resolution restored full Internet connectivity in the VM.

Documented as a reference for troubleshooting similar Hyper‑V networking issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment