【LXD】【Ubuntu】LXD の導入と Network 構成変更 (Linux Bridge)

Ubuntu Desktop 24.04 に Canonical LXD の導入を行い、コンテナインスタンスを作成する。
また、コンテナの Network 構成変更を行う。
※ Ubuntu Server 版ではデフォルトで LXD インストール済み

lxdbr0 (NAPT)
Host の wlp6s0 に接続(WiFi 接続)
10.0.16.0/24
fd00:0:a:10::/64
bridge0 (Linux Bridge)
Host の enx0 に接続 (有線接続)
192.168.0.0/24
fd00::/64

LXD のインストール (Ubuntu Desktop 版)

【snap】を利用してインストールを行う。インストール後は【lxd】グループに操作ユーザーを追加して再起動を実施する。

$ sudo snap install lxd

$ id lxd
uid=997(lxd) gid=123(lxd) groups=123(lxd)

$ sudo gpasswd -a penguin lxd
Adding user penguin to group lxd

$ sudo reboot

$ getent group lxd
lxd:x:123:penguin

$ lxc version
Client version: 6.3
Server version: 6.3

LXD の初期設定

初期設定を行う。基本的にはデフォルト設定、外部から Web GUI で管理するために一部設定を変更する。

$ sudo lxd init
[sudo] password for penguin:
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (lvm, powerflex, zfs, btrfs, ceph, dir) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:
Size in GiB of the new loop device (1GiB minimum) [default=30GiB]:
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like the LXD server to be available over the network? (yes/no) [default=no]: yes
Address to bind LXD to (not including port) [default=all]:
Port to bind LXD to [default=8443]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes
config:
  core.https_address: '[::]:8443'
networks:
- config:
    ipv4.address: auto
    ipv6.address: auto
  description: ""
  name: lxdbr0
  type: ""
  project: default
storage_pools:
- config:
    size: 30GiB
  description: ""
  name: default
  driver: zfs
storage_volumes: []
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      network: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
projects: []
cluster: null

UFW の通信許可設定

【UFW】で Host の通信制御している場合は Web GUI にアクセス出来るように許可設定が必要。また、コンテナ Network の各ブリッジ【lxdbr0】からのルーティング許可設定を行う。

$ sudo ufw allow in on wlp6s0 from 192.168.0.0/16 to 192.168.1.0/24 proto tcp port 8443
$ sudo ufw allow in on wlp6s0 from fd00::/8 to fd00:0:0:1::/64 proto tcp port 8443

$ sudo ufw route allow in on lxdbr0 from 10.0.16.0/24 to any
Rule added
$ sudo ufw route allow in on lxdbr0 from fd00:0:0:a:10::/64 to any
Rule added (v6)

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
192.168.1.0/24 8443/tcp on wlp6s0 ALLOW       192.168.0.0/16
fd00:0:0:1::/64 8443/tcp on wlp6s0 ALLOW       fd00::/8

Anywhere                   ALLOW FWD   10.0.16.0/24 on lxdbr0
Anywhere (v6)              ALLOW FWD   fd00:0:0:a:10::/64 on lxdbr0

Host Network の構成変更

Network セグメントの変更

【lxdbr0】のアドレスを初期値から変更する。また、コンテナ・VM に対して IPv6 の DHCPv6 アサインを固定化できる様に【ipv6.dhcp.stateful】を有効にする。

$ lxc network show lxdbr0
name: lxdbr0
description: ""
type: bridge
managed: true
status: Created
config:
  ipv4.address: 10.214.155.1/24
  ipv4.nat: "true"
  ipv6.address: fd42:295e:ec47:5fd2::1/64
  ipv6.nat: "true"
used_by:
- /1.0/profiles/default
locations:
- none

$ lxc network set lxdbr0 ipv4.address=10.0.16.254/24
$ lxc network set lxdbr0 ipv6.address=fd00:0:a:10::fe/64
$ lxc network set lxdbr0 ipv6.dhcp.stateful=true

