1.9. HOSTS AND RESOLV.CONF

The hosts and resolv.conf files are used to control how FreeBSD performs DNS lookups. A DNS lookup is like calling a telephone operator: You give the operator a person's name and she gives you a phone number in return. For example, if a web page like http://www.google.com is requested, FreeBSD (by default) first consults the hosts file (/etc/hosts), then the DNS servers specified in resolv.conf in order to translate www.google.com into an IP address like 66.102.7.99.

Let's take a closer look at each of these files and see how to set them up.

 

1.9.1. hosts

The hosts file resolves (translates) hostnames to IP addresses. At minimum, the hosts file should be modified to reflect your system's domain name and hostname.

Open the hosts file in a text editor:

# ee /etc/hosts

Your hosts file (~14) should look like this (replace example.com with your domain name, host.example.com with your hostname, and 192.168.1.11 with your IP address):

::1               localhost localhost.example.com  127.0.0.1         localhost localhost.example.com  192.168.1.11      host.example.com

Save and exit.

Settings in this file only affect the local system. The hosts file supplies basic hostname resolution for daemons and other system processes. If you need to provide DNS services, you'll need to use a DNS server. (See "ISC BIND DNS Server 9.4.2" for more information.)

 

1.9.2. resolv.conf

The resolv.conf file contains the IP addresses of the DNS servers that your system will query when trying to resolve any hostname whose IP address is not found in the hosts file. The addresses in this file are automatically set if you chose DHCP to configure your network adapter during the initial FreeBSD installation. To set this file manually, open it:

# ee /etc/resolv.conf

The resolv.conf file should look something like this, where example.com is your domain name, 206.12.29.11 is the IP address of the DNS server, and 192.168.1.11 is the IP address of the backup DNS server (both IP addresses are provided by your ISP):

domain example.com  nameserver 206.12.29.11  nameserver 192.168.1.11

 

注:这个是针对 Unix/Linux 客户端配置的,即客户端的 OS 是 Unix/Linux 才需要这样配置,目的是让客户端可以解析 host.example.com ,类似 Windows 下的 hosts 文件。

 

          印第安

      2009年4月6日11:47:18 更新