前言

DNSmasq是一個小巧且方便地用于配置DNS和DHCP的工具,適用于小型網(wǎng)絡(luò)。它提供了DNS功能和可選擇的DHCP功能可以取代dhcpd(DHCPD服務(wù)配置)和bind等服務(wù),配置起來更簡單,更適用于虛擬化和大數(shù)據(jù)環(huán)境的部署。
DNSmasq主要是在配置文件/etc/dnsmasq.conf,利用好就能快捷部署好使的dhcp和dns服務(wù)。
DHCP服務(wù)
# 服務(wù)監(jiān)聽的網(wǎng)絡(luò)接口地址
#interface=eth0
listen-address=192.168.1.132,127.0.0.1
# dhcp動態(tài)分配的地址范圍
dhcp-range=192.168.1.50,192.168.1.150,48h
# dhcp服務(wù)的靜態(tài)綁定
# dhcp-host=00:0C:29:5E:F2:6F,192.168.1.201,infinite無限租期
dhcp-host=00:0C:29:5E:F2:6F,192.168.1.201,os02
dhcp-host=00:0C:29:15:63:CF,192.168.1.202,os03
# 設(shè)置默認租期
#dhcp-lease-max=150
# 租期保存在下面文件
#dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases
# 通過/etc/hosts來分配對應(yīng)的hostname
#dhcp-host=judge
# 忽略下面MAC地址的DHCP請求
#dhcp-host=11:22:33:44:55:66,ignore
# dhcp所在的domain
domain=debugo.com
# 設(shè)置默認路由出口
dhcp-option=3,192.168.0.1
# 設(shè)置NTP Server.這是使用option name而非選項名來進行設(shè)置
#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5
啟動dnsmasq服務(wù)
service dnsmasq start
下面在客戶端進行測試:
# 確保網(wǎng)絡(luò)接口配置使用dhcp方式
[root@localhost] cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO=dhcp
IPV6INIT=no
NM_CONTROLLED=no
ONBOOT="yes"
TYPE="Ethernet"
# 重啟網(wǎng)絡(luò)服務(wù)
[root@localhost] service network restart
Shutting down interface eth0: [OK]
Shutting down loopback interface: [OK]
Bringing up loopback interface: [OK]
Bringing up interface eth0:
Determining IP information for eth1... done. [OK]
# 檢查IP地址
[root@os03] ifconfig
eth1Link encap:EthernetHWaddr 00:0C:29:15:63:D9
inet addr:192.168.1.202Bcast:192.168.1.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe15:63d9/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:251 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36077 (35.2 KiB)TX bytes:4598 (4.4 KiB)
......
# 檢查默認路由
[root@os03] route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric RefUse Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 000 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth1
配置DNS服務(wù)
DNSmasq能夠緩存外部DNS記錄,同時提供本地DNS解析或者作為外部DNS的代理,即DNSmasq會首先查找/etc/hosts等本地解析文件,然后再查找/etc/resolv.conf等外部nameserver配置文件中定義的外部DNS。所以說dnsmasq是一個很不錯的DNS中繼。DNS配置同樣寫入dnsmasq.conf配置文件里。
# 本地解析文件
#no-hosts
#addn-hosts=/etc/banner_add_hosts
# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
# 例如,/etc/hosts中的os01將擴展成os01.debugo.com
expand-hosts
local=/debugo.com/
# 強制使用完整的解析名
domain-needed
# 添加額外的上級DNS主機(nameserver)配置文件
#resolv-file=
# 不使用上級DNS主機配置文件(/etc/resolv.conf和resolv-file)
no-resolv
# 相應(yīng)的,可以為特定的域名指定解析它的nameserver。一般是其他的內(nèi)部DNS name server
# server=/myserver.com/192.168.0.1
# 設(shè)置DNS緩存大小(單位:DNS解析條數(shù))
cache-size=500
# 關(guān)于log的幾個選項
log-queries
#log-dhcp
log-facility=/var/log/dnsmasq.log
# 異步log,緩解阻塞,提高性能。
log-async=20
# 指定domain的IP地址
address=/doubleclick.net/127.0.0.1
address=/.phobos.apple.com/202.175.5.114
配置完成后重啟dnsmasq,然后在客戶端測試:
[root@os03] nslookup os01.debugo.com
Server:192.168.1.132
Address:192.168.1.132#53
Name:os01.debugo.com
Address: 192.168.1.132
[root@os03] nslookup os02.debugo.com
Server:192.168.1.132
Address:192.168.1.132#53
Name:os02.debugo.com
Address: 192.168.1.201
[root@os03] nslookup doubleclick.net
Server:192.168.1.132
Address:192.168.1.132#53
Name:doubleclick.net
Address: 127.0.0.1
#注意,由于address選項解析為127.0.0.1,而非server的192.168.1.132地址。
[root@os03] nslookup a1.phobos.apple.com
Server:192.168.1.132
Address:192.168.1.132#53
Name:a1.phobos.apple.com
Address: 202.175.5.114
好了,說到這里應(yīng)該都會使用DNSmasq這個小工具了,簡單快捷,下一期,我們再講講如何搭建智能dns。更多精彩》》
本文題目:linux基本服務(wù)系列之DNSmasq的使用
標題URL:http://chinadenli.net/article24/cjieje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、面包屑導(dǎo)航、網(wǎng)站營銷、網(wǎng)站建設(shè)、App設(shè)計、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)