0

My problem is basically that, when trying to use a bridge on a vlan interface, I don't have network to my VM, and I'm not sure what I'm missing.

I have tried the setup detailed in the examples. As well as numerous other guides. This is my current netplan .yaml (though I've tried various combinations of defining addresses, gateway4, and nameservers for the vlan or the bridge with no luck):

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: true
    eno2:
      dhcp4: true
  bridges:
    br0:
      dhcp4: true
      interfaces: [ vlan15 ]
      parameters:
        forward-delay: 0
        stp: true
  vlans:
    vlan15:
      id: 15
      link: eno1

I'd like to keep eno2 untouched, so I always have a fallback (no monitor attached). In my DHCP server, I have set eno1 = 192.168.0.100, and eno2 = 192.168.0.101.

My LAN in the router is set to 192.180.0.0/22 (I was trying to through VMs in the 192.168.1.x range, but not essential).

I have set up the bridge, and activated it:

~$ brctl show
bridge name bridge id           STP enabled interfaces
br0         8000.00215ec64304   yes         vlan15
                                            vnet0

(I'm almost certain that the vnet0 wasn't associated until I booted the VM)

and

~$ virsh net-list --all
 Name      State    Autostart   Persistent
--------------------------------------------
 br0       active   yes         yes
 default   active   yes         yes

ip a shows both br0 and vlan15 linked to the MAC of eno1. In the .xml file for the VM (/etc/libvirt/qemu/hassos.xml), it shows under "interface":

    <interface type='bridge'>
      <mac address='52:54:00:26:69:40'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

I initially set this up with br0 being linked directly to eno1, so I did the virt-install before I started to create vlan, in case that matters. But I have rebooted the VM whenever i do sudo netplan apply.

The closest I could get (which is not really close, just something happened) was that when I defined a addresses: 192.168.1.115 on the br0, I could access something on the server using this address, and the corresponding port. Just not the VM (but a "clone" running in docker, directly on the server). In that case it seems like br0 was then used for anything on the server?

I'm using Ubuntu Server LTS 20.04.

In case this matters, I have (according to other advise) disabled netfilter for bridges as described e.g. here.

EDIT: I set up the bridge for libvirt by creating an br0.xml file:

<network>
  <name>br0</name>
  <forward mode="bridge"/>
  <bridge name="br0"/>
</network>

And added it with:

virsh net-define br0.xml
virsh net-start br0
virst net-autostart br0

I've also tried more complex .xml files such as

<network>
  <name>br1</name>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='br1' stp='on' delay='0'/>
  <ip address='192.168.1.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.1.101' end='192.168.1.150'/>
    </dhcp>
  </ip>
</network>

And with the 192.168.1.X addresses, I an get it to assign in IP from within libvirt, but I can't get access externally. If I instead use a 192.168.0.X address, I get erros when trying to start it:

error: Failed to start network br1
error: internal error: Network is already in use by interface eno2

This is regardless of setting an 192.168.0.X IP within or outside DHCP pool, and regardless of setting 192.168.1.X IP as a DHCP assignment or not.

9
  • Please check this URL: ostechnix.com/… . Looks like it is explained there. Otherwise, I can help you tomorrow in detail. – NK_ Jan 6 at 16:56
  • I had something like that set up, but that uses a bridge directly on the ethernet interface (eno1). That worked, but then the bridge got the IP of eno1, and eno1 no longer had an IP. I was recommended to use a vlan, and add the bridge to that, so I could continue using the eno1 normally for everything else. And that's where I got stuck.... – Aephir Jan 6 at 19:38
  • I see. That goes a little bit beyond my network knowledge. I'm going to let you know if I can find any tips, sorry. – NK_ Jan 7 at 6:31
  • Thanks, please do. It's certainly also beyond my network knowledge... – Aephir Jan 7 at 7:41
  • Hi, how did you setup/activate the bridge "br0"? Usually netplan does that for you and there might be conflicts if you do it manually. Also, you're using DHCP for br0 and eno1, while they have the same MAC address... This might confuse your DHCP server. You could try defining another MAC for one of those devices via a "macaddress: ..." setting. – Lukas Maerdian Jan 7 at 8:44
0

I think I (almost) replicated your situation.

Both network interfaces of my server are connected to my router. My workstation is connected to the same router.

Configurations:

Server (Ubuntu Server 20.04 LTS):

  1. Interface: 192.168.0.240
  2. Interface: 192.168.0.241

Bridge (br0) on VLAN which is on 1. Interface: 192.168.100.1

Netplan File on the server:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0f0:
      addresses: [ 192.168.0.240/24 ]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [ 8.8.8.8,8.8.4.4 ]
    enx00e04c534458:
      addresses: [192.168.0.241/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8,4.4.4.4]
  bridges:
    br0:
      addresses: [ 192.168.100.1/24 ]
      interfaces: [ vlan100 ]
  vlans:
    vlan100:
      accept-ra: no
      id: 100
      link: enp3s0f0

I am not sure if it is really necessary, but to make the server to route between its interfaces (remember I was connecting to 2 different networks before), I made the following configuration.

Add following line to /etc/sysctl.conf

net.ipv4.ip_forward = 1

Run:

sudo sysctl -p

VM (Ubuntu Server 20.04 LTS):

When installing the VM with virt-install, it couldn't get the IP address automatically, so I entered manually as:

subnet: 192.168.100.0/24 ip: 192.168.100.101 gateway: 192.168.100.1

VM could not connect to the internet, but installed succesfully.

Generated netplan file of the VM:

network:
  ethernets:
    enp1s0:
      addresses:
      - 192.168.100.101/24
      gateway4: 192.168.100.1
      nameservers:
        addresses:
        - 8.8.8.8
  version: 2

After installation, I was able to access to the VM on the server, but I couldn't access it from my workstation. It looked like a routing problem. So I added a route.

Workstation (Ubuntu 20.04 LTS):

Single interface with 2 IPs. 192.168.0.242 and 192.168.0.243

Netplan file on the workstation:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
      addresses: [192.168.0.242/24,192.168.0.243/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [46.197.15.60,178.233.140.110,176.240.150.250]
      routes:
      - to: 192.168.100.0/24
        via: 192.168.0.240

The last 3 lines adds a route to 192.168.100.0 network, through the server's interface.

After all these configurations, I am able to connect to the VM from my workstation. If I need to connect to the Vm from any other computer in my network, I need to add that routing information to them too.


The old answer, to be deleted later

I don't have 2 ethernet cards, so I am not able to test it, but I believe this method would possibly run. I believe you can do it without using a VLAN. At least it is something to try.

Make your netplan file as one nic configured as standart and the other one is configured as a bridge (without DHCP just to be sure), feel free to change the IP and nameservers as you wish :

network:
  version: 2
  ethernets:
    eno1:
      dhcp4: no
    eno2:
      dhcp4: no
      addresses: [ 192.168.0.100/24 ]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [ 8.8.8.8,8.8.4.4 ]
  bridges:
    br0:
      dhcp4: no
      interfaces: [ en01 ]
      addresses: [ 192.168.0.101/24 ]
      gateway4: 192.168.0.1
      mtu: 1500
      nameservers:
        addresses: [ 8.8.8.8,8.8.4.4 ]
      parameters:
        forward-delay: 4
        stp: true

Disable netfilter, add the bridge to KVM (I believe you already did them)


As said in the comment, a working netplan config with vlan:

network:
  ethernets:
    enp3s0f0:
      addresses: [192.168.0.240/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
      dhcp4: false
      dhcp6: false
    enx00e04c534458:
      addresses: [10.1.1.1/24]
      gateway4: 10.1.1.1
      nameservers:
        addresses: [8.8.8.8,4.4.4.4]
  vlans:
    vlan10:
      id: 10
      link: enp3s0f0
  bridges:
    br0:
      interfaces: [ vlan10 ]
      addresses: [192.168.1.240/24]
  version: 2
  renderer: networkd
14
  • Thanks a lot for looking into this. And I really don't want to sound ungrateful, but this is sort of what I currently have. This works OK, but I was recommended to keep the eno1 functioning "as is" by "creating vlans on it and define bridges connected to those vlans" (actually an answer to another question I had where you also made a comment). So after that answer, I tried the vlan, it didn't work, I did the bridge without vlan, but then got stubborn, and asked about vlan here :) – Aephir Jan 9 at 20:33
  • I see and understand your point. A good computer specialist must be stabborn always. Your stabborness is my stabborness :) I'll be around until one of us solve this situation, if that is ok with you, of course. I've bought a usb lan adapter to use as a second nic. – NK_ Jan 9 at 20:51
  • Thanks a lot, just stop before you go crazy :) I'm not sure if two physical interfaces would be necessary, as I understood it, the point of the vlan instead of "just" bridge was that you could continue to use the physical interface for everything it was used for before. I might be wrong, but that was my understanding. – Aephir Jan 11 at 8:54
  • I guess I've found something. The reason your configuration does not run is, your VLAN and your original nic is in the same network. I've added a configuration I made at the end of my answer. When I configured a VLAN with another subnet, it worked. But the problem here is, all my VMs will be in another subnet. – NK_ Jan 12 at 10:50
  • Also, as you said it looks like 2 physical interfaces are not necessary. – NK_ Jan 12 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.