Configuring Network for QEMU-KVM
Configuring Network for QEMU-KVM
NAT forwarding
flowchart TD
Internet[🌐 Internet / Physical Network<br/>Router: 192.168.1.1]
subgraph HostMachine[KVM Host Machine]
PhysicalNIC["🔌 Physical NIC (eth0)<br/>IP: 192.168.1.100"]
subgraph VirtualNetwork[Libvirt Default NAT Network]
Bridge["🔀 Virtual Bridge (virbr0)<br/>Gateway: 192.168.122.1/24<br/>DHCP + DNS + NAT"]
DHCPServer["📡 dnsmasq Process<br/>DHCP Range: 192.168.122.2-254"]
DummyInterface["📎 Dummy Interface (virbr0-nic)<br/>Provides stable MAC address"]
Bridge <-.-> DummyInterface
Bridge <--> DHCPServer
end
VM1_Tap["🔧 Virtual NIC (vnet0)<br/>VM #1: 192.168.122.100"]
VM2_Tap["🔧 Virtual NIC (vnet1)<br/>VM #2: 192.168.122.101"]
Bridge <--> VM1_Tap
Bridge <--> VM2_Tap
end
Internet <-.-> PhysicalNIC
PhysicalNIC <-.-> Bridge
%% Styling
classDef internet fill:#fbe9e7,stroke:#bf360c,stroke-width:2px,color:#000;
classDef host fill:#f5f5f5,stroke:#9e9e9e,stroke-width:2px,color:#000;
classDef physical fill:#e3f2fd,stroke:#1565c0,stroke-width:2px,color:#000;
classDef bridge fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#000;
classDef dhcp fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000;
classDef dummy fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#000;
classDef vm fill:#bbdefb,stroke:#1976d2,stroke-width:2px,color:#000;
class Internet internet;
class HostMachine host;
class PhysicalNIC physical;
class Bridge bridge;
class DHCPServer dhcp;
class DummyInterface dummy;
class VM1_Tap,VM2_Tap vm;
Remove default NAT network.
~]# virsh net-destroy default |
Add default NAT network.
~]# virsh net-define /usr/share/libvirt/networks/default.xml |
Check the default NAT network.
~]# ip a |
virbr0 is a virtual network bridge. Think of it as a virtual Ethernet switch that all your VMs are plugged into.
virbr0-nic is a persistent "dummy" Ethernet network interface that is created as a placeholder for the bridge's MAC address.
Libvirt will add iptables rules to allow traffic to/from guests attached to the virbr0 device in the INPUT, FORWARD, OUTPUT and POSTROUTING chains. It will also attempt to enable ip_forward.
~]# iptables -t nat -L -n -v |
Reference:
・ What is the interface virbr0 for and how do I disable it?
・ libvirt Networking
Bridged networking
flowchart TD
subgraph YourPhysicalNetwork [Physical Network]
Internet[🌐 Internet Router<br/>192.168.1.1]
OtherDevice[💻 Other Device<br/>e.g., Laptop: 192.168.1.45]
end
subgraph HostMachine [KVM Host Machine]
HostPhysicalEth0["🔧 Physical NIC (eth0)<br/>No IP - Slave to br0"]
subgraph VirtualNetwork [Network Bridge]
Br0["🌉 Bridge Interface (br0)<br/>IP: 192.168.1.100"]
VM1["🖥️ VM #1 (vnet0)<br/>DHCP: 192.168.1.101"]
VM2["🖥️ VM #2 (vnet1)<br/>DHCP: 192.168.1.102"]
end
Br0 <-..-> HostPhysicalEth0
Br0 <---> VM1
Br0 <---> VM2
end
Internet <-..-> Br0
OtherDevice <-..-> Br0
classDef bridgeNode fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000;
classDef vmNode fill:#ffcc80,stroke:#ef6c00,stroke-width:2px,color:#000;
classDef internetNode fill:#fbe9e7,stroke:#bf360c,stroke-width:2px,color:#000;
classDef deviceNode fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#000;
class Br0 bridgeNode;
class VM1,VM2 vmNode;
class Internet internetNode;
class OtherDevice deviceNode;
- Using ifcfg file
~]# cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF |
- Using nmcli
+-----+ +---------+ +---------------+ |
Bridging on a bond.
# Create the bridge <br0>. |
Check.
ls /sys/class/net/br0/brif/ |
- Using virsh
virsh iface-bridge eth0 br0 |
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.