Setting up container with multiple network interfaces of differernt types

I am trying to set up a container with two interfaces:
1: eth0 based on the default, lxdbr0 to allow internet connection which is available via wifi
2: eth1 based on macvlan

eth0 is behaving as expected but eth1’s ip is not coming up.
Notes:

  1. When I set up a new container with macvlan only on eth0, an ip address is assigned and containers in host 1 and host 2 can ping each other.
  2. macvlan only works with ethernets. My ethernets are connected to a routher without internet connection. The router with internet connection does not have ethernet port to link supply internet connection to the other router (see diagram). But I must have internet connection to the containers for online installations and other fundumental functions.
  3. Also tried bridged network for eth1 but with similar results - no ip assiged to eth1.

Where am I going wrong(see my steps below)?..or is this setup valid(see diagram)?
The setup should be as below:

Below are the steps that I took:

# launch a1 with default with eth0 as a slave to lxdbr0
$ lxc launch ubuntu:22.04 a1
# stopped the container to setup eth1
$ lxc stop a1
# created the network macvlan-network
$ lxc network create macvlan-network --type=macvlan parent=br-enp0s31f6
# attached eth1 to a1
$ lxc network attach macvlan-network a1 eth1 eth1
# start the container
$ lxc start a1
# shell into a1, check the nics. No ip address assigned to eth1
$ lxc shell a1
root@a1:~# ip a
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
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
32: eth0@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:6b:93:c6 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.2.219/24 metric 100 brd 192.168.2.255 scope global dynamic eth0
       valid_lft 3447sec preferred_lft 3447sec
    inet6 fd42:98c5:aa08:d6b1:216:3eff:fe6b:93c6/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 3575sec preferred_lft 3575sec
    inet6 fe80::216:3eff:fe6b:93c6/64 scope link 
       valid_lft forever preferred_lft forever
34: eth1@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:b9:14:ed brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:feb9:14ed/64 scope link 
       valid_lft forever preferred_lft forever
root@a1:~#
1 Like

The LXD instance images only come with network configuration to perform DHCP/SLAAC on the eth0 interface (for containers) and enp5s0 interface (for VMs).

So when you add another interface called something different the automatic configuration won’t happen.

You either need to modify the instance’s network configuration manually so that it is either statically configured or performs DHCP/SLAAC on the external network (although be ware in that case your instance could end up with 2 default gateways and problems will ensue).

Or you can use cloud-init config embedded with the LXD instance or profile configuration so that cloud-init within the instance will modify the network config as desired (if using an image from the ubuntu: remote one of the images: remote /cloud variant images that include cloud-init).

See https://linuxcontainers.org/lxd/docs/master/cloud-init/

Thanks @tomp for the eagerly awaited comment. I will see what I can do with cloud-init and update my results.

This is to confirm that @tomp comment is the way to go. This how to by @simos was also very useful in demonstrating the solution.

1 Like