0xC*_*22L 4 networking ubuntu dns hosts
我有一台 Ubuntu Server 12.04 ( amd64
) 机器,当我更改/etc/hosts
时,即使重新启动后也不会选择更改。我正在/usr/bin/host
用来测试,但其他程序似乎也没有找到它。
这是一个服务器,nscd
并dnsmasq
没有安装。此外,该文件/etc/nsswitch.conf
包含以下行:
hosts: files dns
Run Code Online (Sandbox Code Playgroud)
所以我希望它能够工作。我还检查mtime
了文件的更改是否随着编辑而变化,并尝试运行service networking restart
(排除万难)和resolvconf -u
.
所有命令都root
在需要的地方运行。机器在其中手动配置了网络,/etc/network/interfaces
而不是通过网络管理器(也未安装)。
基本上我想要实现的是可以操纵少数主机的IP。原因是在我们的网络内部,我获得了一个没有路由的 IP,但我可以通过 HTTPS 使用该服务的外部 IP。
我错过了什么?
注意:本地没有运行 DNS 服务器,并且 中的nameserver
行/etc/resolv.conf
(以及 中的相应行interfaces
)指向给我错误 IP 的 DNS 服务器。
另请注意:我在网上搜索并通读了“类似问题”,但似乎没有涵盖我的案例。
/etc/host.conf
是:
# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on
Run Code Online (Sandbox Code Playgroud)
host 命令不检查主机文件。从联机帮助页:
host is a simple utility for performing DNS lookups.
Run Code Online (Sandbox Code Playgroud)
如果您想在尊重主机文件的同时测试查找,请使用 ping 或 getent。
$ tail -1 /etc/hosts
127.0.0.1 google.com
$ ping -c1 google.com | head -1
PING google.com (127.0.0.1) 56(84) bytes of data.
$ getent ahosts google.com
127.0.0.1 STREAM google.com
127.0.0.1 DGRAM
127.0.0.1 RAW
Run Code Online (Sandbox Code Playgroud)