======= Virtual Networking using KVM/QEMU =======
===== Step 1: Create the bridge =====
==== Using NetworkManager ====
=== Create the bridge ===
sudo nmcli connection add type bridge ifname br0 con-name br0
=== Add eno1 as a bridge slave ===
sudo nmcli connection add type ethernet con-name br0-slave ifname eno1 master br0
=== Set bridge to use DHCP ===
sudo nmcli connection modify br0 ipv4.method auto
sudo nmcli connection up br0
sudo nmcli connection up br0-slave
=== Check ===
nmcli connection show
===== Step 2: Configure host networking =====
Once bridged, your host’s IP will now be assigned to br0, not eno1.
This is normal: eno1 is now just a physical port slave.
===== Step 3: Configure libvirt to use the bridge =====
Option A: Use virt-manager
Open virt-manager.
Edit → Connection Details → Virtual Networks tab.
You can disable default NAT network (optional).
When creating or editing a VM:
Go to NIC → Change "Network source" to "Specify shared device name".
Enter: br0.
Set device model to virtio (recommended for Linux guests).
✅ Check your guest interface name
Inside your guest VM, run:
bash
CopyEdit
ip a
Look for a device name like:
CopyEdit
ens3, ens4, enp1s0, eth0, etc.
Example output:
yaml
CopyEdit
2: ens3: mtu 1500 ...
inet 192.168.1.50/24 ...
In this example, the interface is ens3.
✅ Configure DHCP using netplan (Ubuntu 18+)
Most recent Ubuntu versions use netplan for network configuration.
Edit netplan file
bash
CopyEdit
sudo nano /etc/netplan/01-netcfg.yaml
File name might be slightly different (e.g., 00-installer-config.yaml). You can list files:
bash
CopyEdit
ls /etc/netplan/
Example DHCP config
yaml
CopyEdit
network:
version: 2
ethernets:
ens3:
dhcp4: true
Replace ens3 with your interface name, exactly as shown in ip a.
Apply changes
bash
CopyEdit
Netplan generate
sudo netplan apply
Check
bash
CopyEdit
ip a
You should now see an IP like 192.168.1.123 on ens3.
✅ If all else fails: Try manual DHCP request
If your config looks correct but no IP yet:
bash
CopyEdit
sudo dhclient ens3
✅ Test
bash
CopyEdit
ping 8.8.8.8
Or:
bash
CopyEdit
ping google.com
💬 💥 Summary for Step 4 (expanded)
✅ Identify your VM interface name (e.g., ens3).
✅ Edit /etc/netplan/xxx.yaml to set dhcp4: true.
✅ Apply with sudo netplan apply.
✅ Check ip a to confirm you got a LAN IP.
✅ Test connectivity.
If dhclient enp1s0 hangs
When dhclient enp1s0 hangs, that usually means:
The VM is not seeing the bridge properly, or
There’s no DHCP response coming through the bridge, or
The VM's virtual NIC isn't attached to the bridge at all.
💡 Let’s troubleshoot step by step
✅ 1️⃣ Confirm guest NIC is really connected to the bridge
On your host, run:
bash
CopyEdit
virsh dumpxml | grep -A 5 '
✅ 2️⃣ Check bridge is working on host
On host, run:
bash
CopyEdit
brctl show
(or, if brctl isn’t installed, install: sudo apt install bridge-utils)
Example output:
yaml
CopyEdit
bridge name bridge id STP enabled interfaces
br0 8000.xxxxxxxxxxxx no eno1
vnet0
You should see eno1 as an interface in br0.
You should also see something like vnet0, which is your VM’s virtual NIC.
If you do not see vnet0, the VM isn’t connected properly.
✅ 3️⃣ Check if bridge is passing DHCP
On your host:
bash
CopyEdit
tcpdump -i br0 port 67 or port 68
Then, from inside guest, run:
bash
CopyEdit
sudo dhclient enp1s0
On host, you should see DHCP discover packets.
If you see nothing, the VM is not sending or packets aren’t passing.
⭐ If you'd like, please paste those outputs — I’ll walk you line by line and tell you exactly what to fix. Want to?
You said:
I don't see vnet0
ChatGPT said:
💥 Aha! That’s the big clue — you don’t see vnet0 in your bridge.
🔎 Why this is critical
When a KVM guest is running and correctly connected to a bridge (like br0), you must see an interface like vnet0, vnet1, etc. in brctl show.
If it is missing, that means:
The VM’s NIC is not actually connected to the bridge.
It's still connected to the default virbr0 (NAT) or misconfigured.
✅ Fix your VM's NIC to point to br0
🟢 If using virt-manager (GUI)
1️⃣ Shut down the VM.
2️⃣ Open virt-manager.
3️⃣ Select the VM → Open → Click Show virtual hardware details (the ⚙️ icon).
4️⃣ Select the NIC entry.
5️⃣ In "Network source":
Change from "NAT" (or default) to "Bridge br0".
If "br0" does not show, choose Specify shared device name, then type br0.
Device model: virtio (recommended for Linux).
6️⃣ Apply, then start the VM again.
🟢 If using virsh (CLI)
Edit the VM
bash
CopyEdit
sudo virsh edit
Find block
It may look like this (incorrect example):
xml
CopyEdit
...
Change it to use bridge
xml
CopyEdit
Save and exit.
Restart the VM
bash
CopyEdit
sudo virsh start
✅ Check again
On the host, run:
bash
CopyEdit
brctl show
You should now see something like:
yaml
CopyEdit
bridge name bridge id STP enabled interfaces
br0 8000.xxxxxxxxxxxx no eno1
vnet0
✅ Retry DHCP in guest
Inside the guest:
bash
CopyEdit
sudo ip link set enp1s0 up
sudo dhclient enp1s0
Check:
bash
CopyEdit
ip a
💬 Summary (your next moves)
✅ Fix the VM NIC so it points to br0.
✅ Confirm vnet0 appears in brctl show.
✅ Retry DHCP inside guest.
✅ Check guest IP.
⭐ If you'd like, paste your current XML block or a screenshot of the virt-manager NIC settings — I can write exactly what to change for you (ready to copy/paste). Want me to?
You said:
Hooray.. we're up
ChatGPT said:
🎉👏 Fantastic!! That’s exactly what we like to hear — well done!
✅ Your VM is now on the LAN, with its own real IP.
✅ vnet0 properly shows up in the bridge.
✅ You can reach it directly from your other machines.
I have an Linux mint host and running a KVM server, which has a bridged network interface. So, now br0 has my ip address. The issue is that when my computer sleeps and wakes up, br0 doesn't have an IP address
ChatGPT said:
This is a common issue with Linux bridges (like br0) on laptops or desktops that sleep (suspend) and wake. When your system suspends, the physical network interface (e.g., enp3s0, eth0, etc.) is brought down, and when it resumes, NetworkManager or your network stack doesn’t always properly reinitialize the bridge (br0), so it ends up without an IP.
Here’s a detailed explanation and options to fix it.
🔎 Why does it happen?
When the system sleeps:
The physical NIC is turned off or disconnected.
The bridge (br0) remains up but "disconnected" from the physical NIC.
On resume, the NIC may come up, but the bridge may not automatically reacquire an IP via DHCP.
✅ Solutions
1️⃣ Restart NetworkManager on resume
This is often the simplest fix if you're using NetworkManager.
Create a file:
bash
CopyEdit
sudo nano /etc/systemd/system/nm-resume.service
Paste:
ini
CopyEdit
[Unit]
Description=Restart NetworkManager after resume
After=suspend.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart NetworkManager
[Install]
WantedBy=suspend.target
Then enable it:
bash
CopyEdit
sudo systemctl enable nm-resume.service
This will restart NetworkManager whenever your system resumes, causing br0 to reacquire its IP.