个人工具

UbuntuHelp:Dnsmasq

来自Ubuntu中文

Wikibot讨论 | 贡献2009年11月17日 (二) 18:55的版本

跳转至: 导航, 搜索

Introduction

DNSmasq provides two services, either of which can be used independently.

  • DNS service
  • DHCP service (including features relating to network boot)

A local DNS cache can speed up internet browsing because your browser will not need to go to another server, or across the internet, when it looks up a domain name you've used before, e.g. google.com DHCP allows your computer to allocate network addresses to other computers on your wired or wireless network. A computer needs a network address in order to do things like access the internet. DNSmasq does not do "Internet Connection Sharing" however it does do a lot of the hard work needed in the background. With DNSmasq set up, only two additional commands can set up internet connection sharing (ref?). Note that the package "dnsmasq" interferes with Network Manager which can use "dnsmasq-base" to provide DHCP services when sharing an internet connection. Therefore, if you use network manager (fine in simple set-ups only), then install dnsmasq-base, but not dnsmasq. If you have a more complicated set-up, uninstall network manager, use dnsmasq, or similar software (bind9, dhcpd, etc), and configure things by hand.

Setup for dnsmasq

Like much of the Ubuntu packages, dnsmasq is in universe. Make sure its enabled, then run these commands

sudo apt-get install dnsmasq

dnsmasq can be configured by editing the file

/etc/dnsmasq.conf

but for many people, the default (or empty) file will provide a good DNS cache system.

Special Cases

  • On a LAN, e.g. business or university. You do not want to provide name service or DHCP for a thousand colleagues, so add the line:

except-interface=eth0 if eth0 is your internet/LAN connected interface.

  • Add DHCP server:

dhcp-range=192.168.0.20,192.168.0.254,255.255.255.0 This range must not clash with your LAN IP address. Save and exit the file, restart the daemon and you should be running.

sudo invoke-rc.d dnsmasq restart

DNSmasq is now listening on some interfaces for DNS lookups and/or DHCP requests. You can verify this by running:

netstat -ltp
# -l = listen, -t = tcp, -p = show program name

You can add the line: nameserver 127.0.0.1 to the top of your /etc/resolv.conf file to use the local DNS cache first. Alternatively, the package resolvconf sorts all this out automatically. {i} Note: If you have the resolvconf package installed, you cannot use the "`resolv-file=`" option in your `/etc/dnsmasq.conf` configuration file as this value will be overridden by the `init.d` script when dnsmasq is started up. You should specify your upstream DNS servers using a `dns-nameservers` line (and optionally a dns-search line and other dns- options) for each interface in `/etc/network/interfaces`. The resolvconf scripts will automatically create a special file located at `/var/run/dnsmasq/resolv.conf` with your upstream servers and put `127.0.0.1` in `/etc/resolv.conf` to ensure DNS queries on your local machine use dnsmasq. For more information, see the resolvconf(8) man page.