[20161221]快速建立dns伺服器.txt

lfree發表於2016-12-21

[20161221]快速建立dns伺服器.txt

--建立dns對我來講如同噩夢,我記得以前當開始學linux時就配置過一次,裡面引數我根本不熟悉,而且是看這一本書做的,那本書存在印刷
--錯誤,導致自己調式遇到許多問題.所以我對dns的配置一直有點心理上害怕。

--而11Grac需要一個dns,學習一些配置dns非常必要,昨天我重新看了文件,先學習一個簡單的配置就是使用dnsmasq軟體包.感覺它很簡單.

1.環境:

# cat /etc/issue
Oracle Linux Server release 5.9
Kernel \r on an \m

# rpm -qil dnsmasq
Name        : dnsmasq                      Relocations: (not relocatable)
Version     : 2.45                              Vendor: Oracle USA
Release     : 1.1.el5_3                     Build Date: Tue 01 Sep 2009 09:27:24 AM CST
Install Date: Fri 29 Aug 2014 09:30:39 PM CST      Build Host: ca-build9.us.oracle.com
Group       : System Environment/Daemons    Source RPM: dnsmasq-2.45-1.1.el5_3.src.rpm
Size        : 358490                           License: GPL
Signature   : DSA/SHA1, Tue 01 Sep 2009 09:27:36 AM CST, Key ID 66ced3de1e5e0159
URL         :
Summary     : A lightweight DHCP/caching DNS server
Description :
Dnsmasq is lightweight, easy to configure DNS forwarder and DHCP server.
It is designed to provide DNS and, optionally, DHCP, to a small network.
It can serve the names of local machines which are not in the global
DNS. The DHCP server integrates with the DNS server and allows machines
with DHCP-allocated addresses to appear in the DNS with names configured
either in each host or in a central configuration file. Dnsmasq supports
static and dynamic DHCP leases and BOOTP for network booting of diskless
machines.
/etc/dnsmasq.conf
/etc/dnsmasq.d
/etc/rc.d/init.d/dnsmasq
/usr/sbin/dnsmasq
/usr/share/doc/dnsmasq-2.45
/usr/share/doc/dnsmasq-2.45/CHANGELOG
/usr/share/doc/dnsmasq-2.45/COPYING
/usr/share/doc/dnsmasq-2.45/DBus-interface
/usr/share/doc/dnsmasq-2.45/FAQ
/usr/share/doc/dnsmasq-2.45/doc.html
/usr/share/doc/dnsmasq-2.45/setup.html
/usr/share/man/man8/dnsmasq.8.gz

-- 感覺這個就足夠了.很明顯配置檔案/etc/dnsmasq.conf與目錄/etc/dnsmasq.d。
# rpm -qc dnsmasq
/etc/dnsmasq.conf

2.我需要配置的IP如下:
#SCAN IP
#192.168.200.101 xxxscan
#192.168.200.102 xxxscan
#192.168.200.103 xxxscan

--//僅僅3個scan-ip.

3.修改/etc/resolv.conf,加入名字伺服器:
# cat /etc/resolv.conf
search localdomain
nameserver 192.168.100.78
nameserver 192.168.101.7

--也就是本機(192.168.100.78,這行要寫在前面,我不知道為什麼??),如果你存在別的dns伺服器,可以在這裡加入:

4.配置/etc/dnsmasq.conf檔案:
# grep -v "^#" /etc/dnsmasq.conf | grep '^[a-zA-Z]'
conf-dir=/etc/dnsmasq.d

--僅僅1行,其他全是註解,注:如果改動建立做1個備份.
--我修改如下註解上面那行,加入:
# cat /etc/dnsmasq.conf
# conf-dir=/etc/dnsmasq.d
addn-hosts=/etc/dnsmasq.d/rachosts

5.建立/etc/dnsmasq.d/rachosts檔案,包括全部需要解析的主機名.
# cat   /etc/dnsmasq.d/rachosts
192.168.200.101  xxxscan
192.168.200.102  xxxscan
192.168.200.103  xxxscan

--實際上步驟很簡單就是包括1個全部機器的文字檔案,加入addn-hosts=/etc/dnsmasq.d/rachosts這行在配置檔案中.

6.啟動dbsmasq:
# service dnsmasq start
Starting dnsmasq:          [  OK  ]

6.測試:
# nslookup xxxscan
Server:         192.168.100.78
Address:        192.168.100.78#53

Name:   xxxscan
Address: 192.168.200.103
Name:   xxxscan
Address: 192.168.200.101
Name:   xxxscan
Address: 192.168.200.102

# nslookup 192.168.200.101
Server:         192.168.100.78
Address:        192.168.100.78#53

101.200.168.192.in-addr.arpa    name = xxxscan.

# nslookup 192.168.200.102
Server:         192.168.100.78
Address:        192.168.100.78#53

102.200.168.192.in-addr.arpa    name = xxxscan.

# nslookup 192.168.200.103
Server:         192.168.100.78
Address:        192.168.100.78#53

103.200.168.192.in-addr.arpa    name = xxxscan.

# nslookup 127.0.0.1
Server:         192.168.100.78
Address:        192.168.100.78#53

1.0.0.127.in-addr.arpa  name = localhost.localdomain.

# nslookup localhost
Server:         192.168.100.78
Address:        192.168.100.78#53

Name:   localhost.localdomain
Address: 127.0.0.1

--//這樣配置小型的dns簡單多了,快捷簡單實用。

7.其他機器僅僅需要配置:
# cat   /etc/resolv.conf
nameserver 192.168.100.78

--我參考了連結:
--按照他的說明,你什麼都不要做,僅僅將主機列表寫入/etc/hosts檔案就ok了.我自己也測試1次確實這樣.剩下僅僅啟動dnsmasq服務.
--我覺得這個太合適小網路的配置了.根本無需瞭解dns細節.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2131095/,如需轉載,請註明出處,否則將追究法律責任。

相關文章