Linux USES dnsmasq to configure dns cache server

  • 2020-05-09 19:50:12
  • OfStack

Now is the latest version 2.7.1, can go to its FTP download: http: / / www thekelleys. org. uk/dnsmasq /

The installation process is 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 simple. You only need to configure one VIP to float back and forth between two Server


! 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         //  On the other 1 Machine configuration BACKUP
  interface eth1        //  On which interface is the server status detected 
  virtual_router_id 51
  priority 180         // BACKUP Machine configuration 100
  advert_int 1         //  Check interval in seconds 
  authentication {
    auth_type PASS
    auth_pass 1234
  }
 
  virtual_ipaddress {       // VIP Set, specify to the Intranet network card  
    192.168.100.99/24 dev eth1
  }
}

The configuration of dnsmasq is also simple


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


Will dns address written to the/etc/resolv dnsmasq. conf file

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

It is used for native and all other LAN server dns parsing

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

Finally, find a LAN Server to verify 1, if you can resolve the normal.

nslookup www.google.cn 192.168.100.99

This scheme is only suitable for small enterprises, and can be used in small scale. It is best to use bind when the amount of parsing is large.

Here's what others have to add:


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

By comparison, the configuration of dnsmasq is much simpler:

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


[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, after network.

dnsmasq can read entries from additional hosts files by adding forward parsing as follows:

echo "IP address domain" > /etc/dnsmasq.hosts

In addition, restart dnsmasq with SIGHUP (you can change the hosts file to allow the configuration to take effect)

  killall -s SIGHUP dnsmasq

View 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:*

Again under dig 1, it was found to be stable at 4ms, I was dizzy, the same configuration, I was on 1 ubuntu server 10.04, dig is 1ms, in my local unexpectedly in 4ms, hang  


Related articles: