A DNS server has the IP address 192.168.0.1. Which TWO of the following need to be done on a client machine to use this DNS server?
A. Add nameserver 192.168.0.1 to /etc/resolv.conf
B. Run route add nameserver 192.168.0.1
C. Run ifconfig eth0 nameserver 192.168.0.1
D. Ensure that the dns service is listed in the hosts entry in the /etc/nsswitch.conf file
E. Run bind add nameserver 192.168.0.1
题解
GNU C 语言的函数库会根据「/etc/resolv.conf」设置档所定义的网域名称服务器来查找网域名称实际对应的 IP 地址。可以使用的关键字如下:
- nameserver:要查找的网域名称服务器。
- domain:本地的网域名称。
- search:查找主机名称的时候所串接的网域名称。
- sortlist:排序 gethostbyname 函数的回传结果。
- options
部份 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 来的数据。
所以答案是选项 A 和选项 D。
