Debian 12/Bookworm 无头主机
我有一个运行 IP 为 10.88.0.2 的本地容器。我可以通过IP访问容器:
root@dev ~# ping -c2 10.88.0.2
PING 10.88.0.2 (10.88.0.2) 56(84) bytes of data.
64 bytes from 10.88.0.2: icmp_seq=1 ttl=64 time=0.088 ms
64 bytes from 10.88.0.2: icmp_seq=2 ttl=64 time=0.092 ms
--- 10.88.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1018ms
rtt min/avg/max/mdev = 0.088/0.090/0.092/0.002 ms
我还可以使用curl通过IP访问容器:
root@dev ~# curl --insecure 10.88.0.2
The provided host name is not valid for this server.
但根据该消息,我需要通过域名(在软件中配置为允许的域)而不是 IP 连接到容器。为了进行测试,我配置了一个假域名:fake.domain.com.au
.我已将其添加到我的/etc/hosts
文件中:
root@dev ~# grep fake.domain.com.au /etc/hosts
fake.domain.com.au 10.88.0.2
但是,我无法通过该域访问我的容器?!:
root@dev ~# ping -c2 fake.domain.com.au
ping: fake.domain.com.au: Name or service not known
root@dev ~# curl --insecure https://fake.domain.com.au
curl: (6) Could not resolve host: fake.domain.com.au
我到处寻找答案,但一无所获。根据我发现的其他线程,这里有一些进一步的信息:
root@dev ~# cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: files
group: files
shadow: files
gshadow: files
hosts: files dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
以防万一它很重要(IMO 不应该)我使用 resolvconf 作为 DNS(而不是 systemd-resolve):
root@dev ~# apt policy resolvconf systemd-resolved
resolvconf:
Installed: 1.91+nmu1
Candidate: 1.91+nmu1
Version table:
*** 1.91+nmu1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
100 /var/lib/dpkg/status
systemd-resolved:
Installed: (none)
Candidate: 252.12-1~deb12u1
Version table:
252.12-1~deb12u1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
我还发现了另一篇文章,似乎是类似的问题,显然重新启动就解决了它?!但重启后我的问题仍然存在:(
答案1
面掌
在写这个问题的过程中,我的问题所在变得显而易见。在该/etc/hosts
文件中,格式为:
IP_ADDRESS DOMAIN
我正在以相反的方式设置它......Doh!
最初我只是想结束这份草稿并隐藏我的耻辱。但也许它可以让其他人(显然也没有喝足够的咖啡)免于在同样的愚蠢错误上浪费大量时间。