Difference between revisions of "Dnsmasq (简体中文)"

From ArchWiki
Jump to: navigation, search
m
m (codeline -> ic)
Line 59: Line 59:
 
=== 使用NetworkManager ===
 
=== 使用NetworkManager ===
  
Since the upgrade of [[NetworkManager]] to 0.7, Arch Linux now calls {{Package Official|dhcpcd}} directly instead of the common default with {{Package Official|dhclient}}.  Because of the arguments set with {{Package Official|dhcpcd}}, it no longer sources the {{Filename|/etc/resolv.conf.head}}, and {{Filename|/etc/resolv.conf.tail}} 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 {{Package AUR|networkmanager-dhclient|here}}.  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: {{Codeline|127.0.0.1, DNS-server-one, ...}}.
+
Since the upgrade of [[NetworkManager]] to 0.7, Arch Linux now calls {{Package Official|dhcpcd}} directly instead of the common default with {{Package Official|dhclient}}.  Because of the arguments set with {{Package Official|dhcpcd}}, it no longer sources the {{Filename|/etc/resolv.conf.head}}, and {{Filename|/etc/resolv.conf.tail}} 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 {{Package AUR|networkmanager-dhclient|here}}.  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: {{Ic|127.0.0.1, DNS-server-one, ...}}.
  
 
==启动dnsmasq守护进程==
 
==启动dnsmasq守护进程==

Revision as of 17:59, 11 December 2011

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台主机的网络。

安装

dnsmasq在官方软件库里提供,直接安装

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:
interface=<LAN-NIC>

# 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:
bind-interfaces

# Dynamic range of IPs to make available to LAN pc
dhcp-range=192.168.111.50,192.168.111.100,12h

# If you’d like to have dnsmasq assign static IPs, bind the LAN computer's
# NIC MAC address:
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.111.50

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


domain ALL : ALLOW

DNS 缓存设置

如果你将dnsmasq作为DHCP服务器使用,那么dnsmasq已经设置好为内网记录DNS请求并返回DNS解析结果。要以守护进程方式启动dnsmasq做DNS缓存服务器,编辑Template:Filename,添加监听地址:

listen-address=127.0.0.1

在配置好dnsmasq后,你需要编辑Template:Filename让DHCP客户端首先使用本地DNS地址,然后再通过其他DNS服务器解析地址。配置好后需要重新连接网络来使设置生效。

使用dhcpcd

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

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

使用dhclient

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

prepend domain-name-servers 127.0.0.1;

使用NetworkManager

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: 127.0.0.1, DNS-server-one, ....

启动dnsmasq守护进程

Dnsmasq以守护进程方式运行,要启动它:

/etc/rc.d/dnsmasq start

要让dnsmasq开机启动,添加dnsmasq到Template:Filename的守护进程列表里面:

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.

Tips

Prevent OpenDNS Redirecting Google Queries

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

server=/www.google.com/X.X.X.X

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