1. 程式人生 > >centos7.3安裝dnsmasq

centos7.3安裝dnsmasq

linux dns centos7.x dnsmasq

Dnsmasq 提供 DNS 緩存和 DHCP 服務功能。作為域名解析服務器(DNS),dnsmasq可以通過緩存 DNS 請求來提高對訪問過的網址的連接速度。作為DHCP 服務器,dnsmasq 可以用於為局域網電腦分配內網ip地址和提供路由。DNS和DHCP兩個功能可以同時或分別單獨實現。dnsmasq輕量且易配置,適用於個人用戶或少於50臺主機的網絡。此外它還自帶了一個 PXE 服務器。

默認是關閉dhcp功能。

#安裝
yum install dnsmasq -y
#編輯配置文件/etc/dnsmasq.conf
[root@node dnsmasq.d]# grep -Ev "^$|^[#;]" /etc/dnsmasq.conf  
listen-address=10.0.40.246,127.0.0.1
cache-size=10000
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig

默認會從/etc/hosts,/etc/resolv.conf讀取文件。

/etc/hosts 會讀取到本地域名配置文件(不支持泛域名)

/etc/resolv.conf 會讀取上遊DNS配置文件,如果讀取不到/etc/hosts的地址解析,就會轉發給resolv.conf進行解析地址

如果你想使用泛指域名的話,可以在/etc/dnsmasq.d編輯一個配置文件

[root@node dnsmasq.d]# cat /etc/dnsmasq.d/address.conf 
address=/xxxlocal.com/10.0.40.247

下面是網上找到的一個例子,僅作參考:

address=/www.taobao.com/127.0.0.1  #正向解析
ptr-record=127.0.0.1.in-addr.arpa,www.taobao.com    #反向解析(可選)

address=/baidu.com/127.0.0.1    #泛域名解析

最後可選項:

配置日誌輪詢

#配置日誌輪轉,編輯/etc/logrotate.d/dnsmasq
/var/log/dnsmasq.log {
    daily
    copytruncate
    missingok
    rotate 30
    compress
    notifempty
    dateext
    size 200M
}

重啟服務


命令:

systemctl enable dnsmasq
systemctl start dnsmasq
systemctl restart dnsmasq
#查看dnsmasq是否啟動正常,查看系統日誌:
journalctl -u dnsmasq


參考:

https://wiki.archlinux.org/index.php/Dnsmasq_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

http://www.cnblogs.com/wsl222000/p/5981299.html

本文出自 “禪劍一如” 博客,請務必保留此出處http://yanconggod.blog.51cto.com/1351649/1977598

centos7.3安裝dnsmasq