Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3749  / 2 Years ago, tue, january 4, 2022, 9:49:58

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.


More From » networking

 Answers
1

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):


# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
dhcp4: no
bridges:
br0:
interfaces: [ enp4s0 ]
dhcp4: no
addresses: [192.168.2.15/24]
gateway4: 192.168.2.1
nameservers:
addresses: [1.1.1.1]
dhcp6: no
link-local: [ ]
parameters:
stp: true
forward-delay: 4

Do:


sudo netplan apply

Go to /etc/libvirt/qemu/networks. There should be a host-bridge.xml file. Save a copy:


sudo cp host-bridge.xml host-bridge.xml.original

If you do not have a host-bridge.xml file, my original was:


doug@s19:~/config/etc/libvirt/qemu/networks$ cat host-bridge.xml.original
<network>
<name>host-bridge</name>
<bridge name='br0'/>
<forward mode="bridge"/>
</network>

Runs these commands:


virsh net-define host-bridge.xml
virsh net-autostart host-bridge
virsh net-start host-bridge
virsh net-list --all

In case of having issues and needing to undo, be aware of:


virsh net-destroy br0
virsh net-undefine br0

Example:


doug@s19:~/config/etc/libvirt/qemu/networks$ virsh net-list --all
Name State Autostart Persistent
------------------------------------------------
host-bridge active yes yes

Example:


doug@s19:~/config/etc/libvirt/qemu/networks$ sudo cat /etc/libvirt/qemu/networks/host-bridge.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh net-edit host-bridge
or other application using the libvirt API.
-->

<network>
<name>host-bridge</name>
<uuid>d474d859-8448-4055-9fc0-bb0b6cb83c34</uuid>
<forward mode='bridge'/>
<bridge name='br0'/>
</network>

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:


<interface type='network'>
<mac address='52:54:00:06:8d:b0'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

after:


<interface type='bridge'>
<mac address='52:54:00:06:8d:b0'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

For creating a new VM, and depending on your method, something like:


virt-install -n serv-jj -r 8192 
--disk path=/home/doug/vm/serv-jj.img,bus=virtio,size=50
-c jammy-live-server-amd64-2022-04-21.iso
--network bridge=br0,model=virtio,mac=52:54:00:27:1c:6e
--graphics vnc,listen=0.0.0.0 --noautoconsole -v --vcpus=4 --cpu SandyBridge

Examples with 3 VMs running:


doug@s19:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 3c:7c:3f:0d:99:83 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 3c:7c:3f:0d:99:83 brd ff:ff:ff:ff:ff:ff
inet 192.168.111.136/24 brd 192.168.111.255 scope global dynamic br0
valid_lft 81610sec preferred_lft 81610sec
4: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:22:2f:dc brd ff:ff:ff:ff:ff:ff
5: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:60:ea:3e brd ff:ff:ff:ff:ff:ff
6: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:60:ea:5e brd ff:ff:ff:ff:ff:ff
doug@s19:~$ networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp3s0 ether enslaved configured
3 br0 bridge routable configured
4 vnet0 ether carrier unmanaged
5 vnet1 ether carrier unmanaged
6 vnet2 ether carrier unmanaged
doug@s19:~$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.3c7c3f0d9983 no enp3s0
vnet0
vnet1
vnet2

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


[#447] Thursday, January 6, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ippalogu

Total Points: 215
Total Questions: 127
Total Answers: 146

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
ippalogu questions
Tue, Sep 21, 21, 09:12, 3 Years ago
Wed, May 19, 21, 02:24, 3 Years ago
Mon, Dec 27, 21, 01:44, 2 Years ago
Sat, Jul 3, 21, 00:10, 3 Years ago
;