Switching the network adapter in an Ubuntu Hyper-V VM from a default switch to an external switch often breaks connectivity because the guest operating system does not automatically update its network configuration files. The issue stems from static definitions that reference the old interface name or IP settings which no longer match the new virtual hardware profile. Restoring access requires manually correcting the Netplan configuration to reflect the new NIC identifier and ensuring the Hyper-V switch is properly bound to a physical uplink.
Understanding the Root Cause
When you change the Virtual Machine Network Adapter settings in Hyper-V Manager, the underlying hardware presented to the Ubuntu guest changes. If the previous connection relied on the "Default Switch" (a NAT-based internal network), the DHCP client likely obtained an IP address dynamically. However, many Ubuntu installations use
netplan with YAML configuration files that may contain static IP assignments or hardcoded gateway entries tied to the previous interface state.
Furthermore, Hyper-V's "External Switch" requires a direct binding to a physical network interface card (NIC) on the host machine. If this binding is missing or incorrect, the VM has no path to the outside world. Unlike the Default Switch, which handles NAT transparently, an External Switch acts as if the VM were plugged directly into your physical LAN. Therefore, the OS must be configured to obtain an IP address via DHCP from your actual router, or you must manually assign a static IP that exists within your local subnet range.
Verifying Hyper-V Switch Configuration
Before modifying the Linux guest, ensure the host-side configuration is correct. Open Hyper-V Manager on your Windows host. Navigate to
Virtual Switch Manager. You should see a switch type set to
External. Select it and verify that the checkbox for "Allow management operating system to share this network adapter" is checked if you need the host to retain internet access. More importantly, ensure the specific physical NIC that provides your internet connection is selected in the dropdown menu. If this is unselected, the virtual switch is effectively disconnected from the physical network, regardless of what the guest OS attempts to do.
After confirming the switch settings, restart the virtual machine. This ensures the new virtual hardware profile is loaded correctly by the hypervisor.
Diagnosing the Guest Network Interface
Once Ubuntu boots, log in via the console or SSH if possible. The first step is to identify the current network interface name. In modern Linux distributions, interface names are dynamic. Run the following command:
ip link show
Look for an interface that is in the
UP state but has no IP address assigned, or one that shows a carrier signal. Common names include
eth0,
ens3, or
enp0s5. Note this exact name. If you previously used a static configuration file referencing
eth0 but the system now identifies the card as
ens3, the configuration will fail to apply.
Check the current status of the interface using:
ip addr show <interface_name>
If the output shows no IPv4 address, the DHCP client has failed to communicate with the router. This confirms that the issue is either a misconfiguration in Netplan or a lack of physical connectivity from the Hyper-V side.
Correcting Netplan Configuration
Ubuntu uses
netplan to manage networking. The configuration files are typically located in
/etc/netplan/. List the files in this directory:
ls /etc/netplan/
Open the primary YAML file (often named something like
01-netcfg.yaml or
50-cloud-init.yaml) using a text editor such as
nano or
vim:
sudo nano /etc/netplan/01-netcfg.yaml
You must ensure two critical things in this file. First, the
match section must correspond to the interface name you identified earlier. Second, you should generally use DHCP for external switches unless you have a specific static IP requirement. Avoid using deprecated keywords like
gateway4, which are ignored in newer versions of Netplan and can cause silent failures. Instead, use the modern syntax.
A correct, robust configuration for a DHCP-enabled external switch looks like this:
network:
version: 2
ethernets:
ens3: # Replace with your actual interface name
dhcp4: true
dhcp6: false
Ensure there is proper indentation. YAML is whitespace-sensitive. If you had previous static entries, remove them. If you specifically need a static IP, you must include the
routes section instead of
dhcp4, specifying the correct gateway IP for your local network.
Apply the changes with:
sudo netplan apply
If the command returns an error, check the syntax carefully. If it succeeds silently, test connectivity by pinging a public DNS server:
ping 8.8.8.8
If ping fails, check the routing table with
ip route show. If no default route exists, the DHCP lease was not obtained. Re-check the Hyper-V switch binding.
Alternative Troubleshooting Steps
If the standard Netplan fix does not resolve the issue, consider checking the firewall settings on the Ubuntu guest. Sometimes, switching networks triggers UFW (Uncomplicated Firewall) rules that block incoming traffic. Temporarily disable the firewall to test:
sudo ufw disable
If connectivity returns, re-enable it and configure appropriate rules. Additionally, verify that the Hyper-V integration services are installed and running, as these provide optimized drivers for network and time synchronization.
For more complex scenarios involving hybrid setups where you need to balance host and guest access, refer to our guide on
Hyper-V: Accessing LAN Devices on Host. This resource details how to configure VLANs and advanced switch properties that might interfere with basic external connectivity.
Another common pitfall occurs when users attempt to force static IPs without understanding their local subnet mask. If you are unsure about the correct gateway address for your home or office network, consult your router's admin page or use the host machine's
ipconfig (on Windows) to find the default gateway, then mirror that value in your Netplan config.
Frequently Asked Questions
Why did my internet work on Default Switch but not External?
The Default Switch uses NAT and handles IP assignment internally, requiring minimal guest configuration. An External Switch connects directly to your physical network, meaning the guest must behave like any other device on your LAN, relying on your physical router for IP addresses and routing.
Can I use a static IP with an External Switch?
Yes, but you must manually calculate the correct IP, subnet mask, and gateway based on your local network. Using the wrong gateway address will result in no internet access even if the interface is UP.
What if netplan apply says 'invalid configuration'?
This usually indicates a YAML syntax error, such as incorrect indentation or a typo in the interface name. Use
yamllint or carefully compare your file against a known-good template to spot spacing issues.
Does changing the switch affect my SSH keys?
No, SSH keys are stored on the disk and are independent of network interfaces. However, if your SSH server is configured to listen only on a specific IP, you may need to update that configuration after the switch change.
How do I revert to the Default Switch?
In Hyper-V Manager, delete the External Switch binding from the VM's network adapter settings and select "Default Switch" from the dropdown. Then reboot the VM. The guest will automatically reconfigure via DHCP for the NAT environment.