Home  >  Article  >  Operation and Maintenance  >  How to use dnsmasq to configure dns cache server under Linux

How to use dnsmasq to configure dns cache server under Linux

王林
王林forward
2023-05-15 19:28:041027browse

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 float between the two servers to achieve active and backup.

! configuration file for 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         // 另一台配置backup
  interface eth1        // 在哪个接口上进行服务器状态检测
  virtual_router_id 51
  priority 180         // backup机器上配置100
  advert_int 1         // 检查间隔,单位为秒
  authentication {
    auth_type pass
    auth_pass 1234
  }
 
  virtual_ipaddress {       // vip设置,指定到内网网卡 
    192.168.100.99/24 dev eth1
  }
}

dnsmasq The configuration is also very simple

resolv-file=/etc/resolv.dnsmasq.conf
cache-size=1000
conf-dir=/etc/dnsmasq.d


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

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

This machine and all other servers in the LAN use it for dns resolution

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

Finally Find a LAN server to verify. If it can be parsed, it means it is normal.

nslookup www.google.cn 192.168.100.99

This solution is only suitable for small enterprises and is used when the scale is small. , it is best to use bind when the amount of analysis is large.

The following are additions from other netizens:

Copy the code The code is as follows:


sudo pacman -s --needed dnsmasq
cd /etc

[admin@huangye etc]$ sudo cp -v dnsmasq.conf{,.orig}
`dnsmasq.conf' -> `dnsmasq.conf.orig'

[admin@huangye etc]$ sudo vim dnsmasq.conf


In comparison, the configuration of dnsmasq is much simpler:

Copy code The code is as follows:


resolv-file=/etc/dnsmasq.resolv.conf
addn-hosts=/etc/dnsmasq.hosts
local=/localnet/
no-dhcp-interface=eth0
conf-dir=/etc/dnsmasq.d

Copy code The code is as follows:


[admin@huangye etc]$ sudo cp -v resolv.conf dnsmasq.resolv .conf
password:
`resolv.conf' -> `dnsmasq.resolv.conf'
sudo mkdir /etc/dnsmasq.d
sudo touch /etc/dnsmasq.hosts

sudo /etc/rc.d/dnsmasq start

Finally, don’t forget to add rc.conf daemons, be sure to add them after network.

dnsmasq can read entries from additional hosts files. For example, you can add forward resolution like this:

echo "ip address domain name" > /etc/dnsmasq.hosts

In addition, you can use sighup to restart dnsmasq (you can make the configuration take effect after modifying the hosts file)

killall -s sighup dnsmasq

Check the service status:

netstat -tunl
tcp 0 0 0.0.0.0:53 0.0.0.0:* listen
udp 0 0 0.0.0.0:53 0.0.0.0 :*

The above is the detailed content of How to use dnsmasq to configure dns cache server under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete