How to Configure Network for Linux VMs in Hyper‑V Using the Default Switch (NAT)
This guide walks through using Hyper‑V's Virtual Switch Manager to set up a Default Switch with NAT, configure the vEthernet adapters, and manually assign static IP, gateway, netmask, and DNS on a CentOS 7.9 VM so it gains network connectivity.
Hyper‑V includes a built‑in Hyper‑V Manager and a Virtual Switch Manager for creating and managing local virtual machine environments. The author created two VMs—CentOS 7.9 (Linux) and Windows 11—and discovered the Linux VM had no network connectivity because its network settings were not configured by default.
Virtual Switch Manager
The Virtual Switch Manager can be opened by right‑clicking the server name in the left‑hand pane of Hyper‑V Manager or via the preview pane. It allows creation and configuration of virtual switches and network adapters.
The default virtual switch is Default Switch (default network).
Virtual Switch Types
Internal : Enables communication between VMs on the same Hyper‑V host and between those VMs and the host.
External : Maps the virtual network to a physical network adapter (including wireless adapters) on the host.
Private : Allows communication only among VMs on the same host; the host cannot communicate with the VMs.
Additional tips: VLAN IDs can be assigned to virtual adapters to extend existing VLANs, and VLANs partition traffic between logical networks.
Default Switch (NAT) Details
When using the Default Switch, the host creates two adapters: vEthernet (Default Switch) and vEthernet (WLAN) . These adapters are the source of the virtual network for the VMs.
Viewing the host's network configuration with ipconfig /all shows the IP address and subnet mask that will serve as the VM's gateway.
ipconfig /allConfiguring Network on the CentOS VM
Inside the CentOS VM, the default network interface is eth0. Verify it with:
ip addrEdit the interface configuration file:
vi /etc/sysconfig/network-scripts/ifcfg-eth0Set the following parameters:
BOOTPROTO=static – use a static IP.
ONBOOT=yes – enable the interface at boot.
IPADDR – assign an IP address in the same subnet as the virtual switch.
GATEWAY – specify the gateway (the host’s vEthernet address).
NETMASK – set the subnet mask.
Configure DNS by editing /etc/resolv.conf to match the host’s DNS servers.
After saving changes, restart the network service: systemctl restart network.service Verify the new settings:
Test connectivity from the VM to external networks:
With these steps, the CentOS VM can communicate through the Default Switch’s internal NAT network.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
