Understanding the Network Topology
In a typical home or small office environment, the goal is to have OpenWrt act as a gateway or transparent bridge rather than a NATed device behind another router. For this to work, the Hyper-V virtual switch must be configured as an External type. This specific configuration binds the virtual switch to a physical network adapter on your Windows host, allowing frames to pass between the virtual machine and the physical LAN.
It is crucial to understand that when you create an External virtual switch, Hyper-V installs a mini-filter driver on the host’s physical NIC. This allows the host operating system to share the network connection with the VM. Consequently, the host machine will temporarily lose its own network connectivity during the creation process, but it will regain access once the switch is fully established. If you are using Wi-Fi, note that many wireless adapters do not support promiscuous mode required for bridging, so a wired Ethernet connection is strongly recommended for stability.
Creating the External Virtual Switch
The first step is to configure the virtual infrastructure within Hyper-V. Open the Hyper-V Manager application on your Windows host. From the right-hand actions pane, click on Virtual Switch Manager. In the window that appears, select New virtual network switch and choose External from the dropdown menu.
- Name the Switch: Give it a descriptive name such as
OpenWrt-Bridge. - Select Adapter: Choose the physical network adapter that provides your internet connection (e.g., Ethernet Controller).
- Enable Sharing: Check the box labeled Allow management operating system to share this network adapter. This is critical; without this checkbox, the Windows host will lose internet access entirely while the VM is running, and the VM may not function correctly depending on your specific hardware drivers.
Click OK to apply the changes. You will receive a warning that network connectivity will be interrupted briefly. Confirm the action. Once completed, verify that your Windows host still has internet access by opening a browser. If it fails, ensure the sharing option was checked and try recreating the switch.
Troubleshoot Hyper-V Ubuntu VM NIC Not Getting IP Address After UpgradeConfiguring the OpenWrt Virtual Machine
With the virtual switch ready, you need to attach it to your OpenWrt VM. Shut down the OpenWrt virtual machine if it is currently running. Right-click the VM in Hyper-V Manager and select Settings. Navigate to the SCSI Controller or SATA Controller section where your virtual hard disk is attached, and then locate the Network Adapter section.
In the Network Adapter settings, change the Virtual switch dropdown from its default (usually Default Switch) to the OpenWrt-Bridge you created earlier. The Default Switch uses NAT and internal networking, which prevents direct access to your LAN devices and often complicates DHCP assignment from your main router. By switching to the External bridge, the OpenWrt VM becomes a direct participant on your physical network.
Apply the settings and start the VM. During boot, OpenWrt should request an IP address via DHCP from your primary router, just like any other physical device on the network. You can check the console output or use a tool like ifconfig inside the VM to verify it has received an IP address in your subnet range (e.g., 192.168.1.x).
Verifying Connectivity and Routing
Once the VM is online, test the connectivity. Log into the OpenWrt web interface or SSH into the VM. Run a ping command to an external IP address, such as ping 8.8.8.8, and then to a local device, such as your router’s gateway IP. If both succeed, the basic layer 2 and layer 3 connectivity is working.
If you encounter issues where the VM gets an IP but cannot reach the internet, check the firewall rules on your Windows host. Sometimes, Windows Defender Firewall or third-party antivirus software blocks incoming/outgoing traffic for new virtual adapters. Ensure that the OpenWrt-Bridge adapter is allowed on private networks. Additionally, verify that the OpenWrt instance itself does not have aggressive firewall rules blocking outbound traffic on the lan zone by default, although standard OpenWrt installations usually allow forwarding from LAN to WAN.
Advanced Considerations
For most users, the External Bridge method is sufficient. However, if you plan to run multiple services or require stricter isolation, consider setting up VLANs. This requires support from your physical switch and additional configuration in both Hyper-V and OpenWrt. It allows you to segment traffic logically even though they share the same physical wire.
Another common pitfall is MAC address filtering. Some routers block devices based on unknown MAC addresses. Since Hyper-V generates a random MAC address for new VMs, your router might reject the DHCP request. Check your router’s logs for denied requests and add the OpenWrt VM’s MAC address to the allowed list or disable MAC filtering temporarily during setup.
Frequently Asked Questions
Why did my Windows host lose internet after creating the switch?
This happens if you forgot to check the "Allow management operating system to share this network adapter" box. Reopen the Virtual Switch Manager, edit the switch, and ensure the sharing checkbox is selected. The host shares the physical NIC's bandwidth with the VM through this filter.
Can I use Wi-Fi for the Hyper-V External Switch?
While technically possible on some advanced wireless cards, it is highly unstable and unsupported by many manufacturers. Wireless adapters often lack the necessary promiscuous mode support required for bridging. Use a wired Ethernet connection for reliable internet access in the VM.
How do I find the IP address of my OpenWrt VM?
Check your main router’s DHCP client list. Look for a device named openwrt or identified by the MAC address assigned in Hyper-V settings. Alternatively, check the Hyper-V event logs or use arp -a in Windows to see recent ARP responses from the VM.
What is the difference between Default Switch and External Switch?
The Default Switch uses NAT and isolates the VM from the physical LAN, making it invisible to other devices on your network. An External Switch bridges the VM directly to your physical network, allowing it to obtain an IP from your router and communicate with other LAN devices.
Why can't OpenWrt ping the internet but gets an IP?
This usually indicates a routing or firewall issue. Verify that the default gateway in OpenWrt matches your router's IP. Also, check if Windows Firewall is blocking ICMP (ping) packets for the virtual adapter, or if OpenWrt's firewall zones are misconfigured.