DNSMASQ (Simplified Chinese)

Source: Internet
Author: User
Tags log log nameserver
dnsmasq (Simplified Chinese)From ArchWiki Jump to:navigation, search Translation Status:This is the English page dnsmasq translation, the last translation time: 2012-06-18, click here to see the translation of the English page changes.

DNSMASQ provides DNS caching and DHCP service functionality. As a domain name resolution server (DNS), DNSMASQ can increase the speed of connection to visited URLs by caching DNS requests. As a DHCP server, DNSMASQ can provide intranet IP addresses and routes for LAN computers. DNS and DHCP two features can be implemented separately or separately. DNSMASQ lightweight and easy to configure for use with individual users or networks with fewer than 50 hosts.

Contents [Hide] 1 Install 2 DHCP server settings 3 DNS cache Settings 3.1 DHCP settings 3.1.1 Use dhcpcd 3.1.2 Use dhclient 3.1.3 use NetworkManager 4 to start DNSMASQ Daemon 5 Test 5.1 DNS Cache 5.2 DHCP Server 6 tips 6.1 Avoid OpenDNS redirect Google Request 6.2 View Leases
installation

Install DNSMASQ from the official warehouse. DHCP Server Settings

DNSMASQ configuration file (/etc/dnsmasq.conf), the necessary configuration is as follows:

# only listen to routers ' LAN NIC.  Doing so opens up tcp/udp port to
# localhost and UDP port to World:
interface=<lan-nic>

# DNSMASQ Would open TCP/UDP port and UDP port to world to help with
# Dynamic interfaces (assigning dynamic IPs). DNSMASQ would discard World
# requests to them, but the paranoid might as-to-close them and let the 
# kernel hand Le 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
DNS Cache Settings

To start dnsmasq as a daemon, do a DNS cache server, edit/etc/dnsmasq.conf, and add a listener address:

listen-address=127.0.0.1

If you use this computer as the default DNS, use a fixed IP address:

listen-address=192.168.1.1 # Example IP
DHCP Settings

After you configure DNSMASQ, you need to edit/etc/resolv.conf to have the DHCP client first add the local address (localhost) to the DNS file (/etc/resolv.conf) and then resolve the address via another DNS server. After you configure the DHCP client, you need to restart the network for the settings to take effect. using DHCPCD

DHCPCD can specify a DNS server by creating (or editing)/etc/resolv.conf.head files or/etc/resolv.conf.tail files so that/etc/resolv.conf is not rewritten every time dhcpcd

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

To use Dhclient, uncomment the following lines in the/etc/dhclient.conf file:

Prepend domain-name-servers 127.0.0.1;
using NetworkManager

NetworkManager use DHCPCD instead of dhclient by default. DHCPCD now no longer import/etc/resolv.conf.head and/etc/resolv.conf.tail name resolution settings. There are several options:

The first option is to use a script to add localhost to resolv.conf in NetworkManager dispatcher:

/etc/networkmanager/dispatcher.d/localhost-prepend
#!/bin/bash                                       
# prepend localhost to resolv.conf for dnsmasq

if [[! $ (grep 127.0.0.1/etc/resolv.conf)]]; then
  
   sed-i ' 1s|^|nameserver 127.0.0.1\n| '/etc/resolv.conf
fi
  

This is executable:

# chmod +x/etc/networkmanager/dispatcher.d/localhost-prepend

The second option is to enter the Networkmanagers setting and enter it manually. Select a profile and select DHCP type ' Automatic (specify addresses). ' DNS addresses need to be entered manually: 127.0.0.1, Dns-server-one, .....

You can use the Networkmanager-dhclient package to NetworkManager dhclient. start the DNSMASQ daemon

DNSMASQ is run as a daemon. But before you start it, let's see how fast we're parsing. Enter the following command: (Dig is part of the Dnsutils software package):

$ Dig archlinux.org | grep "Query Time"

Now we start it:

#/ETC/RC.D/DNSMASQ Start

To have DNSMASQ boot up, add DNSMASQ to the/etc/rc.conf daemon list:

daemons= (Network dnsmasq ...)

Check to see if DNSMASQ is up and checking the/var/log/messages.log log file.

You need to restart network so DHCPD will re-establish/etc/resolv.conf.

#/etc/rc.d/network Restart

Now let's test the DNS query and then measure the response time:

$ Dig archlinux.org | grep "Query Time"

Query time should be reduced.

And if you remove grep, you can see the server used (Query time next line), now it should be localhost or 127.0.0.1. Test DNS Cache

To test the speed of the query, please let me have a DNSMASQ launched after the site has not been visited, executed (dig (located in the Dnsutils package):

$ Dig archlinux.org | grep "Query Time"

Run the command again, because the cache is used and the query time should be shortened considerably. DHCP Server

From a computer that is connected to a computer that uses DNSMASQ, configure it to use DHCP to automatically obtain an IP address, and then try to connect to the network you normally use. Small Tips Avoid OpenDNS redirect Google requests

To avoid OpenDNS redirecting all Google requests to their own search server, add the following to/etc/dnsmasq.conf:

server=/www.google.com/x.x.x.x

Replace x.x.x.x with IP of your ISP's DNS server/router. View Leases

Cat/var/lib/misc/dnsmasq.leases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.