resolvconf 与 dnsmasq 和 lxd 结合使用

resolvconf 与 dnsmasq 和 lxd 结合使用

问:如何以编程方式为基于 lxd 的 dnsmasq 添加持久 resolvconf 条目?

我有一个非常基础的 Ubuntu 16.04 服务器安装。

我已经安装并配置了 lxd 并创建了一个容器。

lxd lxd/bridge-domain   string  lxd
# lxcbr0 is being replaced by lxdbr0
lxd lxd/bridge-upgrade-warning  note    
lxd lxd/bridge-ipv6-address string  fd6d:c772:b128:ebfd::1
lxd lxd/bridge-ipv6-netmask string  64
# Choices: gnome, kde, xfce, lxde, cinnamon, mate
lxd lxd/bridge-empty-error  note    
lxd lxd/bridge-ipv6-nat boolean true
lxd lxd/bridge-name string  lxdbr0
lxd lxd/bridge-ipv4-netmask string  24
lxd lxd/bridge-ipv4 boolean true
lxd lxd/bridge-dnsmasq  string  
lxd lxd/bridge-ipv6 boolean true
lxd lxd/use-existing-bridge boolean false
lxd lxd/bridge-ipv4-dhcp-first  string  10.41.63.2
lxd lxd/bridge-ipv4-dhcp-leases string  252
lxd lxd/bridge-random-warning   note    
lxd lxd/bridge-ipv4-dhcp-last   string  10.41.63.254
lxd lxd/bridge-http-proxy   boolean false
lxd lxd/setup-bridge    boolean true
lxd lxd/bridge-ipv4-nat boolean true
lxd lxd/update-profile  boolean true
lxd lxd/bridge-ipv4-address string  10.41.63.1

正在运行的容器:

+-------+---------+--------------------+-----------------------------------------------+------------+-----------+
| NAME  |  STATE  |        IPV4        |                     IPV6                      |    TYPE    | SNAPSHOTS |
+-------+---------+--------------------+-----------------------------------------------+------------+-----------+
| first | RUNNING | 10.41.63.27 (eth0) | fd6d:c772:b128:ebfd:216:3eff:fea7:69c6 (eth0) | PERSISTENT | 0         |
+-------+---------+--------------------+-----------------------------------------------+------------+-----------+

LXD 流程:

root       886     1  0 11:28 ?        00:00:00 /usr/bin/lxcfs /var/lib/lxcfs/
lxd       4129     1  0 13:04 ?        00:00:00 dnsmasq -s lxd -S /lxd/ -u lxd --strict-order --bind-interfaces --pid-file=/run/lxd-bridge//dnsmasq.pid --dhcp-no-override --except-interface=lo --interface=lxdbr0 --dhcp-leasefile=/var/lib/lxd-bridge//dnsmasq.lxdbr0.leases --dhcp-authoritative --listen-address 10.41.63.1 --dhcp-range 10.41.63.2,10.41.63.254 --dhcp-lease-max=252 --dhcp-range=fd6d:c772:b128:ebfd::1,ra-only --listen-address fd6d:c772:b128:ebfd::1
root      4146     1  0 13:04 ?        00:00:18 /usr/bin/lxd --group lxd --logfile=/var/log/lxd/lxd.log
root      4209     1  0 13:05 ?        00:00:00 [lxc monitor] /var/lib/lxd/containers first

但是,查找容器名称没有返回任何内容:

# dig first @10.41.63.1
...
first.          0   IN  A   10.41.63.27
...

同样,由于 lxd 配置:

# dig first.lxd @10.41.63.1
...
first.lxd.          0   IN  A   10.41.63.27
...

这是因为:

# lsof -i :53
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dnsmasq 4129  lxd    7u  IPv4  27561      0t0  UDP 10.41.63.1:domain 
dnsmasq 4129  lxd    8u  IPv4  27562      0t0  TCP 10.41.63.1:domain (LISTEN)
...

ifconfig 报告:

eno1      Link encap:Ethernet  HWaddr b8:ae:ed:ea:69:41  
          inet addr:192.168.0.3  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::baae:edff:feea:6941/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:116948 errors:0 dropped:3 overruns:0 frame:0
          TX packets:59726 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:161031770 (161.0 MB)  TX bytes:4656462 (4.6 MB)
          Interrupt:16 Memory:df100000-df120000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:177 errors:0 dropped:0 overruns:0 frame:0
          TX packets:177 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:13388 (13.3 KB)  TX bytes:13388 (13.3 KB)

lxdbr0    Link encap:Ethernet  HWaddr fe:5c:57:cd:bd:72  
          inet addr:10.41.63.1  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fd6d:c772:b128:ebfd::1/64 Scope:Global
          inet6 addr: fe80::d08c:f9ff:fed9:5cd1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5064 (5.0 KB)  TX bytes:11128 (11.1 KB)

vethD7L5U9 Link encap:Ethernet  HWaddr fe:5c:57:cd:bd:72  
          inet6 addr: fe80::fc5c:57ff:fecd:bd72/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:75 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5610 (5.6 KB)  TX bytes:10322 (10.3 KB)

当我启动我的第一个容器时,这座桥就出现了。

resolve.conf 包含:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.1

... 因为没有安装 NetworkManager 和 dnsmasq 包(这没问题)

最后,网络接口文件包含:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eno1
iface eno1 inet static
    address 192.168.0.3
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 192.168.0.1

另外,重要的一点,我正在使用 ansible 来管理这一切。

当然,如果我手动添加适当的名称服务器,它就会起作用。

nameserver 10.41.63.1
nameserver 192.168.0.1

如果反过来,则不会像预期的那样。

同样,它无法在 resolvconf -u 或重启后继续存在。

卸载 resolvconf 感觉失败了。

创建 /etc/resolvconf/resolv.conf.d/tail 显然不起作用

底座和头部看起来像是拼凑起来的

深入到 init.d 的中间,感觉太过沮丧和肮脏。

我正在寻找一种方法,它可以连接到桥的上行或下行,我至少可以尝试 resolvconf -a,即使我不确定它是否会按照正确的顺序获取它。

那就是问题所在。

更新:事实上,我需要的是:

echo "nameserver 10.41.63.1" | resolvconf -a lo.dnsmasq

resolv.conf 现在变成:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.41.63.1
nameserver 192.168.0.1

这正是我所需要的。

那么,这个钩子在哪里可以实例化桥呢?

答案1

您可以在 loopback* 接口上配置 DNS 名称服务器。这些名称服务器将始终列出。以下内容应保留列出的名称服务器。

# The loopback network interface
auto lo
iface lo inet loopback
    dns-nameservers 192.168.0.1

相关内容