Use dnsmasq for dns cache server in CentOS

Source: Internet
Author: User
Tags nameserver

Recently, the local DNS of foreign servers is always faulty. Transient disconnections will affect services. So I found two servers in the data center and installed keepalived and dnsmasq on the local DNS cache.
The installation process is relatively simple

yum -y install dnsmasq*

wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz

tar zxvf keepalived-1.2.9.tar.gz

cd keepalived-1.2.9

./configure --prefix=/usr/local/keepalived

make && make install

mkdir /etc/keepalived

cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/

chkconfig --add keepalived

chkconfig --level 35 keepalived on


The configuration of keepalived is very simple. You only need to configure a VIP to move between two servers to implement the master and slave nodes.

! ConfigurationFilefor keepalived

Global_defs {

Notification_email {

Xxx@xxx.com

}

Notification_email_from xxx@xxx.com

Smtp_server 127.0.0.1

Smtp_connect_timeout 30

Router_id LVS_DEVEL

}

Vrrp_instance dnscache {

State MASTER // configure BACKUP for another instance

Interface eth1 // interface on which server status detection is performed

Virtual_router_id 51

Priority 180 // configure 100 on the BACKUP machine

Advert_int 1 // check interval, in seconds

Authentication {

Auth_type PASS

Auth_pass 1234

}

Virtual_ipaddress {// VIP settings, specified to the Intranet Nic

192.168.100.99/24 dev eth1

}

}


The configuration of dnsmasq is also very simple.

resolv-file=/etc/resolv.dnsmasq.conf

cache-size=1000

conf-dir=/etc/dnsmasq.d


Write the dns address to the/etc/resolv. dnsmasq. conf file.

echo "nameserver 8.8.8.8">/etc/resolv.dnsmasq.conf


Use dns resolution for all servers on the local machine and LAN

echo "nameserver 192.168.100.99">/etc/resolv.conf


Finally, find a local area network Server to verify that it is normal if it can be resolved.

nslookup www.google.cn 192.168.100.99


This solution is only suitable for small enterprises. It is best to use bind when there is a small amount of resolution.


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.