Setting a static IP address using network bridge

root@c2:~# 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
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:de:5a:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.177.108.109/24 brd 10.177.108.255 scope global dynamic eth0
       valid_lft 3468sec preferred_lft 3468sec
    inet6 fd42:6507:3321:8a12:216:3eff:fede:5a06/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 3541sec preferred_lft 3541sec
    inet6 fe80::216:3eff:fede:5a06/64 scope link 
       valid_lft forever preferred_lft forever
12: eth1@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:c3:c3:2b brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:fec3:c32b/64 scope link 
       valid_lft forever preferred_lft forever
root@c2:~# ip r
default via 10.177.108.1 dev eth0 proto dhcp src 10.177.108.109 metric 100 
10.177.108.0/24 dev eth0 proto kernel scope link src 10.177.108.109 
10.177.108.1 dev eth0 proto dhcp scope link src 10.177.108.109 metric 100 
jsharief@desktop:~$ lxc info c2
Name: c2
Location: none
Remote: unix://
Architecture: x86_64
Created: 2021/05/11 17:04 UTC
Status: Running
Type: container
Profiles: default, multi
Pid: 3025
Ips:
  eth0:	inet	10.177.108.109	veth050f084e
  eth0:	inet6	fd42:6507:3321:8a12:216:3eff:fede:5a06	veth050f084e
  eth0:	inet6	fe80::216:3eff:fede:5a06	veth050f084e
  eth1:	inet6	fe80::216:3eff:fec3:c32b	wlx28ee52172bcc
  lo:	inet	127.0.0.1
  lo:	inet6	::1
Resources:
  Processes: 14
  Disk usage:
    root: 591.11MB
  CPU usage:
    CPU usage (in seconds): 2
  Memory usage:
    Memory (current): 234.11MB
    Memory (peak): 245.35MB
  Network usage:
    eth0:
      Bytes received: 9.13kB
      Bytes sent: 3.56kB
      Packets received: 74
      Packets sent: 36
    eth1:
      Bytes received: 75.92kB
      Bytes sent: 1.92kB
      Packets received: 293
      Packets sent: 22
    lo:
      Bytes received: 0B
      Bytes sent: 0B
      Packets received: 0
      Packets sent: 0

Please show output of lxc config show c2 --expanded (as lxc info c2 pretty much just shows the same output as ip a)

jsharief@desktop:~$ lxc config show c2 --expanded
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Ubuntu hirsute amd64 (20210511_07:42)
  image.os: Ubuntu
  image.release: hirsute
  image.serial: "20210511_07:42"
  image.type: squashfs
  image.variant: default
  limits.cpu: "1"
  limits.memory: 1GB
  volatile.base_image: b1d41f89b9c522048b01ee89b553da39d8eda9f344b6e86049532f02792c265f
  volatile.eth0.host_name: veth050f084e
  volatile.eth0.hwaddr: 00:16:3e:de:5a:06
  volatile.eth1.host_name: macd49f488d
  volatile.eth1.hwaddr: 00:16:3e:c3:c3:2b
  volatile.eth1.last_state.created: "false"
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.power: RUNNING
  volatile.uuid: f8025666-7172-4503-bc50-87b84a2f455e
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  eth1:
    name: eth1
    nictype: macvlan
    parent: wlx28ee52172bcc
    type: nic
  root:
    path: /
    pool: default
    size: 5GB
    type: disk
ephemeral: false
profiles:
- default
- multi
stateful: false
description: ""

OK thanks.

So the LXD images by default are configured to have eth0 use DHCP (you can see that by looking at /etc/netplan/10-lxc.yaml:

lxc exec c1 -- cat /etc/netplan/10-lxc.yaml 
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      dhcp-identifier: mac

So when your eth0 NIC device is connected to the LXD managed lxdbr0, it will get a private address from that bridge via DHCP.

When you attach another NIC, in this case eth1 as a macvlan connected to your wlx28ee52172bcc interface, the container doesn’t have any automatic configuration, so nothing happens (apart from the IPv6 link local addressing).

So you need to modify your container’s network config inside the container (in this case modifying /etc/netplan/10-lxc.yaml ) to do what you want to do, be it a statically assigned IP or to use DHCP, the same way you would with a real computer. You can also do this configuration automatically using cloud-init (which LXD supports passing config to).

See https://netplan.io/examples/ for more info on using netplan.

Also, you will likely have problems getting macvlan to work with a wifi parent as the different MAC addresses will cause issues with wifi authentication.

Brilliant, thank you.

I copied the code eth0 block in the /etc/netplan/10-lxc.yaml

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      dhcp-identifier: mac
    eth1:
      dhcp4: true
      dhcp-identifier: mac

Restarted

jsharief@desktop:~$ lxc list
+-----------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
|   NAME    |  STATE  |         IPV4          |                     IPV6                      |   TYPE    | SNAPSHOTS |
+-----------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| c2        | RUNNING | 192.168.1.50 (eth1)   | fd42:6507:3321:8a12:216:3eff:fede:5a06 (eth0) | CONTAINER | 0         |
|           |         | 10.177.108.109 (eth0) |                                               |           |           |
1 Like

Great, although if you’re using DHCP on both interfaces, you’re likely to get conflicts with the default route as you’ll get one added on both.

I am not following, re the conflict as they are on different networks and different cards, does that count?

If the DHCP servers on the two separate networks both return a default route then the DHCP client inside your container will do one of two things:

  1. Setup the default route to the first or last DHCP request complete (this may be different each time you reboot).
  2. Setup two default routes via different networks, which means outgoing connections will randomly take different paths (and thus appear to come from different IPs).

Neither outcome will likely be desirable.

Can you show the output of ip r in the container now?

root@c2:~# ip r
default via 10.177.108.1 dev eth0 proto dhcp src 10.177.108.109 metric 100 
default via 192.168.1.1 dev eth1 proto dhcp src 192.168.1.50 metric 100 
10.177.108.0/24 dev eth0 proto kernel scope link src 10.177.108.109 
10.177.108.1 dev eth0 proto dhcp scope link src 10.177.108.109 metric 100 
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.50 
192.168.1.1 dev eth1 proto dhcp scope link src 192.168.1.50 metric 100 

Yeah, so you can see the two default routes out of each interface there, and the metric priority is the same, so I believe outbound connections will be load balanced over those two, meaning the lxdbr0 one will go through NAT and appear to be your LXD host, and the macvlan one will appear to be your container on the external network.