LXD Networking Bridge - LTS 20.04 host, how to?

I’ve got a box I setup about 8 months ago, and starting to realize I never documented the full end-to-end steps to recreate (not good if I have an issue with the box)

sources :

I was trying at first to start with just a cleaner setup than my first post… but getting stuck. Once I setup the basic bridge… and modify the yaml file my VM running kubuntu 20.04 loses all internet connectivity… Should I have run the lxd init and THEN added a bridge for my containers?

my steps so far

sudo apt update
sudo apt upgrade -y
sudo snap install lxd
sudo apt install bridge-utils vim net-tools

lxc network create mybridge

sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak

ifconfig
    enp0s2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.108  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 blah:::blah  prefixlen 64  scopeid 0x20<link>
            ether blah:::blah  txqueuelen 1000  (Ethernet)
            RX packets 12931  bytes 13508096 (13.5 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 6488  bytes 1401240 (1.4 MB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
            device memory 0xfa700000-fa71ffff
    mybridge: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet6 blah:::blah  prefixlen 64  scopeid 0x20<link>
            ether blah:::blah  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 4  bytes 304 (304.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

my netmanager looks like

network:
  version: 2
  renderer: NetworkManager
  
  ethernets:
    enp0s2:
      dhcp4: no
  bridges:
    mybridge:
     dhcp4: no
    interfaces:
      - enp0s2

I did lxd init and chose all the defaults except I chose to use mybridge instead of LXD’s default provided bridge… was this a mistake?

it feels like I need to re-add my ethernet to my desktop host… which I tried but still the internet is not reachable

Hi. Networking is not my thing, but I am wondering why you have no ip address (with dhcp set to ‘no’) and no gateway listed - it’s no wonder you can’t find the internet if there’s no gateway? I have these entries in my network file (but I use networkd not NetworkManager):

addresses: [insert-ip-here/24]
gateway4: 192.168.1.1

Good luck!

1 Like

thank you,

in my original attempt (which is still up and running) I never entered a gateway… but you’ve rightly pointed out an error… I’ve updated that file now to the following

vim /etc/netplan/01-network-manager-all.yaml

# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager

ethernets:
    enp0s2:
        dhcp4: no
    bridges:
        br0:
            dhcp4: yes
            interfaces:
            - enp0s2

this trick was, after that… run

sudo netplan apply
sudo nmcli conn add type ethernet slave-type bridge con-name bridge-br0 ifname enp0s2 master br0

The second line restores the internet to my host … not sure why exactly but … now trying to modify my default LXC profile to use that bridge instead…

devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: br0
    type: nic
  root: 
 .... 

Hopefully I am almost there…! thanks for checking in

Hmmm unfortunately I’ve seemed to have created a bridge which still just grabs a private NAT address under 10.0.1.19/24 CIDR

not my expected 192.168.0.0…

but at least I can reach from the host of the LXD machine now … and the internet works… but might need to redo the configuration to get full DHCP working

from my mac hosting the VM

Edit 2: Even after adding some more to the manager… not getting 192.168.x.x

beeng googling and fiddling… does it help to say I am hosting this linux host within a QEMU VM?? I’ve tried moving things around in the 01-network-manager-all.yaml

it seems I never can get a IP from my router … could my host OS (mac mini) be blocking something here?

Soyou likely need more help than I can give. Acouple of points: LXD will create abridge that uses a virtual lan it controls. There are several ways you can make yourcontainers accessible via your router and/or visible on your lan. A simple one is usign macvlan on lxd. It’s easy (google it), but it has a snag: containers will not be able to talk to the host via this method (it’s a feature I think - but sometimes an inconveneient one). Another way is to create your own bridge and assign that to containers as you need. Here’s mine, conveniently or confusingly called br0:

lxc profile show br0
config: {}
description: “”
devices:
eth0:
nictype: bridged
parent: br0
type: nic
root:
path: /
pool: default
type: disk
name: br0

That’s what I do. So I keep the default br0 bridge as some of my containers do not need lan access (so I keep them isolated by using the lxd bro), but those that do need easy access via the lan, I just assign my new br0 bridge to it using a single comnand:

lxc profile assign container-name br0

restart the container, and it will grab an ip from dhcp - my lan. And in this case, it can be accessed from the lan or even the host (unlike the macvlan method).

Keep going and good luck - you will get there. Lots of postings on here which google will find for you with some patience. :slight_smile:
Andrew

1 Like

I’ve infact created a bridge yes… and it seems to be okay some of the time, all except for the fact it’s not getting IPs from the router… and according to a link there’s a snag with macvlan when you’re hosted inside of a VM (which my linux LXD host is)

but I will try again… maybe I just need to get qemu/kvm host to allow promiscious mode and I will be through… thanks @Andrew_Wilson

can anyone confirm my guess?

I think I will try in the next few weeks to reinstall my base OS from scratch… and on bare metal re-attempt the macvlan bridge when outside of a VM… if it works I will be happy… if not well I at least can confirm that the issue is not my being in a vm …

I can confirm in fact the bare metal box I installed LXD on… never got IP’s from the DHCP router either… I was mistaken in my original assumption…