Steps to connect VM created by LXC to ovs bridge

Hi,

I am a newbie to lxc and open vswitch. I am have brought up a Ubuntu VM using lxc launch. I have created an ovs bridge on the host and added my ethernet interface to the ovs bridge. I am able to access the host machine via the ovs bridge.

I intend to run apps on the Ubuntu VM. So, I need to have external traffic coming in and going out from the VM via the ovs bridge

I added one of the VM’s network interface to the ovs bridge using the cmd:
lxc config device add ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0

In the VM, I do not see a IP address assigned to the enp5s0 nic interface. I am not sure if my steps are correct or complete. Looking for guidance/help

You did the right step connect VM to ovs bridge. But you didn’t tell the VM to use the NIC you added.
Here is some guide for you:

  1. Use ip a to find the NIC name you just added. Because you didn’t set the name when you run the cmd.
  2. Manually bring up the NIC. Because ubuntu use netplan for network and I don’t use netplan, so search it yourself.
  3. If you don’t need VM connects to lxdbr0 anymore, bring down eth0.
  4. Restart network after you bring up the NIC. It’s not necessary, but recommended.

Thanks @catfish , in the command:
lxc config device add ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0

The ‘enp5s0’ interface is the pre-existing interface in the VM which I tried to connect to ovs bridge. I hope this is right
the VM was previously connected to lxdbr0, so I removed the connection and deleted the lxdbr0

I have connected my eth0/eno1 host interface to the ovs bridge and ran dhclient shashi_ovsbr0 from console so that the ovs bridge has direct network access

So, should I modify the command to look like:
lxc config device add ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0 name=enp5s0

So when you first run lxc config device add ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0, you already disconnected VM to lxdbr0, you just didn’t run dhclient, that why your VM didn’t get an ip, right?

If you run lxc config device add ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0 name=enp5s0, I guess you will encounter error, try this: lxc config device override ubuntu-vm1 enp5s0 nic nictype=bridged parent=shashi_ovsbr0 name=enp5s0

And the NIC’s name doesn’t have to be enp5s0, it just need to show in ip a and connects to shashi_ovsbr0.

And wait a moment, I just created a VM, it’s default NIC name is enp5s0. Interesting, container’s default NIC name is eth0. And I added my network profile to it, but the profile is this:

devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: ovsbr0
    type: nic

Neither device name and device name in vm is enp5s0. So ignore all cmd above, run all this cmd for test and find out which is the right one, I believe you can learn from failure. And don’t worry if you will run some wrong cmd, you can always take snapshots before taking action. I’ve done a lot trial and error to learn incus features.

  • lxc config device override ubuntu-vm1 enp5s0 nic name=enp5s0 nictype=bridged parent=shashi_ovsbr0
  • lxc config device override ubuntu-vm1 enp5s0 nic name=eth0 nictype=bridged parent=shashi_ovsbr0
  • lxc config device add ubuntu-vm1 eth0 nic name=enp5s0 nictype=bridged parent=shashi_ovsbr0
  • lxc config device override ubuntu-vm1 eth0 nic name=eth0 nictype=bridged parent=shashi_ovsbr0

Thanks @catfish , I was away on another work. the ovs work got de-prioritized. I will try commands suggested by you once I get back on the task.
Appreciate your help!