I'm having quite a lot of problems setting up a network bridge for both my host and my vm to use.
The host (os of the server) is Ubuntu 20.04.4 LTS. The VM (using KVM and virt-manager) is TrueNAS Core (FreeBSD). I have one ethernet port on my server (on the motherboard) that I want to use for both my os and the vm. The os needs to get the ip of 192.168.2.15 with dns set to 1.1.1.1 and the vm needs to get the ip of 192.168.2.16. They both need to be accessible from "the outside". So, as far as I understand, I need to setup a network bridge.
Well it's all going wrong. I started with this video but with no success. Then I tried this video but also with no success. Then I tried this guide but again with no success. Then I turned to SO and tried these (1, 2) but all with no success.
Evertime there's something wrong. Most of the time DNS is not working, or the ip addresses are messed up (completely different subnet), or the os has the correct ip but can't ping any other devices (not 1.1.1.1 but also not 192.168.2.79 which is my static-ip-ed win10 computer) or /etc/network/interfaces is ignored (the file didn't exist yet). And most of the time people suggest using sudo /etc/init.d/networking restart
or similar using systemd but evertime I get the message that networking
doesn't exist which I find peculiar because everyone else does have it.
It's just all a mess and I can't get it to work. I would really appreciate some help!
The file /etc/network/interfaces
does currently not exist.
ifconfig -a
output:
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.15 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::8506:f97f:df7c:f66b prefixlen 64 scopeid 0x20<link>
ether 18:c0:4d:9b:3c:12 txqueuelen 1000 (Ethernet)
RX packets 10390 bytes 3524106 (3.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2534 bytes 330756 (330.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfc600000-fc61ffff
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 7172 bytes 712208 (712.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7172 bytes 712208 (712.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:06:8d:b0 txqueuelen 1000 (Ethernet)
RX packets 142 bytes 12152 (12.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 40 bytes 4136 (4.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:06:8d:b0 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fee6:a823 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:e6:a8:23 txqueuelen 1000 (Ethernet)
RX packets 142 bytes 14140 (14.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 939 bytes 55015 (55.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
EDIT: inside /etc/netplan
, there is one file: 01-network-manager-all.yaml
. Contents:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
I don't care about network manager. If there is some solution that works but breaks network manager, I'm totally fine with that.
I only have experience with networkd as the renderer not NetManager, so I don't know the value of this answer.
Save
/etc/netplan/01-network-manager-all.yaml
somewhere, so that you can revert if things do not work.Create
/etc/netplan/01-netcfg.yaml
(gateway address assumed):Do:
Go to
/etc/libvirt/qemu/networks
. There should be ahost-bridge.xml
file. Save a copy:If you do not have a
host-bridge.xml
file, my original was:Runs these commands:
In case of having issues and needing to undo, be aware of:
Example:
Example:
Now, modify any existing VMs to use the bridge:
Note: There is probably a way to do this step using
virt-manager
, however I do not use it and do not know how.Use
virsh edit
and change your interface definition lines to use bridging instead of what is currently being used. Something like this:Before:
after:
For creating a new VM, and depending on your method, something like:
Examples with 3 VMs running:
Not covered herein: How to set the static address of 192.168.2.16 on the VM, because the VM was stated to be FreeBSD and I do not know how.
References:
https://netplan.io/examples/#configuring-network-bridges
KVM Network Bridge to assign Static IP