12.8. 配置文件

12.8.1. /etc 的配置

有许多目录保存着配置信息。这些目录包括:

目录 用途
/etc 通用的系统特定配置信息。
/etc/defaults 系统配置文件的默认版本。
/etc/mail 额外的 sendmail(8) 配置和其他 MTA 配置文件。
/etc/ppp 用户或系统 ppp 程序的配置
/usr/local/etc 已安装的应用程序的配置文件。可能包含每个应用的子目录。
/usr/local/etc/rc.d 已安装程序的 rc(8) 脚本
/var/db 自动生成系统特定的数据库文件,例如软件包数据库和 locate(1) 数据库。

12.8.2. 主机名称

12.8.2.1. /etc/resolv.conf

FreeBSD 系统如何访问互联网域名系统 ( DNS ) 是由 resolv.conf(5) 控制的。

以下为 /etc/resolv.conf 中最常见的条目:

条目 解释
nameserver 解析器应查询的名称服务器的 IP 地址,服务器按照列出的顺序进行查询,最多可查询三个。
search 用于主机名查询的搜索列表,这通常是由本地主机名的域决定的。
domain 本地域名。

一个典型的 /etc/resolv.conf 长这样:

  1. search example.com
  2. nameserver 147.11.1.11
  3. nameserver 147.11.100.30

注意

searchdomain 中,只有一个能被使用。

当使用 DHCP 时,dhclient(8) 常常用从 DHCP 服务器中收到的信息来重写 /etc/resolv.conf

12.8.2.2. /etc/hosts

/etc/hosts 是一个简单的文本数据库,它与 DNS 和 NIS 一起工作,提供主机名和 IP 地址的映射。通过局域网连接的本地计算机的条目可以被添加到这个文件中,以达到简化命名的目的,而不是建立一个 named(8) 服务器。此外,/etc/hosts 还可以用来提供互联网名称的本地记录,减少为常用名称查询外部 DNS 服务器的需要。

  1. # $FreeBSD$
  2. #
  3. #
  4. # Host Database
  5. #
  6. # This file should contain the addresses and aliases for local hosts that
  7. # share this file. Replace 'my.domain' below with the domainname of your
  8. # machine.
  9. #
  10. # In the presence of the domain name service or NIS, this file may
  11. # not be consulted at all; see /etc/nsswitch.conf for the resolution order.
  12. #
  13. #
  14. ::1 localhost localhost.my.domain
  15. 127.0.0.1 localhost localhost.my.domain
  16. #
  17. # Imaginary network.
  18. #10.0.0.2 myname.my.domain myname
  19. #10.0.0.3 myfriend.my.domain myfriend
  20. #
  21. # According to RFC 1918, you can use the following IP networks for
  22. # private nets which will never be connected to the Internet:
  23. #
  24. # 10.0.0.0 - 10.255.255.255
  25. # 172.16.0.0 - 172.31.255.255
  26. # 192.168.0.0 - 192.168.255.255
  27. #
  28. # In case you want to be able to connect to the Internet, you need
  29. # real official assigned numbers. Do not try to invent your own network
  30. # numbers but instead get one from your network provider (if any) or
  31. # from your regional registry (ARIN, APNIC, LACNIC, RIPE NCC, or AfriNIC.)
  32. #

/etc/hosts 的格式如下:

  1. [Internet address] [official hostname] [alias1] [alias2] ...

比如:

  1. 10.0.0.1 myRealHostname.example.com myRealHostname foobar1 foobar2

可在 hosts(5) 的手册中找到更多信息。