$ lxc network show lxdbr0
name: lxdbr0
description: ""
type: bridge
managed: true
status: Created
config:
  ipv4.address: 10.0.16.254/24
  ipv4.nat: "true"
  ipv6.address: fd00:0:a:10::fe/64
  ipv6.dhcp.stateful: "true"
  ipv6.nat: "true"
used_by:
- /1.0/profiles/default
locations:
- none

Linux Bridge の作成

ブリッジを LXD から作成すると、アップリンクの Host 側 NIC が再起動時に Network Manager 側の自動設定と衝突してエラーとなるため、 Host 側で Linux Bridge を作成する。(エラーは以下)

$ lxc warning show 7d58e6b0-f137-46da-aa8a-f635a2e51960
uuid: 7d58e6b0-f137-46da-aa8a-f635a2e51960
location: none
project: default
type: Network unavailable
count: 33
first_seen_at: 2025-03-23T06:50:14.485248847Z
last_seen_at: 2025-03-23T16:22:15.690249843+09:00
last_message: 'Failed starting: Only unconfigured network interfaces can be bridged'
severity: high
status: new
entity_url: /1.0/networks/lxdbr1?project=default

※参考までに LXD から作成した【lxdbr1】とアップリンク(Host 側 NIC)の設定は以下。

$ lxc network create lxdbr1
Network lxdbr1 created

$ lxc network set lxdbr1 ipv4.firewall=false ipv6.firewall=false
$ lxc network set lxdbr1 ipv4.address=none ipv4.nat=false
$ lxc network set lxdbr1 ipv6.address=none ipv6.nat=false
$ lxc network set lxdbr1 bridge.external_interfaces=enx0

$ lxc network show lxdbr1
name: lxdbr1
description: ""
type: bridge
managed: true
status: Created
config:
  bridge.external_interfaces: enx0
  ipv4.address: none
  ipv4.firewall: "false"
  ipv4.nat: "false"
  ipv6.address: none
  ipv6.firewall: "false"
  ipv6.nat: "false"
used_by: []
locations:
- none

Host OS の【Advanced Network Configuration】から、外部スイッチに接続する L2 ブリッジ【bridge0】を作成する。この時アップリンクの【enx0】を追加する。

GUI から作成後の設定は以下。
【bridge0】

$ sudo cat /etc/netplan/90-NM-f5697b65-a2bc-44be-a743-eee68ec5a7ab.yaml
[sudo] password for penguin:
network:
  version: 2
  bridges:
    bridge0:
      renderer: NetworkManager
      ipv6-address-generation: "stable-privacy"
      parameters:
        stp: false
      networkmanager:
        uuid: "f5697b65-a2bc-44be-a743-eee68ec5a7ab"
        name: "bridge0"
        passthrough:
          connection.timestamp: "1742717298"
          ethernet._: ""
          ipv4.method: "disabled"
          ipv6.method: "disabled"
          ipv6.ip6-privacy: "-1"
          proxy._: ""

【en0】

$ sudo cat /etc/netplan/90-NM-a65bd1ea-4163-4941-aca8-2ec3f4b0778c.yaml
network:
  version: 2
  ethernets:
    NM-a65bd1ea-4163-4941-aca8-2ec3f4b0778c:
      renderer: NetworkManager
      match:
        name: "enx0"
        macaddress: "**:**:**:**:**:**"
      wakeonlan: true
      networkmanager:
        uuid: "a65bd1ea-4163-4941-aca8-2ec3f4b0778c"
        name: "bridge0 enx0"
        passthrough:
          connection.controller: "bridge0"
          connection.master: "bridge0"
          connection.port-type: "bridge"
          connection.slave-type: "bridge"
          bridge-port._: ""

Host 側のネットワーク状態

$ ip address
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 noprefixroute
       valid_lft forever preferred_lft forever
2: enx0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bridge0 state UP group default qlen 1000
    link/ether **:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
3: wlp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether **:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.32/24 brd 192.168.1.255 scope global noprefixroute wlp6s0
       valid_lft forever preferred_lft forever
    inet6 fd00:0:0:1::20/64 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fe80::****:****:****:****/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
