![如何解析 systemd-nspawn 容器?](https://linux22.com/image/201566/%E5%A6%82%E4%BD%95%E8%A7%A3%E6%9E%90%20systemd-nspawn%20%E5%AE%B9%E5%99%A8%EF%BC%9F.png)
我有一个 nspawn 容器:
root@nomad-02:~# machinectl list
MACHINE CLASS SERVICE OS VERSION ADDRESSES
debian container systemd-nspawn debian 11 192.168.88.171…
1 machines listed.
systemd-resolved.service
在主机上启动(也在容器中):
root@nomad-02:~# systemctl status systemd-resolved.service
● systemd-resolved.service - Network Name Resolution
Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-01-25 22:16:34 UTC; 12h ago
Docs: man:systemd-resolved.service(8)
man:org.freedesktop.resolve1(5)
https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
Main PID: 232128 (systemd-resolve)
Status: "Processing requests..."
Tasks: 1 (limit: 1132)
Memory: 5.3M
CPU: 153ms
CGroup: /system.slice/systemd-resolved.service
└─232128 /lib/systemd/systemd-resolved
Jan 25 22:16:34 nomad-02 systemd[1]: Starting Network Name Resolution...
Jan 25 22:16:34 nomad-02 systemd-resolved[232128]: Positive Trust Anchors:
Jan 25 22:16:34 nomad-02 systemd-resolved[232128]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Jan 25 22:16:34 nomad-02 systemd-resolved[232128]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.>
Jan 25 22:16:34 nomad-02 systemd-resolved[232128]: Using system hostname 'nomad-02'.
Jan 25 22:16:34 nomad-02 systemd[1]: Started Network Name Resolution.
容器有一个 vnet:
root@nomad-02:~# resolvectl status
Global
Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign
...
Link 439 (ve-debian)
Current Scopes: LLMNR/IPv4 LLMNR/IPv6
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
我想知道是否可以使用主机名从主机内部访问容器。
我尝试的是:
dig @127.0.0.53 debian
这是行不通的。
我找不到任何有关如何执行此操作的文档。有可能做到吗?
提前致谢。
答案1
您需要 NSS(名称服务开关,请参阅man 5 nss
)模块”我的机器/etc/nsswitch.conf
“像这样安装并启用(请参阅man 8 nss-mymachines
):
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
libnss-mymachines
例如,在 Debian 上,您需要该软件包。