This translation is older than the original page and might be outdated. See what has changed.



Dnsmasq is a lightweight, easy to configure DNS-forwarder and DHCP-server. It is designed to provide DNS and, optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP-server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP for network booting of disk-less machines. It is already installed and preconfigured on OpenWrt.

中文翻译Dnsmasq 是一个轻量级的,易配置的DNS转发器和DHCP服务器。 它用来为小型网络提供DNS解析的,以及DHCP地址分发。 它还可以用来解析那些公网上没有的,本地网络的主机名称的IP地址。 DHCP服务器整合了一个DNS服务器,以及一个用来分配地址DHCP分配器;不管DNS的解析名字是配置在各个主机里,还是统一配置在一个文件里。 Dnsmasq可以支持动态或者静态的地址分配,以及用于BOOTP这样无盘系统的场景下。 OpenWrt内置,且默认配置了该软件。

The configuration is done with help of the uci-configuration file: /etc/config/dhcp, but you can use this together with the file /etc/dnsmasq.conf.

Depending on the setting in the uci-file, you may also use the files /etc/ethers and /etc/hosts additionally.




/etc/config/dhcp is a UCI configuration file and as such documented exclusively in uci. Almost all settings can be configured with it!

中文翻译: → /etc/config/dhcp采用了统一配置接口文件,那些在统一配置命令的特定功能uci,几乎都可以在这个文件里配置出来。

It is possible to mix the traditional /etc/dnsmasq.conf configuration file with the options found in /etc/config/dhcp.

The dnsmasq.conf file does not exist by default but will be processed by dnsmasq on startup if it is present. Note that options in /etc/config/dhcp take precendence over dnsmasq.conf since they are translated to command line arguments.

You can have dnsmasq execute a script on every action: dhcp-script = /sbin/

Example: By default, Dnsmasq comes configured to put your hosts into the .lan domain. This is specified in the configuration file as:

中文翻译: 统一的配置文件“/etc/config/dhcp”也可以跟“/etc/dnsmasq.conf”同时配置使用。 而“dnsmasq.conf”文件默认是不存在的,但是dnsmasq软件再启动的时候,如果发现有该文件,那么它就会去处理。 注意,在配置文件最终转换成dnsmasq配置命令参数的时候,“/etc/config/dhcp”文件的配置参数优先级高,相同参数的配置会覆盖“dnsmasq.conf”文件里配置参数。

例如: 默认情况下,Dnsmasq可以将你的主机解析到“.lan”的域名下 这个可以在配置文件里就指定了:

# allow /etc/hosts and dhcp lookups via *.lan

You can change this to whatever you'd like your home domain to be. Also, if you want your hosts to be available via your home domain without having to specify the domain in your /etc/hosts file, add the expand-hosts directive to your /etc/dnsmasq.conf file.

As an example, without expand-hosts, you can only reach router, ubuntu-desktop and ubuntu-laptop. With expand-hosts on, you can reach router, router.lan, ubuntu-desktop, ubuntu-desktop.lan, etc. This probably matches what you're looking for anyway.

Without this setting, you'll have to add .lan entries to your /etc/hosts.

中文翻译: 在这个参数里你可以随便定义自己的主机域名。 同样的,如果你想让你定义的域名访问到你的本地机器,又不想在“/etc/hosts”文件里添加域名解析信息,你也可以直接在“/etc/dnsmasq.conf”里添加“expand-hosts”参数设定。

举例说,如果不使用“expand-hosts”选项设置,你就只可以访问到 router, ubuntu-desktop and ubuntu-laptop。 而如果使用了“expand-hosts”选项,那么你可以访问到除了router, ubuntu-desktop and ubuntu-laptop,还有 router.lan, ubuntu-desktop.lan等等。 这个特点可能正是你想要的。


In /etc/ethers static lease entries can be assigned. See → static_leases.


在“/etc/ethers”中静态的分配地址。 详情请参考→ static_leases.

In /etc/hosts DNS entries are configured. Dnsmasq will utilize these entries to answer DNS queries on your network.

中文翻译:在“/etc/hosts”文件中配置DNS的解析条目。 Dnsmasq软件将使用这些条目来响应来自网络的DNS查询请求。



