首頁  >  文章  >  運維  >  Linux下如何用dnsmasq做dns cache server配置

Linux下如何用dnsmasq做dns cache server配置

王林
王林轉載
2023-05-15 19:28:041079瀏覽

安裝過程比較簡單

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

keepalived的設定很簡單,只需要設定一個vip可以在兩台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         // 另一台配置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的設定也很簡單

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


  將dns位址寫入/etc/resolv.dnsmasq.conf檔案中

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

  本機和區域網路其它全部的伺服器dns解析都用它

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

##  最後最後找一台區域網路server驗證一下,如果能解析就說明正常了.

nslookup www.google.cn 192.168.100.99

  此方案只適合小型企業,規模少的情況下使用,解析量大的時候還是用bind最好。

以下是其它網友的補充:

複製程式碼 程式碼如下:

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


比較來說,dnsmasq的設定簡單多了:

複製程式碼 程式碼如下:

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


最後,別忘記加入rc.conf daemons,注意要在network後面。

dnsmasq 可從額外的hosts檔案讀取項目,如可以這樣新增正向解析:

echo "ip位址網域名稱" > /etc/dnsmasq.hosts

另外,重新啟動dnsmasq可以用sighup(可以在修改hosts檔案後,讓設定生效)

 killall -s sighup dnsmasq

檢視服務狀態:

 netstat -tunl

tcp        0      0 0.0.0.0:53                 0      0 0.0.0.0:53              0.0.0.0:*

以上是Linux下如何用dnsmasq做dns cache server配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除