Understanding Two Network Interfaces in Ubuntu 22.04 with Hyper-V Virtual Machines

Abstract: Configure dual network interfaces in Ubuntu 22.04 Hyper-V VMs using Netplan for separate internet and internal traffic routing.

Created: 2026-09-21 by
To configure two network interfaces in Ubuntu 22.04 on Hyper-V, you must edit the Netplan configuration files located in /etc/netplan/. This setup allows one interface to handle external internet traffic while the second manages internal or isolated network communication, ensuring stable connectivity for complex virtual machine environments.

Identifying Your Network Interfaces

Before modifying any configuration, you need to know the exact names of your network adapters. Modern Linux distributions use predictable network interface naming schemes, which means the names will not be simple eth0 or eth1. Instead, they often follow patterns like enp3s0, ens33, or similar variations depending on the bus and slot. Open a terminal in your Ubuntu VM and run the following command:
ip link show
This output lists all network interfaces along with their MAC addresses and state. You will see at least two active interfaces if you have attached two virtual switches in Hyper-V. Note down the names of both interfaces. For example, you might identify enp0s3 as your primary internet-facing adapter and enp0s8 as your internal-only adapter. It is crucial to use these exact names in your configuration files to avoid errors. If you are unsure which interface corresponds to which physical switch in Hyper-V, you can temporarily disconnect one virtual switch and observe which interface goes down using ip link show.

Configuring Netplan YAML Files

Ubuntu 22.04 uses Netplan for network configuration. The configuration files are stored in /etc/netplan/ and typically end with a .yaml extension. There is usually only one file in this directory, such as 00-installer-config.yaml or 50-cloud-init.yaml. Always back up the original file before making changes:
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Edit the YAML file using a text editor like nano or vim:
sudo nano /etc/netplan/00-installer-config.yaml
The structure of the Netplan file defines how each interface behaves. You need to specify whether an interface gets its IP address via DHCP or if it should use a static IP address. Below is a generic template that demonstrates how to define two interfaces. Replace the placeholder interface names and IP details with your actual values.
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3: # Primary Interface (Internet)
      dhcp4: true
      dhcp6: false
    enp0s8: # Secondary Interface (Internal)
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.100.10/24
      routes:
        - to: 192.168.100.0/24
          via: 192.168.100.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
In this example, enp0s3 is configured to obtain an IP automatically from your router via DHCP. This is the standard approach for the interface connected to your main network. The second interface, enp0s8, is set to static addressing. This is common for internal networks where you want consistent IP addresses for services like DNS, web servers, or database connections that other machines need to reach reliably. Note that the deprecated gateway4 directive has been removed in recent Netplan versions. Instead, you must explicitly define routes using the routes block. In the example above, the route directs traffic destined for the 192.168.100.0/24 subnet through the gateway 192.168.100.1. If your secondary interface does not require a default gateway (because it is isolated), you can omit the routes section entirely for that interface. However, ensure that the primary interface handles the default route to the internet.

Applying and Verifying Changes

Once you have saved the YAML file, apply the configuration by running:
sudo netplan apply
If there are syntax errors in your YAML file, this command will return an error message indicating the line number and nature of the problem. YAML is sensitive to indentation, so ensure that spaces are used consistently (typically two spaces per level) and that tabs are not used. After applying the configuration, verify that both interfaces are working correctly. Use the ip addr show command to check if the IP addresses have been assigned as expected. You can also test connectivity by pinging an external host from the primary interface and pinging a host on the internal network from the secondary interface.
ping -c 4 8.8.8.8
ping -c 4 192.168.100.1
If you experience issues with name resolution after configuring multiple interfaces, it is often due to how the resolver handles multiple DNS sources. You may need to adjust your /etc/resolv.conf settings or ensure that your DHCP server provides the correct DNS servers. For more details on resolving name resolution issues in multi-interface setups, refer to our guide on Temporary Failure in Name Resolution with pfSense on Ubuntu Server 22.04. Additionally, if you find that internet access is lost after adding a second interface, it might be because the routing table is prioritizing the wrong interface for default traffic. Ensure that only one interface defines a default route (to: default). If you accidentally add a default route to the secondary interface, it can cause asymmetric routing issues. See Lost Internet Connection After Upgrading Ubuntu 20.04.6: Two Different Interfaces named en01 and eth1 for troubleshooting steps related to interface conflicts.

Troubleshooting Common Issues

Even with correct YAML syntax, you might encounter connectivity problems. One common issue is that the Hyper-V virtual switch is not properly bridged to the physical NIC on the host machine. Check the Hyper-V Manager on your Windows host to ensure that the virtual switch is connected to an external network adapter. Another potential pitfall is firewall rules blocking traffic on the secondary interface. Ubuntu uses ufw (Uncomplicated Firewall) by default. If you enable ufw, you must explicitly allow traffic on the specific interface or port ranges you intend to use. You can check the status of your firewall with:
sudo ufw status verbose
If you are running services on the secondary interface, ensure that they are bound to the correct IP address. For example, if you are setting up a web server, you might want it to listen only on the internal IP to prevent external access. You can configure this in your application's configuration file by specifying the listen address as the static IP of enp0s8. Finally, always keep your system updated. Kernel updates can sometimes change driver behaviors or network stack optimizations. Regularly run sudo apt update && sudo apt upgrade to ensure you have the latest stability fixes. For broader troubleshooting of misconfigured files that affect SSH and web labs, consult Misconfigured Files: Web Labs, SSH Server, ping, traceroute, and Web Apps Not Working on Main VM (SSH via Browser Works).

Frequently Asked Questions

Can I use DHCP for both interfaces?

Yes, you can configure both interfaces to use DHCP by setting dhcp4: true for each. However, this is generally discouraged for internal interfaces because dynamic IP assignments can break connections to services that rely on fixed addresses. Static IPs provide better predictability for internal networking.

What happens if I make a typo in the Netplan YAML file?

If you introduce a syntax error, netplan apply will fail and display an error message. Your existing network configuration remains unchanged until you successfully apply a new valid configuration. To recover, you can revert to the backup file you created earlier using sudo cp /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml and then reapply.

How do I remove a default gateway from a specific interface?

To remove a default gateway, simply delete the line containing gateway4 (if present in older configs) or the route entry with to: default under the specific interface block in the YAML file. Only one interface should have a default route to ensure proper internet routing.

Why is my secondary interface not visible in ip addr show?

If the interface does not appear, it may be disabled in Hyper-V or disconnected from the virtual switch. Verify the connection in Hyper-V Manager. Additionally, check if the interface name has changed due to kernel updates or hardware changes. Using ip link show helps identify the current names.

Can I assign multiple IP addresses to a single interface?

While Netplan primarily supports one primary IP per interface, you can add additional IPs using the addresses list within the same interface block. However, for distinct network segments, it is cleaner and more manageable to use separate physical or virtual interfaces rather than aliasing multiple IPs on one NIC.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More