Dnsmasq (简体中文)

From ArchWiki
Revision as of 17:59, 11 December 2011 by Strcat (Talk | contribs) (codeline -> ic)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Package Official提供DNS缓存和dhcp服务功能。作为DNS服务器,dnsmasq可以通过缓存来提高解析网址的速度。作为dhcp服务器,dnsmasq可以为电脑提供内网ip地址并为电脑路由至局域网。DNS和DHCP两个功能可以同时或分别单独实现。dnsmasq轻量且易配置,适用于个人用户或少于50台主机的网络。



pacman -S dnsmasq

DHCP 服务器设置

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Dnsmasq (简体中文)#)

dnsmasq 配置文件(Template:Filename),必要的配置如下:

# Only listen to routers' LAN NIC.  Doing so opens up tcp/udp port 53 to
# localhost and udp port 67 to world:

# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with
# dynamic interfaces (assigning dynamic ips). Dnsmasq will discard world
# requests to them, but the paranoid might like to close them and let the 
# kernel handle them:

# Dynamic range of IPs to make available to LAN pc

# If you’d like to have dnsmasq assign static IPs, bind the LAN computer's
# NIC MAC address:

If you choose not to bind the interfaces, the domain port will need to be allowed in Template:Filename:

domain ALL : ALLOW

DNS 缓存设置





Template:Package Official 可以是通过创建(或编辑)Template:Filename文件或 Template:Filename文件来指定dns服务器,使Template:Filename不会被每次都被dhcpcd重写

echo "nameserver" > /etc/resolv.conf.head #设置dns服务器为127.0.0.1


如果你使用dhclient,你添加或编辑 Template:Filename 文件:

prepend domain-name-servers;


Since the upgrade of NetworkManager to 0.7, Arch Linux now calls Template:Package Official directly instead of the common default with Template:Package Official. Because of the arguments set with Template:Package Official, it no longer sources the Template:Filename, and Template:Filename settings for insertion of name servers. There are two workarounds to fix this. The first would be to use NetworkManager with dhclient which can be found in Template:Package AUR. The second workaround would be to go into NetworkManagers' settings (usually by right-clicking the applet) and entering your settings manually. Depending on the type of front-end you use for NetworkManager, the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as 'Automatic (specify addresses).' The DNS ddresses are usually entered in such form:, DNS-server-one, ....



/etc/rc.d/dnsmasq start


DAEMONS=(network dnsmasq ...)

查看dnsmasq是否启动正常,检查 Template:Filename 日志文件。

Test DHCP Server

From a computer that is connected to the one with dnsmasq on it, configure it to use DHCP for automatic IP address assignment, then attempt to log into the network as you normally would.

Test DNS Caching

Do a DNS lookup and measure the time response (dig is part of the Template:Package Official package):

dig archlinux.org | grep "Query time"

Try it again to compare the result.


Prevent OpenDNS Redirecting Google Queries

To prevent OpenDNS from redirecting all Google queries to their own search server, add to Template:Filename:


Replace X.X.X.X with your ISP's DNS server/Router IP.