In Linux, cache DNS resolution is used to speed up online response!

Source: Internet
Author: User
Tags nameserver

These days I have been very careful and found that when I browsed the web page using Firefox, I always saw a prompt in the lower left corner at the beginning:

"Parsing host xxx ..."

It seems that it is waiting for the DNS server to resolve the domain name. It is idle, so I decided to make a DNS Cache to speed up the Internet!

I found a software that meets the requirements:

[Xport @ ubuntu ~] $ Apt-cache search "dns" | fgrep "cach"
Dnsmasq-A small caching DNS proxy and DHCP server

Follow these steps:

1. Install dnsmasq:


# Install the dnsmasq Software Package
[Xport @ ubuntu ~] $ Sudo apt-get install "dnsmasq"

2. Set dnsmasq to take over the local DNS resolution request:


# Modify the configuration file of dnsmasq
[Xport @ ubuntu ~] $ Sudo gedit/etc/dnsmasq. conf

# Find the following content and modify it
# If you want dnsmasq to listen for DHCP and DNS requests only on
# Specified interfaces (and the loopback) give the name of
# Interface (eg eth0) here.
# Repeat the line for more than one interface.
# Interface =
# Or you can specify which interface _ not _ to listen on
# Define T-interface =
# Or which to listen on by address (remember to include 127.0.0.1 if
# You use this .)
Listen-address = 127.0.0.1 # Remove the comment above this line

3. Modify the dhclient Configuration:


# Modify the configuration file of dnsmasq
[Xport @ ubuntu ~] $ Sudo gedit/etc/dhcp3/dhclient. conf

# Find the following content and modify it
Prepend domain-name-servers 127.0.0.1; # Remove the comment above this line
Request subnet-mask, broadcast-address, time-offset, routers,
Domain-name, domain-name-servers, host-name,
Netbios-name-servers, netbios-scope;

4. Modify the resolv. conf configuration:


[Xport @ ubuntu ~] $ Sudo gedit/etc/resolv. conf

# Note: The content of my resolv. conf file will not be rewritten because of ADSL dialing.
# Because dnsmasq takes over the DNS resolution request of the local machine, the address of 127.0.0.1 is placed at the beginning.
Nameserver 127.0.0.1
Nameserver xxx. xxx
Nameserver xxx. xxx
Search lan

5. Restart the dnsmasq service:


[Xport @ ubuntu ~] $ Sudo/etc/init. d/dnsmasq restart

6. Take a look at the time required for DNS resolution, and compare the data between the two before and after DNS resolution:


[Xport @ ubuntu ~] $ Dig baidu.com # first execution
... Omitted output information...
; Query time: 8 msec
; SERVER: 127.0.0.1 #53 (127.0.0.1)
; WHEN: Mon Feb 19 20:43:32 2007
; Msg size rcvd: 229
 
[Xport @ ubuntu ~] $ Dig baidu.com # Run again
... Omitted output information...
; Query time: 0 msec
; SERVER: 127.0.0.1 #53 (127.0.0.1)
; WHEN: Mon Feb 19 20:45:27 2007
; Msg size rcvd: 59

Okay, close the job ~~~!

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.