Linux

suse 11sp3 - 無法 ping/解析自己的主機名

  • September 26, 2013

我有一個本地虛擬機(在本地安裝的 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.

我不想將主機名添加到 /etc/hosts 作為 127.0.0.1。理想情況下,我希望與 Windows 上的行為相同 - ping 您自己的主機名會解析為“真實”IP 地址(可能是眾多 IP 地址之一)。

/etc/resolve.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

該行為是預期的,名稱伺服器根據域名空間解析主機名。它與 /etc/hosts 的工作方式無關。

思考如下:

當您執行 ping suse11 時,首先嘗試使用 /etc/hosts 進行解析,因為 suse11 不存在,然後嘗試使用名稱伺服器 192.168.19.2,但請注意 /etc/resolv.conf 中的“搜尋本地域”以便附加到“查詢”,所以 192.168.19.2 嘗試解析 suse11.localdomain,這樣的域在公共名稱空間中不存在。

ping 不是測試主機解析度的工具,也不是為此而設計的。

您可以使用真正的 DNS 查找工具看到更好的結果,例如:

挖@ 192.168.19.2 suse11

高溫高壓

引用自:https://serverfault.com/questions/540810