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