4: bridge0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 1e:44:5c:91:b9:29 brd ff:ff:ff:ff:ff:ff
5: lxdbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 00:16:3e:a5:a9:e3 brd ff:ff:ff:ff:ff:ff
    inet 10.0.16.254/24 scope global lxdbr0
       valid_lft forever preferred_lft forever
    inet6 fd00:0:a:10::fe/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fea5:a9e3/64 scope link
       valid_lft forever preferred_lft forever

Ubuntu 24.04 コンテナ

コンテナのインスタンス作成

【Ubuntu 24.04/amd64】のコンテナを作成する。
イメージレジストリ一覧は【lxc remote list】 で確認可能。
レジストリ内のイメージ一覧は【lxc image list ubuntu:】などで確認可能。

$ lxc remote list
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
|         NAME         |                        URL                        |   PROTOCOL    |  AUTH TYPE  | PUBLIC | STATIC | GLOBAL |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| images               | https://images.lxd.canonical.com                  | simplestreams | none        | YES    | NO     | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| local (current)      | unix://                                           | lxd           | file access | NO     | YES    | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu               | https://cloud-images.ubuntu.com/releases/         | simplestreams | none        | YES    | YES    | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu-daily         | https://cloud-images.ubuntu.com/daily/            | simplestreams | none        | YES    | YES    | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu-minimal       | https://cloud-images.ubuntu.com/minimal/releases/ | simplestreams | none        | YES    | YES    | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu-minimal-daily | https://cloud-images.ubuntu.com/minimal/daily/    | simplestreams | none        | YES    | YES    | NO     |
+----------------------+---------------------------------------------------+---------------+-------------+--------+--------+--------+
$ lxc image list ubuntu: 24.04/amd64
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+-----------+-------------------------------+
|   ALIAS    | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |      TYPE       |   SIZE    |          UPLOAD DATE          |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+-----------+-------------------------------+
| n (9 more) | 1e461e0e46d4 | yes    | ubuntu 24.04 LTS amd64 (release) (20250313) | x86_64       | VIRTUAL-MACHINE | 582.56MiB | Mar 13, 2025 at 12:00am (UTC) |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+-----------+-------------------------------+
| n (9 more) | 9203c53127ae | yes    | ubuntu 24.04 LTS amd64 (release) (20250313) | x86_64       | CONTAINER       | 256.60MiB | Mar 13, 2025 at 12:00am (UTC) |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+-----------+-------------------------------+

コンテナのインスタンス【ubuntu-01】を作成。プロファイルはデフォルトで作成。
【default】プロファイルにより【volatile.eth0.hwaddr】が作成される。

$ lxc init ubuntu:24.04/amd64 ubuntu-01 -p default
Creating ubuntu-01

$ lxc config show ubuntu-01
architecture: x86_64
config:
  image.architecture: amd64
  image.description: ubuntu 24.04 LTS amd64 (release) (20250313)
  image.label: release
  image.os: ubuntu
  image.release: noble
  image.serial: "20250313"
  image.type: squashfs
  image.version: "24.04"
  volatile.apply_template: create
  volatile.base_image: 9203c53127ae6b11280d9b94b1579ed71b9964a428bc724eed96212f9ca699fc
  volatile.cloud-init.instance-id: ae2ea8d6-654d-4264-9ab9-fad8ef899d1f
  volatile.eth0.hwaddr: 00:16:3e:0c:53:18
  volatile.idmap.base: "0"
  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: '[]'
  volatile.uuid: ebf03d97-9e4c-403a-909f-1b2626649835
  volatile.uuid.generation: ebf03d97-9e4c-403a-909f-1b2626649835
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

インスタンスの Network 設定

コンテナインスタンスの【eth0】の IP 設定(DHCP 固定アサイン)、及び【eth1】の追加を行う。
※ eth1 は Linux Bridge に接続しているため、 IP の設定はインスタンス内で設定を行う。

$ lxc network attach lxdbr0 ubuntu-01 eth0 en0
$ lxc network attach bridge0 ubuntu-01 eth1 en1
$ lxc config device set ubuntu-01 eth0 ipv4.address=10.0.16.1
$ lxc config device set ubuntu-01 eth0 ipv6.address=fd00:0:a:10::1

