Dnsmasq/zh-cn

Dnsmasq是一个简单的DHCP/DNS服务器，它可以被一个小于1000个客户端的局域网来使用，关键特性是容易配置的而且占用空间很少，它还支持IPv6.

Installation
Dnsmasq的安装可以被包管理器和Portage树完全支持. 不过首先请先选择好适当的USE标记.

下一步，安装 ，然后把它加入default runlevel，如果您打算让它开机自动运行的话.

Configuration
有很多资源都可以被用来改变dnsmasq的行为，它们包括：
 * 通过 来提供的命令行选项
 * 主配置文件

服务配置
在 中，需要在启动时传递给dnsmasq后台驻留程序的命令行选项可以被配置.

主配置文件
dnsmasq的主配置文件为. 这个文件使用  语法而且是随安装包一起被提供出来的，它的文档非常全面，因此建议被阅读. 在文件里或者通过命令行选项的设置，外部的资源是可以被引用的（例如一个DHCP主机文件）.

下面就是一个范例配置文件：

配置完配置文件后，服务需要被重启——重载虽然是被支持的但它是为其它资源准备的.

Hosts文件
dnsmasq使用 文件作为它提供DNS服务所需的资源之一，除非    命令行参数被传递给服务进程.

如果是最新的，dnsmasq服务需要接收一个SIGHUP信号来重新载入这些设置，这也可以通过初始化脚本“reload”命令来支持.

这个行为也可以通过在配置文件中设置 参数来禁止.

额外的hosts文件
为了DNS查询参考一个（额外的）hosts文件作为源是可能的. 要实现这一点，增加  命令行选项. 也可以传递一个目录，在这种情况下，被包括在这个目录下的所有文件将被当作额外的hosts文件.

类似于标准的hosts文件，一个SIGHUP信号会重新载入这个文件.

这个行为也可以通过在配置文件里的 参数进行设置.

上游的名称服务器们
缺省地，dnsmasq使用 里定义的名称服务器们作为它自己的上游名称服务器.

通过   命令行选项可以使用一个不同的文件.

这个行为也可以通过在配置文件中的  参数来进行设置.

特性
Dnsmasq支持DNS, TFTP, PXE，路由器广告和DHCP服务，所以它是一个给中小型网络的万用网管工具.

DNS服务
为了（只）提供DNS服务，首先要分辨所使用的“上游名称服务器”，如果这与在中定义的相同，那么就没什么其它步骤需要进行操作了. 否则就需要通过  命令行参数让dnsmasq指向适当的  文件. 它的语法就是被 文件使用的方法，虽然dnsmasq只看"nameserver"的定义.

For instance:

Next point dnsmasq to this file through the configuration file:

To verify that the service is running (after restarting as the configuration file has just been changed), use the  command (provided through ), asking the DNS server (running on localhost in the following example) to resolve a local or remote address:

DNSSEC
Dnsmasq can validate DNSSEC data while passing through data. This can be accomplished by adding these lines to the config file:

The trusted anchor can be found on the iana.org site. After this change dnsmasq will return SERVFAIL and no DNS data if the validation fails. If the validation succeeds it sets the ad flag. In case the domain does not support DNSSEC dnsmasq behaves as before.

DHCP services
In order to enable the DHCP services of dnsmasq, use the  configuration setting.

For instance, to enable IPv6 address configuration through RA with infinite lease time, and IPv4 address configuration also with infinite lease time:

It is possible to use static definitions for known hosts, either through the main configuration file ( settings) or through a separate file. If a separate file is used, point dnsmasq to it through the  command line option. The advantage of the latter approach is that it is sufficient to send a SIGHUP signal (or reload the service) in order to reread the entries, whereas definitions in the configuration file require a full service restart.

For more information about the syntax of the  parameter please refer to the manual page or configuration file as its syntax is very extensive.

Usage
This section covers various usage scenarios (maintenance and operational tasks) for the dnsmasq service.

Resetting leases
Clients that had a network interface update which results in a different MAC address might not get the intended IP address immediately. This is because the dnsmasq service has provided this IP address to the old MAC address, and will wait until the lease of this address has expired before re-assigning it.

The dnsmasq service stores its leases in. If the lease needs to be removed faster, shut down the dnsmasq service, remove the lease from the file and start the service again.

Reloading non-main configuration settings
Next to the file, the dnsmasq service can use external definitions for the following services:
 * DHCP host configuration entries (through  command line option)
 * DHCP options (through  command line option)

When these files are modified, a SIGHUP signal has dnsmasq reload these configuration files.