我有一个本地虚拟机(在本地安装的 vmware 工作站上运行,网络设置为 NAT),其上安装了 suse enterprise 11 sp3。
该机器设置为使用 dhcp(来自 vmware)获取 ip 地址,并且这有效 - 至少我有互联网连接。
问题是它无法解析自己的主机名:
suse11:~ # hostname
suse11
suse11:~ # ping suse11
ping: unknown host suse11
suse11:~ # ping www.google.com
PING www.google.com (74.125.131.99) 56(84) bytes of data.
我不想将主机名 127.0.0.1 添加到 /etc/hosts。理想情况下,我希望与在 Windows 上的行为相同 - ping 您自己的主机名会解析为“真实”IP 地址(可能是众多地址之一)。
/etc/resolv.conf:
### /etc/resolv.conf file autogenerated by netconfig!
#
# Before you change this file manually, consider to define the
# static DNS configuration using the following variables in the
# /etc/sysconfig/network/config file:
# NETCONFIG_DNS_STATIC_SEARCHLIST
# NETCONFIG_DNS_STATIC_SERVERS
# NETCONFIG_DNS_FORWARDER
# or disable DNS configuration updates via netconfig by setting:
# NETCONFIG_DNS_POLICY=''
#
# See also the netconfig(8) manual page and other documentation.
#
# Note: Manual change of this file disables netconfig too, but
# may get lost when this file contains comments or empty lines
# only, the netconfig settings are same with settings in this
# file and in case of a "netconfig update -f" call.
#
### Please remove (at least) this line when you modify the file!
search localdomain
nameserver 192.168.19.2
/etc/nsswitch.conf:
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
# compat Use compatibility setup
# nisplus Use NIS+ (NIS version 3)
# nis Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# [NOTFOUND=return] Stop searching if not found so far
#
# For more information, please read the nsswitch.conf.5 manual page.
#
# passwd: files nis
# shadow: files nis
# group: files nis
passwd: compat
group: compat
hosts: files dns
networks: files dns
services: files
protocols: files
rpc: files
ethers: files
netmasks: files
netgroup: files nis
publickey: files
bootparams: files
automount: files nis
aliases: files
答案1
这是预期的行为,名称服务器根据域名空间解析主机名。它与 /etc/hosts 的工作方式无关。
思考如下:
当您运行 ping suse11 时,首先尝试使用 /etc/hosts 进行解析,因为 suse11 不存在,然后尝试使用名称服务器 192.168.19.2,但请注意 /etc/resolv.conf 中的“search localdomain”,以便将其附加到“query”,因此 192.168.19.2 尝试解析 suse11.localdomain,这样的域在公共名称空间中不存在。
ping 不是用于测试主机解析的工具,不适用于此。
您可以使用真正的 DNS 查找工具来更好地查看,例如:
挖@192.168.19.2 suse11
高血压
答案2
当您加入 Windows 域时,PDC 中集成的 dhcp 服务会在 Windows DNS 服务中添加一条 DNS A 记录,因此您可以在 Windows 域网络中解析 Windows PC