$ lxc config show ubuntu-01
architecture: x86_64
config:
  image.architecture: amd64
  image.description: ubuntu 24.04 LTS amd64 (release) (20250313)
  image.label: release
  image.os: ubuntu
  image.release: noble
  image.serial: "20250313"
  image.type: squashfs
  image.version: "24.04"
  volatile.apply_template: create
  volatile.base_image: 9203c53127ae6b11280d9b94b1579ed71b9964a428bc724eed96212f9ca699fc
  volatile.cloud-init.instance-id: bba50af8-b068-4f71-8f91-3c9e069586f2
  volatile.eth0.hwaddr: 00:16:3e:0c:53:18
  volatile.eth1.hwaddr: 00:16:3e:e9:29:d0
  volatile.idmap.base: "0"
  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: '[]'
  volatile.uuid: ebf03d97-9e4c-403a-909f-1b2626649835
  volatile.uuid.generation: ebf03d97-9e4c-403a-909f-1b2626649835
devices:
  eth0:
    ipv4.address: 10.0.16.1
    ipv6.address: fd00:0:a:10::1
    name: en0
    network: lxdbr0
    type: nic
  eth1:
    name: en1
    nictype: bridged
    parent: bridge0
    type: nic
ephemeral: false
profiles:
- default
stateful: false
description: ""

インスタンスの起動

インスタンス【ubuntu-01】を起動する。【eth0】側(en0)に DHCP で IP がアサインされる。

$ lxc list
+-----------+---------+------+------+-----------+-----------+
|   NAME    |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-----------+---------+------+------+-----------+-----------+
| ubuntu-01 | STOPPED |      |      | CONTAINER | 0         |
+-----------+---------+------+------+-----------+-----------+

$ lxc start ubuntu-01

$ lxc list
+-----------+---------+-----------------+----------------------+-----------+-----------+
|   NAME    |  STATE  |      IPV4       |         IPV6         |   TYPE    | SNAPSHOTS |
+-----------+---------+-----------------+----------------------+-----------+-----------+
| ubuntu-01 | RUNNING | 10.0.16.1 (en0) | fd00:0:a:10::1 (en0) | CONTAINER | 0         |
+-----------+---------+-----------------+----------------------+-----------+-----------+

インスタンス内での Network 設定

シェルを実行し、インスタンス内部にアクセスする。
netplan より【eth1】側(en1)の IP アドレスを設定する。

$ lxc shell ubuntu-01
root@ubuntu-01:~# ip address
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: en0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:0c:53:18 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.0.16.1/24 metric 100 brd 10.0.16.255 scope global dynamic en0
       valid_lft 3188sec preferred_lft 3188sec
    inet6 fd00:0:a:10::1/128 scope global dynamic noprefixroute
       valid_lft 3189sec preferred_lft 3189sec
    inet6 fe80::216:3eff:fe0c:5318/64 scope link
       valid_lft forever preferred_lft forever
12: en1@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:e9:29:d0 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:fee9:29d0/64 scope link
       valid_lft forever preferred_lft forever

root@ubuntu-01:~# ll /etc/netplan/
total 9
drwxr-xr-x   2 root root   3 Mar 22 16:38 ./
drwxr-xr-x 104 root root 196 Mar 22 16:38 ../
-rw-------   1 root root  62 Mar 22 16:38 50-cloud-init.yaml
root@ubuntu-01:~# cat <<EOF > /etc/netplan/51-en1.yaml
> network:
  version: 2
  ethernets:
    en1:
      dhcp4: false
      dhcp6: false
      accept-ra: false
      addresses:
        - 192.168.0.11/24
        - fd00::b/64
      routes:
        - to: 192.168.0.0/16
          via: 192.168.0.254
        - to: fd00::/8
          via: fd00::fe
      nameservers:
        addresses:
          - 192.168.0.254
          - fd00::fe
        search:
          - net.home
> EOF

