0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LXDでのDNS設定

Posted at

LinuxサーバのテストをするときにLXDをよく使っていますが、LXDのゲストをDNSで参照できた方が都合が良い場合があるのでその設定方法です。
参照した記事はこちらだったのですが、Ubuntu24.04ではちょっと違っていたので覚書です。
参照元
https://qiita.com/apatchk/items/65cd8b356f25233baa90

Ubuntu24.04ではsystemd-resolveが使用できないのでresolvctlを使います。

#!/bin/bash

set -eu

CONTAINER_NAME="$(lxc list -c n -f compact status=RUNNING | tail -1 | tr -d ' ')"
LXDBRIP="$(ip addr show dev lxdbr0| grep -Po 'inet \K[\d.]+')"
sudo resolvectl dns lxdbr0
sudo resolvectl domain lxdbr0 lxd
echo "auth-zone=lxd\nauth-server=${LXDBRIP}" | lxc network set lxdbr0 raw.dnsmasq -
lxc network show lxdbr0
echo "All done.. try command"
echo "dig ${CONTAINER_NAME}.lxd @${LXDBRIP}"

上記のシェルではDomain名がlxd、lxdが使っているブリッジがlxdbr0と言う
デフォルト値を前提としているので異なる場合変更の必要があります。
また、何か一つはコンテナが動いている(RUNNING)という前提です。

参考までに設定後の状態です。

$ lxc network show lxdbr0
name: lxdbr0
description: ""
type: bridge
managed: true
status: Created
config:
  ipv4.address: 10.81.243.1/24
  ipv4.nat: "true"
  ipv6.address: fd42:19f6:6c43:4ee5::1/64
  ipv6.nat: "true"
  raw.dnsmasq: |
    auth-zone=lxd
    auth-server=10.81.243.1
used_by:
- /1.0/instances/host1
- /1.0/instances/host3
- /1.0/profiles/default
locations:
- none

LXDのゲストにアクセスする場合lxc execコマンドでアクセスできますのでDNS参照してネットワーク経由でアクセスする必要はないんですが、必要になった時の覚書です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?