將 IP 數字轉換為名稱係方便記憶。實務上,IP 位址係用於辨識網路卡之類的網路介面設備。機器可能有多個網路卡,每個網路卡可能有多個介面,所以在網域名稱系統裡,一部電腦就可能有多個名稱。
Linux 的名稱解析機制是模組化的且可使用 /etc/nsswitch.conf 宣稱的資料來源。涉及主機名稱解析的款目是 hosts。預設,它包括 files dns,表示系統先參照 /etc/hosts 檔案,再參照 DNS 伺服器。NIS/NIS+ 或 LDAP 伺服器是另個來源選擇。
DNS (網域名稱服務) 是對映名稱至 IP 位址的分散式階層服務,同時也反向對映。尤其是,把人可閱讀的名稱,如 www.eyrolles.com 對映至實際的 IP 位址 213.244.11.247。
必須先設定 DNS 伺服器,才能用到 DNS 資訊。Falcot 公司自設該伺服器,但個人使用者可能使用 ISP 提供的 DNS 伺服器。
The DNS servers to be used are indicated in /etc/resolv.conf, one per line, with the nameserver keyword preceding an IP address, as in the following example:
nameserver 212.27.32.176
nameserver 212.27.32.177
nameserver 8.8.8.8
Note that the /etc/resolv.conf file may be handled automatically (and overwritten) when the network is managed by NetworkManager or configured via DHCP, or when resolvconf is installed or systemd-resolved(8) is enabled.
If there is no name server on the local network, it is still possible to establish a small table mapping IP addresses and machine hostnames in the /etc/hosts file, usually reserved for local network stations. The syntax of this file as described in hosts(5) is very simple: each line indicates a specific IP address followed by the list of any associated names (the first being “completely qualified”, meaning it includes the domain name).
即使網路停擺或 DNS 伺服器不通仍可近用此檔案,但祗適用於在地區網路所有機器重製的內容。即使是極微小的變動,都需要更新各地所有的檔案。所以, /etc/hosts 通常祗包括最重要的款目。
這個檔案對未連上網際網路的小型網路是夠用的,5 部以內的機器,建議安裝一個 DNS 伺服器較佳。