root@ubuntu-01:~# chmod 600 /etc/netplan/51-en1.yaml
root@ubuntu-01:~# netplan apply
root@ubuntu-01:~# ip address
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: en0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:0c:53:18 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.0.16.1/24 metric 100 brd 10.0.16.255 scope global dynamic en0
       valid_lft 3596sec preferred_lft 3596sec
    inet6 fd00:0:a:10::1/128 scope global dynamic noprefixroute
       valid_lft 3597sec preferred_lft 3597sec
    inet6 fe80::216:3eff:fe0c:5318/64 scope link
       valid_lft forever preferred_lft forever
12: en1@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:e9:29:d0 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.0.11/24 brd 192.168.0.255 scope global en1
       valid_lft forever preferred_lft forever
    inet6 fd00::b/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fee9:29d0/64 scope link
       valid_lft forever preferred_lft forever

root@ubuntu-01:~# ip route show
default via 10.0.16.254 dev en0 proto dhcp src 10.0.16.1 metric 100
10.0.16.0/24 dev en0 proto kernel scope link src 10.0.16.1 metric 100
10.0.16.254 dev en0 proto dhcp scope link src 10.0.16.1 metric 100
192.168.0.0/24 dev en1 proto kernel scope link src 192.168.0.11
192.168.0.0/16 via 192.168.0.254 dev en1 proto static

root@ubuntu-01:~# ip -6 route show
fd00::/64 dev en1 proto kernel metric 256 pref medium
fd00:0:a:10::/64 dev en0 proto ra metric 100 expires 3486sec mtu 1500 hoplimit 64 pref medium
fd00:0:a:10::/64 dev en0 proto kernel metric 256 expires 2712sec pref medium
fd00::/8 via fd00::fe dev en1 proto static metric 1024 pref medium
fe80::/64 dev en0 proto kernel metric 256 pref medium
fe80::/64 dev en1 proto kernel metric 256 pref medium
default via fe80::216:3eff:fea5:a9e3 dev en0 proto ra metric 100 expires 1686sec mtu 1500 hoplimit 64 pref medium

