Enable Internet Access for a CentOS VM on Hyper‑V Using the Default Switch (NAT)
This guide explains how to configure Hyper‑V's virtual switch manager, choose the Default Switch (internal NAT), and set static IP, gateway, netmask, and DNS inside a CentOS 7.9 VM so that it can communicate with the host and external networks.
Hyper‑V Virtual Switch Manager
Hyper‑V includes a Virtual Switch Manager for creating and managing virtual network adapters and switches. It is accessed from the Hyper‑V console by right‑clicking the server name or via the preview pane.
Virtual Switch Types
Internal : Enables communication among 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) so VMs can reach external networks.
Private : Allows communication only among VMs on the same host; the host cannot communicate with the VMs.
Default Switch (Internal NAT)
The built‑in Default Switch provides an internal NAT network. VMs attached to it receive a virtual Ethernet adapter (e.g., vEthernet (Default Switch)) and can access external networks through port‑mapping performed by the host.
On the host, open Control Panel → All Control Panel Items → Network Connections to see adapters such as vEthernet (Default Switch) and vEthernet (WLAN), which correspond to the virtual switches.
Configuring Network Inside a CentOS VM
CentOS VMs created by Hyper‑V have no network configuration by default. Follow these steps:
Identify the primary network interface (usually eth0) with ip addr.
Edit the interface configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 and set a static address that matches the subnet of the host’s virtual adapter:
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.x # replace x with an unused host address
GATEWAY=192.168.0.1 # host’s virtual adapter address
NETMASK=255.255.255.0Configure DNS by editing /etc/resolv.conf to use the same DNS servers as the Hyper‑V host.
Restart the network service to apply changes: systemctl restart network.service Verify the configuration from the host with ipconfig /all or from the VM with ip addr.
Testing Connectivity
After setting the static IP, gateway, netmask, and DNS, the VM should be able to ping external addresses and browse the Internet. Use ping or a web browser inside the VM to confirm connectivity. The host can also verify that the VM appears with the assigned IP address.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
