Which keyword must be listed in the hosts option of the Name Service Switch configuration file in order to make host lookups consult the /etc/hosts file?



Answer: files

題解

部份GNU C語言的函式庫會根據本地端系統的設定不同而有不同的運作方式,像是getaliasent、gethostbyname、getnetent等等的函數。GNU C語言的函式庫會使用NSS(Name Service Switch)來讀取系統的資料庫,資料庫名稱列表如下:

  • aliases
  • ethers
  • group
  • hosts
  • initgroups
  • netgroup
  • networks
  • passwd
  • protocols
  • publickey
  • rpc
  • services
  • shadow

NSS的設定檔「/etc/nsswitch.conf」決定了該資料庫名稱的資料取得的來源和順序。如「files」表示來源為檔案(設定檔)、「db」表示來源為資料庫、「dns」表示來源為網域名稱伺服器,而「compat」則有點像是「files」但同時能使用檔案來過濾NIS來的資料。

要讓NSS使用「/etc/hosts」檔案,應使用如下設定:

hosts: files