root@ubuntu-01:~# resolvectl
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 6 (en0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
       DNS Servers: 10.0.16.254 fd00:0:a:10::fe fe80::216:3eff:fea5:a9e3
        DNS Domain: lxd

Link 8 (en1)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
       DNS Servers: 192.168.0.254 fd00::fe
        DNS Domain: net.home

インスタンスからの疎通確認

NIC-1【en0】インターネット側の疎通確認。

root@ubuntu-01:~# ping www.google.com -c 3
PING www.google.com (172.217.175.228) 56(84) bytes of data.
64 bytes from www.google.com (172.217.175.228): icmp_seq=2 ttl=53 time=102 ms
64 bytes from www.google.com (172.217.175.228): icmp_seq=3 ttl=53 time=74.7 ms

--- www.google.com ping statistics ---
3 packets transmitted, 2 received, 33.3333% packet loss, time 2026ms
rtt min/avg/max/mdev = 74.749/88.457/102.165/13.708 ms

root@ubuntu-01:~# ping6 www.google.com -c 3
PING www.google.com (2404:6800:4004:828::2004) 56 data bytes
64 bytes from www.google.com (2404:6800:4004:828::2004): icmp_seq=1 ttl=53 time=79.2 ms
64 bytes from www.google.com (2404:6800:4004:828::2004): icmp_seq=2 ttl=53 time=73.2 ms
64 bytes from www.google.com (2404:6800:4004:828::2004): icmp_seq=3 ttl=53 time=93.9 ms

--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 73.180/82.090/93.912/8.710 ms

root@ubuntu-01:~# tracepath www.google.com -4 -m 5
 1?: [LOCALHOST]                      pmtu 1500
 1:  _gateway.lxd                                          0.079ms
 1:  _gateway.lxd                                          0.202ms
 2:  _gateway                                              4.630ms
 3:  vyos-m01.mgt.net.home                                 6.471ms
 4:  172.20.10.1                                          13.661ms
 5:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500

root@ubuntu-01:~# tracepath www.google.com -6 -m 5
 1?: [LOCALHOST]                        0.021ms pmtu 1500
 1:  _gateway.lxd                                          0.121ms
 1:  _gateway.lxd                                          0.058ms
 2:  _gateway                                              4.521ms
 3:  vyos-m01.mgt.net.home                                 5.016ms
 4:  vyos-m01.mgt.net.home                                 4.927ms pmtu 1440
 4:  ???                                                   8.655ms
 5:  ???                                                  67.237ms asymm  6
     Too many hops: pmtu 1440
     Resume: pmtu 1440

NIC-2【en1】LAN 側の疎通

root@ubuntu-01:~# ping 192.168.254.254 -c 3
PING 192.168.254.254 (192.168.254.254) 56(84) bytes of data.
64 bytes from 192.168.254.254: icmp_seq=1 ttl=63 time=1.88 ms
64 bytes from 192.168.254.254: icmp_seq=2 ttl=63 time=1.86 ms
64 bytes from 192.168.254.254: icmp_seq=3 ttl=63 time=1.89 ms

--- 192.168.254.254 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.862/1.877/1.893/0.012 ms

root@ubuntu-01:~# ping6 fd00:0:0:fe::fe -c 3
PING fd00:0:0:fe::fe (fd00:0:0:fe::fe) 56 data bytes
64 bytes from fd00:0:0:fe::fe: icmp_seq=1 ttl=63 time=1.71 ms
64 bytes from fd00:0:0:fe::fe: icmp_seq=2 ttl=63 time=1.88 ms
64 bytes from fd00:0:0:fe::fe: icmp_seq=3 ttl=63 time=1.97 ms

--- fd00:0:0:fe::fe ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.706/1.853/1.971/0.110 ms

root@ubuntu-01:~# tracepath 192.168.254.254 -4 -nm 5
 1?: [LOCALHOST]                      pmtu 1500
 1:  192.168.0.254                                         1.434ms
 1:  192.168.0.254                                         1.405ms
 2:  192.168.254.254                                       5.479ms reached
     Resume: pmtu 1500 hops 2 back 2

root@ubuntu-01:~# tracepath fd00:0:0:fe::fe -6 -nm 5
 1?: [LOCALHOST]                        0.014ms pmtu 1500
 1:  fd00::fe                                              1.435ms
 1:  fd00::fe                                              1.525ms
 2:  fd00:0:0:fe::fe                                       2.371ms reached
     Resume: pmtu 1500 hops 2 back 2

インスタンスの停止

インスタンス内からシャットダウンしても良いが、一旦 Host 側に戻ってから停止する。

$ lxc list
+-----------+---------+--------------------+----------------------+-----------+-----------+
|   NAME    |  STATE  |        IPV4        |         IPV6         |   TYPE    | SNAPSHOTS |
+-----------+---------+--------------------+----------------------+-----------+-----------+
| ubuntu-01 | RUNNING | 192.168.0.11 (en1) | fd00::b (en1)        | CONTAINER | 0         |
|           |         | 10.0.16.1 (en0)    | fd00:0:a:10::1 (en0) |           |           |
+-----------+---------+--------------------+----------------------+-----------+-----------+

$ lxc stop ubuntu-01
$ lxc list
+-----------+---------+------+------+-----------+-----------+
|   NAME    |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-----------+---------+------+------+-----------+-----------+
| ubuntu-01 | STOPPED |      |      | CONTAINER | 0         |
+-----------+---------+------+------+-----------+-----------+

コンテナイメージの作成

上記で設定したインスタンスイメージからコンテナイメージを作成し、必要に応じて再利用可能にする。

$ lxc publish ubuntu-01 --alias ubuntu-custom
Instance published with fingerprint: 9e3e1955f9899726d65c15f73e14e971d210e4aad0b921d17ef769f47a9560ae

$ lxc image list local:
+---------------+--------------+--------+---------------------------------------------+--------------+-----------+------------+-------------------------------+
|     ALIAS     | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |   TYPE    |    SIZE    |          UPLOAD DATE          |
+---------------+--------------+--------+---------------------------------------------+--------------+-----------+------------+-------------------------------+
| ubuntu-custom | 9e3e1955f989 | no     | Ubuntu 24.04 LTS server (20250313)          | x86_64       | CONTAINER | 549.06MiB  | Mar 23, 2025 at 10:09am (UTC) |
+---------------+--------------+--------+---------------------------------------------+--------------+-----------+------------+-------------------------------+
|               | 9203c53127ae | no     | ubuntu 24.04 LTS amd64 (release) (20250313) | x86_64       | CONTAINER | 256.60MiB  | Mar 20, 2025 at 3:22pm (UTC)  |
+---------------+--------------+--------+---------------------------------------------+--------------+-----------+------------+-------------------------------+

先程のインスタンスを削除し、新たにインスタンスを作成する。この時、デバイスの追加が再度必要となる。起動後に IP が自動で設定されることを確認する。

$ lxc delete ubuntu-01

$ lxc init local:ubuntu-custom ubuntu-02
Creating ubuntu-02

$ lxc network attach lxdbr0 ubuntu-02 eth0 en0
$ lxc network attach bridge0 ubuntu-02 eth1 en1
$ lxc start ubuntu-02

$ lxc list
+-----------+---------+--------------------+---------------------------------------+-----------+-----------+
|   NAME    |  STATE  |        IPV4        |                 IPV6                  |   TYPE    | SNAPSHOTS |
+-----------+---------+--------------------+---------------------------------------+-----------+-----------+
| ubuntu-02 | RUNNING | 192.168.0.11 (en1) | fd00::b (en1)                         | CONTAINER | 0         |
|           |         | 10.0.16.167 (en0)  | fd00:0:a:10:71ba:e9a0:5d7b:4fb9 (en0) |           |           |
+-----------+---------+--------------------+---------------------------------------+-----------+-----------+

$ lxc config show ubuntu-02
architecture: x86_64
config:
  image.architecture: x86_64
  image.description: Ubuntu 24.04 LTS server (20250313)
  image.os: ubuntu
  image.release: noble
  volatile.base_image: 9e3e1955f9899726d65c15f73e14e971d210e4aad0b921d17ef769f47a9560ae
  volatile.cloud-init.instance-id: b853c86b-362f-46f0-8b0c-405873b1740e
  volatile.eth0.host_name: veth94d8bb43
  volatile.eth0.hwaddr: 00:16:3e:ee:8e:ba
  volatile.eth1.host_name: vethdf1a2a65
  volatile.eth1.hwaddr: 00:16:3e:ca:b4:0a
  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: '[]'
  volatile.last_state.power: RUNNING
  volatile.uuid: 886655eb-e470-4323-9b40-12d1ca48e2bc
  volatile.uuid.generation: 886655eb-e470-4323-9b40-12d1ca48e2bc
devices:
  eth0:
    name: en0
    network: lxdbr0
    type: nic
  eth1:
    name: en1
    nictype: bridged
    parent: bridge0
    type: nic
ephemeral: false
profiles:
- default
stateful: false
description: ""
$ lxc exec ubuntu-02 -- ip address
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: en0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:ee:8e:ba brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.0.16.167/24 metric 100 brd 10.0.16.255 scope global dynamic en0
       valid_lft 3357sec preferred_lft 3357sec
    inet6 fd00:0:a:10:71ba:e9a0:5d7b:4fb9/128 scope global dynamic noprefixroute
       valid_lft 3358sec preferred_lft 3358sec
    inet6 fe80::216:3eff:feee:8eba/64 scope link
       valid_lft forever preferred_lft forever
12: en1@if13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:ca:b4:0a brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.0.11/24 brd 192.168.0.255 scope global en1
       valid_lft forever preferred_lft forever
    inet6 fd00::b/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:feca:b40a/64 scope link
       valid_lft forever preferred_lft forever

$ lxc exec ubuntu-02 -- cat /etc/netplan/51-en1.yaml
network:
  version: 2
  ethernets:
    en1:
      dhcp4: false
      dhcp6: false
      accept-ra: false
      addresses:
        - 192.168.0.11/24
        - fd00::b/64
      routes:
        - to: 192.168.0.0/16
          via: 192.168.0.254
        - to: fd00::/8
          via: fd00::fe
      nameservers:
        addresses:
          - 192.168.0.254
          - fd00::fe
        search:
          - net.home

参考URL
Canonical LXD Docs
LXC/LXDコンテナのネットワーク設定方法