How to Fix UFW Blocking KVM Guest from Getting IP Address and Accessing Network

Abstract: Resolve KVM guest network isolation by configuring UFW to allow traffic on the bridge interface for DHCP and connectivity.

Created: 2026-08-20 by

UFW blocks KVM guests from obtaining IP addresses by filtering DHCP broadcasts on the host bridge interface. To restore connectivity, you must configure UFW to allow traffic specifically on the bridge device (typically br0) while keeping the physical interface restricted. This ensures the guest VM can communicate with the DHCP server and access the network without compromising host security.

Understanding the Root Cause

When you set up a KVM virtual machine with bridged networking, the host creates a virtual bridge interface (often named br0 or similar) that connects the guest directly to your local network. The guest VM sends DHCP requests as broadcast packets to this bridge. If UFW is enabled on the Ubuntu host, it may inadvertently drop these essential broadcast packets because they arrive on the bridge interface rather than the physical Ethernet port (eth0 or wlan0). By default, UFW policies often apply to incoming traffic on all interfaces unless explicitly scoped. If the policy is set to DROP or REJECT for incoming connections, the DHCP discovery packets from the guest never reach the DHCP server on your router. Consequently, the guest fails to obtain an IP address via DHCP, leaving it isolated. Additionally, even if static IPs are assigned, general network traffic might be blocked if the bridge interface is not correctly whitelisted in the firewall rules. It is crucial to distinguish between the physical interface and the bridge interface. Allowing traffic only on eth0 does not automatically permit traffic on br0. You must explicitly configure UFW to trust the bridge interface. This approach maintains security by restricting direct access to the host's physical network stack while enabling the necessary layer-2 communication for virtual machines. For more context on firewall setups for virtual networks, you might find Setting Up a Firewall on Ubuntu Network Gateway for a Virtual Network with VirtualBox helpful, although the principles of interface-specific rules apply similarly to KVM.

Step 1: Identify Your Bridge Interface

Before modifying firewall rules, you need to confirm the name of the bridge interface used by your KVM guests. Run the following command in the terminal:
ip addr show
Look for an interface with type bridge. It is typically named br0, but it could also be virbr0 (if using libvirt's default NAT bridge) or a custom name defined in your Netplan configuration. Note the exact name, as you will use it in the next steps. If you are using Netplan, check the YAML files in /etc/netplan/ to see how the bridge is defined.

Step 2: Configure UFW for the Bridge Interface

The most effective solution is to allow all traffic on the bridge interface. Since the bridge operates at Layer 2, allowing incoming and outgoing traffic on this interface ensures that DHCP broadcasts and subsequent network packets pass through unimpeded. Open the UFW application profiles or modify the rules directly. The recommended method is to add specific rules for the bridge interface. Execute the following commands, replacing br0 with your actual bridge interface name:
sudo ufw allow in on br0
sudo ufw allow out on br0
These commands tell UFW to ignore filtering rules for any traffic entering or leaving the specified bridge interface. This effectively whitelists the virtual network segment connected to the bridge. If you have multiple bridge interfaces, repeat these commands for each one. If you prefer a more granular approach, you can allow only specific protocols. However, for DHCP and general LAN access, allowing all traffic on the bridge is standard practice because the bridge itself handles MAC address filtering and forwarding. The host kernel manages the separation between the host and guest traffic, so broad rules on the bridge interface do not expose the host to external threats from the guest side beyond what the bridge already permits.

Step 3: Verify UFW Status and Rules

After adding the rules, verify that they have been applied correctly. Run:
sudo ufw status verbose
You should see lines indicating "ALLOW IN" and "ALLOW OUT" for your bridge interface. Ensure that the default policies for other interfaces (like eth0) remain restrictive if desired. For example, you might want to keep SSH access restricted to specific IPs on the physical interface while allowing full access on the bridge. If the guest still cannot get an IP, check if UFW is actually active. Sometimes, services like firewalld or other iptables-based firewalls may conflict. On Ubuntu, UFW is the primary tool, but ensure no other firewall service is running. You can check with:
systemctl status ufw

Step 4: Restart Networking and Test

Once the rules are in place, restart the networking service or reboot the host to ensure the changes take effect cleanly. Alternatively, you can restart the KVM guest. Inside the guest VM, request a new IP address using:
sudo dhclient -r
sudo dhclient
Or simply reboot the guest. The guest should now successfully receive an IP address from your router's DHCP server. Test connectivity by pinging an external site or accessing internal resources. For further troubleshooting if remote access remains an issue, refer to Can't Connect to VM Remotely: Troubleshooting Guide, which covers common connectivity pitfalls beyond just DHCP.

Alternative: Using NAT Instead of Bridging

If configuring UFW for bridged networking proves too complex or insecure for your use case, consider switching the KVM guest to use NAT networking instead. In NAT mode, the guest shares the host's IP address and is hidden behind the host's firewall. UFW rules on the host will naturally protect the guest, and the guest can access the internet without needing explicit bridge rules. However, inbound connections from the external network to the guest will require port forwarding rules, which adds complexity. Bridged networking is generally preferred for servers that need to be directly accessible on the local network.

Frequently Asked Questions

Why does my KVM guest fail to get an IP via DHCP?

The most common reason is that UFW is blocking DHCP broadcast packets on the bridge interface. Since DHCP relies on broadcasts, and UFW may filter them by default, the guest cannot complete the lease process. Whitelisting the bridge interface resolves this.

Can I allow only DHCP traffic on the bridge instead of all traffic?

Technically yes, by allowing UDP ports 67 and 68, but it is impractical. Once the IP is obtained, the guest needs general network access. Restricting to only DHCP would break all other connectivity, requiring additional rules for HTTP, SSH, etc., making it harder to maintain than simply allowing the bridge.

Does allowing traffic on the bridge expose my host to security risks?

It exposes the host to traffic originating from the guest VM, but not directly from the external network. The host's physical interface filters external traffic. As long as you secure the guest VM itself and do not share sensitive data unnecessarily, this setup is considered safe for home and lab environments.

What if I am using Libvirt's default virbr0 bridge?

If you are using the default Libvirt NAT bridge (virbr0), UFW usually allows it by default via its application profile. If it is blocked, run sudo ufw allow in on virbr0 and sudo ufw allow out on virbr0. Check if Libvirt has added its own iptables rules that might override UFW.

How do I revert these changes if something goes wrong?

To remove the rules, use sudo ufw delete allow in on br0 and sudo ufw delete allow out on br0. Replace "br0" with your interface name. You can view current rules with sudo ufw status numbered to identify the rule numbers for deletion.

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