[IP地址] 主机名称 主机名称缩写 ...

例如: router OpenWrt localhost debian-server ubuntu-laptop

Sometimes when an interface is on the edge of the capacity (especially WiFi over longer distances) a DHCP request could be not replied in time. Therefore the DHCP client will not be able to receive proper network settings. A possible workaround is using static IPs or very long DHCP leases (more than 12h). This is particularly important when one has several WiFi repeaters that use DHCP and are distant from each other or not easily accessible.

中文翻译: 有些时候,当一个网络接口快达到它的处理能力的时候(特别是因为WiFi因为超出其稳定信号的范围),DHCP的请求可能不会及时响应。 因此DHCP客户端就没法收到网络地址的配置。 一种折中的解决办法设置静态IP地址,或者加长DHCP租用时间(比如大于12小时)。 这在存在很多WiFi中继的场景中很重要,因为它们之间很远或者连接不稳定。

Windows 7 among others ask for proxy settings using DHCP. The issue is that they do not stop asking until they have received an answer. This results in that the log contains a lot information about these requests, an example can be found below (thanks to the excito wiki for the info).


中文翻译: Windows7跟其他系统之间,使用DHCP来配置代理的情况里; 因为客户端不停的发送请求,直到收到回复才会停止; 结果就是,在日志里充满了这些重复的请求,下面就是这么一个例子的解决(参看the excito wiki提供相关的信息)。


uci add_list dhcp.lan.dhcp_option='252,"\n"'
uci commit dhcp
service dnsmasq restart

Windows 7 has introduced a new Microsoft-enhanced feature. It won't assign IP address obtained from a DHCP server to an interface, if the IP was used before for another interface, even if that other interface is NOT active currently (i.e. cable disconnected). This behaviour is unique and was not reported for older Windows versions, Mac OS nor Linux.

If you try configure MAC address hot swap on your router, Windows 7 clients will end up in an infinite DORA loop.

中文翻译: Windows7包含一个新的功能 Microsoft-enhanced 。 系统不会把一个之前已经由DHCP服务器分配给另外一个接口(对应网卡)的IP地址,再配置给当前接口;即使是这个接口现在已经关闭了(比如该接口的网线已经拔了)。 这个处理思路很清奇,在老版本的Windows、Mac OS、Linux里都没听说过。



  1. Create a bridge from the wireless and ethernet interfaces on your client
    • Add the MAC address of the bridge to /etc/config/dhcp
    • Since the bridge will probably take and alter your ethernet MAC address, you will lose SLAAC on wifi interface, making your laptop IPv6-disabled when only wireless is up.
  2. Another solution is IPv6 friendly, you don't need to create a bridge, nor add MAC address to dnsmasq config file, but it involves user interaction:
    • When you plug the ethernet cable in, disable wireless interface in control panel (power off wireless won't do it).
    • When you unplug ethernet cable, enable wireless and disable ethernet.



  1. 创建一个Windows7种的有线网卡跟无线网卡的网桥,然后:
    • 给这个网桥添加MAC地址,并写到“/etc/config/dhcp”
    • 因为你的网桥可能会占用或者改变你的MAC地址,你可能会在WiFi接口上丢失SLAAC状态,这样,你如果想用无线网络,就得在你的笔记本上(假设你的客户机就是笔记本)禁掉IPv6.
  2. 另一种对IPv6兼容一点的做法是,你可以不要添加网桥的配置,也不用手工去dnsmasq软件里添加MAC地址,但是却要做别的配置:
    • 如果你要用有线网络,你插网线的前,先去控制面板把无线网卡禁用掉。
    • 如果你要用无线网络,你拔网线的前,再把无线网卡启用,然后把有线网卡禁用。
uci add dhcp host
uci set	dhcp.@host[-1].name="example-host"
uci set	dhcp.@host[-1].ip=""
uci set	dhcp.@host[-1].mac="00:a0:24:5a:33:69 00:11:22:33:44:55 02:a0:24:5a:33:69 02:11:22:33:44:55"
uci commit dhcp
service dnsmasq restart

LongGenxing 20191105 第一次翻译

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2019/11/04 23:17
  • by longgenxing