Resolving network issues in Ubuntu 22.04 on KVM often involves correcting the virtual NIC model or fixing bridge configurations. The most common fix is switching the network device from e1000 to virtio in virt-manager settings and ensuring the host bridge is correctly linked to your physical interface.
Verify Host Bridge Configuration
The foundation of any successful KVM networking setup lies in the host machine's bridge configuration. If the host cannot route traffic through a bridge, the guest VM will remain isolated regardless of its internal settings. You must ensure that a Linux bridge exists and is attached to your physical network interface, such aseth0 or wlan0.
On modern Ubuntu systems, NetworkManager handles these bridges automatically when you create one via the GUI. However, manual interventions or corrupted state files can break this link. To verify the current state, open a terminal on the host and run the following command:
nmcli connection show
Look for an entry named something like br0 or bridge-br0. If it is missing, you need to create a new Ethernet connection in NetworkManager, set the method to "Bridge," and select your physical interface as the slave. If the bridge exists but shows no IP address, check the status with:
ip addr show br0
If the bridge has no IP, ensure that the physical interface connected to it is set to "Manual" or "Off" in NetworkManager to prevent IP conflicts. For more details on managing QEMU and KVM integrations, see our guide on virt-manager with QEMU and KVM.
Change the Virtual NIC Model to Virtio
Ubuntu 22.04 utilizes optimized drivers for KVM environments, specifically thevirtio suite. Using legacy models like e1000 (Intel PRO/1000) or rtl8139 can lead to performance degradation and occasional driver timeouts that manifest as dropped packets or complete network failure. The virtio-net driver is paravirtualized, meaning it communicates directly with the hypervisor, reducing overhead and improving stability.
To change this setting, shut down the Ubuntu VM completely. Open virt-manager and double-click the VM to open its details. Navigate to the "Overview" tab and click "Add Hardware." Select "Network Source" if adding a new device, or edit the existing "Network" device. In the "Device model" dropdown, select virtio. Ensure the "Source mode" is set to "Bridge device" and the source is your previously verified bridge interface.
After applying these changes, start the VM. Ubuntu should detect the new hardware and load the appropriate kernel module. If the network still fails, proceed to check the internal network configuration within the guest OS.
Check Guest Network Manager Settings
Once the virtual hardware is correct, the issue may lie within Ubuntu's own network management tools. Ubuntu 22.04 uses Netplan for configuration, which generates systemd-networkd or NetworkManager backend files. Sometimes, updates or fresh installations leave the network interface in a "down" state or misconfigured. Boot into the Ubuntu VM and open a terminal. Run the following command to list all network interfaces:ip link show
Identify your primary interface, typically named ens3, enp0s3, or similar. Check its state; if it says DOWN, bring it up with:
sudo ip link set dev [interface-name] up
Next, verify that DHCP is enabled. Check the Netplan configuration file located in /etc/netplan/. It usually contains a YAML file ending in .yaml. Open it with a text editor like nano:
sudo nano /etc/netplan/*.yaml
Ensure the section for your network controller includes:
network:
version: 2
ethernets:
ens3: # Replace with your interface name
dhcp4: true
Apply the configuration using:
sudo netplan apply
If you encounter errors during application, check the logs for syntax issues. This step resolves many connectivity problems caused by stale configuration files. For users dealing with complex iptables rules that might interfere, refer to our article on Unable to forward all traffic from one interface to another with iptables.
Restart Networking Services
If the configuration appears correct but the VM still lacks internet access, restarting the networking services can clear temporary states or stuck connections. In Ubuntu 22.04, depending on whether you are using NetworkManager or systemd-networkd, the service names differ. For NetworkManager users, restart the daemon with:sudo systemctl restart NetworkManager
For systemd-networkd users, use:
sudo systemctl restart systemd-networkd
After restarting, check if the interface has obtained an IP address again using ip addr. Test connectivity by pinging a public DNS server, such as Google's 8.8.8.8. If ping works but web browsing fails, the issue may be related to DNS resolution rather than basic connectivity.
Frequently Asked Questions
Why does my VM have an APIPA address (169.254.x.x)?
An APIPA address indicates that the VM failed to obtain an IP from the DHCP server on the host bridge. This usually means the bridge is not properly linked to the physical network or the DHCP service on the host is unreachable. Verify the bridge configuration on the host and ensure the physical interface is active.
Can I use NAT instead of Bridged networking?
Yes, NAT is a viable alternative if bridging causes conflicts with your local network. In virt-manager, select "Virtual network: default" as the source. This allows the VM to share the host's IP address but prevents direct inbound connections from other devices on your LAN.
How do I check if iptables is blocking my VM traffic?
Run sudo iptables -L -n -v on the host to view filter rules. Look for chains dropping packets from your bridge interface. If you see aggressive drop rules, you may need to adjust them or flush the chain temporarily to test connectivity.
What if virtio drivers are not loading in Ubuntu?
Ensure your VM is running a recent kernel version. Older kernels may lack updated virtio drivers. Update Ubuntu with sudo apt update && sudo apt upgrade and reboot. If issues persist, check dmesg logs for virtio initialization errors.
Does enabling IPv6 cause network issues in KVM?
Sometimes, dual-stack configurations can cause routing confusion if the host bridge does not support IPv6 properly. Try disabling IPv6 in the Netplan configuration by setting dhcp6: false and accept-ra: false to isolate IPv4 connectivity issues.