centos6 名字服务dnsmasq配置

1 主机名配置

主机hd1配置(后面配置为名字服务器)

[grid_hd@hd1 Desktop]$ cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=hd1.asn.cn #主机名为hd1.asn.cn (asn.cn为搜索域)

 

[grid_hd@hd1 Desktop]$ cat /etc/hosts

127.0.0.1     localhost     localhost.localdomain

 

客户机hd2配置:

[grid_hd@hd2 Desktop]$ cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=hd2.asn.cn

 

[grid_hd@hd2 Desktop]$ cat /etc/hosts

127.0.0.1     localhost     localhost.localdomain

 

客户机hd3配置:

[grid_hd@hd3 Desktop]$ hostname

hd3.asn.cn

[grid_hd@hd3 Desktop]$ cat /etc/hosts

127.0.0.1    localhost     localhost.localdomain

 

 

2 名字服务配置

dnsmasq

[grid_hd@hd1 Desktop]$ sudo find / -name *dnsmasq*

/var/lock/subsys/dnsmasq

/var/run/dnsmasq.pid #进程PID文件

/var/lib/dnsmasq

/etc/dnsmasq.d ##放入该目录的文件将作为配置文件自动加载

/etc/dnsmasq ##自己创建的目录,用于存放上游名字服务列表文件resolv.conf和主机名到IP的映射文件hosts

/etc/dbus-1/system.d/dnsmasq.conf

/etc/selinux/targeted/modules/active/modules/dnsmasq.pp

/etc/dnsmasq.conf ##dnsmasq的主配置文件

 

/etc/rc.d/rc0.d/K50dnsmasq ##指向脚本文件/etc/rc.d/init.d/dmsmasq的软连接

/etc/rc.d/rc1.d/K50dnsmasq

/etc/rc.d/rc2.d/K50dnsmasq

/etc/rc.d/rc3.d/K50dnsmasq

/etc/rc.d/rc4.d/K50dnsmasq

/etc/rc.d/rc5.d/K50dnsmasq

/etc/rc.d/rc6.d/K50dnsmasq

 

 

/etc/rc.d/init.d/dnsmasq ##dnsmasq的启停控制Shell脚本文件{start|stop|restart|reload|condrestart|status}

/usr/sbin/dnsmasq ##dnsmasq服务程序二进制文件

 

 

[grid_hd@hd1 ~]$ ll /etc/rc.d/rc5.d/K50dnsmasq

lrwxrwxrwx. 1 root root 17 Jul 18 21:11 /etc/rc.d/rc5.d/K50dnsmasq -> ../init.d/dnsmasq ##指向脚本文件/etc/rc.d/init.d/dmsmasq

 

启动脚本文件/etc/rc.d/init.d/dnsmasq

#!/bin/sh

#

# Startup script for the DNS caching server

#

# chkconfig: - 49 50

# description: This script starts your DNS caching server 该脚本启动你的DNS缓存服务

# processname: dnsmasq

# pidfile: /var/run/dnsmasq.pid

 

# Source function library.

. /etc/rc.d/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

 

dnsmasq=/usr/sbin/dnsmasq #定义dnsmasq变量

[ -f $dnsmasq ] || exit 0

 

DOMAIN_SUFFIX=`dnsdomainname`

if [ ! -z "${DOMAIN_SUFFIX}" ]; then

OPTIONS="-s $DOMAIN_SUFFIX" #定义OPTIONS变量

fi

 

RETVAL=0 #定义RETVAL变量

 

PIDFILE="/var/run/dnsmasq.pid" #定义PIDFILE变量

 

# See how we were called.

case "$1" in #$0程序名,$1代表第一参数

#如果输入参数是start

start)

if [ $UID -ne 0 ] ; then

echo "User has insufficient privilege."

exit 4

fi

echo -n "Starting dnsmasq: "

daemon $dnsmasq $OPTIONS

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dnsmasq

;;

#如果输入参数是stop

stop)

if test "x`pidfileofproc dnsmasq`" != x; then

echo -n "Shutting down dnsmasq: "

killproc dnsmasq

fi

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dnsmasq $PIDFILE

;;

 

status)

status -p $PIDFILE dnsmasq

RETVAL=$?

;;

 

reload)

if test "x`pidfileofproc dnsmasq`" != x; then

echo -n "Reloading dnsmasq: "

killproc dnsmasq -HUP

fi

RETVAL=$?

echo

;;

 

 

force-reload)

# new configuration takes effect only after restart

$0 stop

$0 start

RETVAL=$?

;;

 

 

restart)

$0 stop

$0 start

RETVAL=$?

;;

 

 

condrestart)

if test "x`pidfileofproc dnsmasq`" != x; then

$0 stop

$0 start

RETVAL=$?

fi

;;

 

 

*)

echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"

exit 2

 

esac #

 

exit $RETVAL

 

 

 

/etc

├── dnsmasq

│      ├── hosts

│      ├── resolv.conf

├── dnsmasq.conf

├── dnsmasq.d

 

 

配置

/etc/dnsmasq.conf

[grid_hd@hd1 ~]$ cat /etc/dnsmasq.conf

# Change this line if you want dns to get its upstream servers from somewhere other that /etc/resolv.conf

# 如果你想让dns从某个地方(而不是/etc/resolv.conf)获得上游服务

resolv-file=/etc/dnsmasq/resolv.conf ##从/etc/dnsmasq/resolv.conf文件中获得上游DNS服务的IP地址

 

# By default, dnsmasq will send queries to any of the upstream servers it knows about

# 默认dnsmasq会把查询请求发送到它知道的任意一个上游DNS服务器

# and tries to favour servers to are known to be up.

# Uncommenting this forces dnsmasq to try each query with each server strictly in the order they appear in /etc/resolv.conf

# 解注该行,强制dnsmasq严格以/etc/resolv.conf文件中每个服务的出现顺序尝试查询

strict-order

 

# Or which to listen on by address (remember to include 127.0.0.1 if you use this.)

listen-address=192.168.145.151,127.0.0.1

 

 

# For debugging purposes, log each DNS query as it passes through dnsmasq.

log-queries

 

 

# If you don't want dnsmasq to read /etc/hosts, uncomment the following line.

no-hosts

 

# or if you want it to read another file, as well as /etc/hosts, use this.

addn-hosts=/etc/dnsmasq/hosts

 

/etc/dnsmasq/resolv.conf 配置上游名字服务的IP地址

[grid_hd@hd1 ~]$ cat /etc/dnsmasq/resolv.conf

nameserver    192.168.145.2

nameserver    8.8.8.8

nameserver    8.8.4.4

 

/etc/dnsmasq/hosts 自定义的域名(主机名,名字)到IP映射

[grid_hd@hd1 ~]$ cat /etc/dnsmasq/hosts

192.168.145.151        hd1.asn.cn    hd1

192.168.145.152        hd2.asn.cn    hd2

192.168.145.153        hd3.asn.cn    hd3

 

查看/etc/resolv.conf

[grid_hd@hd1 ~]$ cat /etc/resolv.conf

# Generated by NetworkManager

search asn.cn

nameserver 127.0.0.1 ##遇到不认识的名字,首先本地解释,然后再找上游服务器

 

重启

[grid_hd@hd1 ~]$ sudo service dnsmasq restart

Shutting down dnsmasq: [ OK ]

Starting dnsmasq: [ OK ]

 

 

 

 

 

设置开机自启

[grid_hd@hd1 ~]$ sudo chkconfig --list dnsmasq

dnsmasq     0:off    1:off    2:off    3:off    4:off    5:off    6:off

[grid_hd@hd1 ~]$ sudo chkconfig dnsmasq on

[grid_hd@hd1 ~]$ sudo chkconfig --list dnsmasq

dnsmasq     0:off    1:off    2:on    3:on    4:on    5:on    6:off

 

 

本机测试

[grid_hd@hd1 ~]$ dig archive.cloudera.com

 

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.2 <<>> archive.cloudera.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56484

;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 4, ADDITIONAL: 4

 

;; QUESTION SECTION:

;archive.cloudera.com.        IN    A

 

;; ANSWER SECTION:

archive.cloudera.com.    5    IN    CNAME    j.global-ssl.fastly.net.

j.global-ssl.fastly.net. 5    IN    A    199.27.79.68

 

;; AUTHORITY SECTION:

fastly.net.        5    IN    NS    ns3.p04.dynect.net.

fastly.net.        5    IN    NS    ns4.p04.dynect.net.

fastly.net.        5    IN    NS    ns1.p04.dynect.net.

fastly.net.        5    IN    NS    ns2.p04.dynect.net.

 

;; ADDITIONAL SECTION:

ns1.p04.dynect.net.    5    IN    A    208.78.70.4

ns2.p04.dynect.net.    5    IN    A    204.13.250.4

ns3.p04.dynect.net.    5    IN    A    208.78.71.4

ns4.p04.dynect.net.    5    IN    A    204.13.251.4

 

;; Query time: 337 msec

;; SERVER: 127.0.0.1#53(127.0.0.1)

;; WHEN: Sun Aug 9 22:24:29 2015

;; MSG SIZE rcvd: 238

 

 

 

[grid_hd@hd1 ~]$ dig archive.cloudera.com

 

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.2 <<>> archive.cloudera.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24829

;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 4, ADDITIONAL: 4

 

;; QUESTION SECTION:

;archive.cloudera.com.        IN    A

 

;; ANSWER SECTION:

archive.cloudera.com.    5    IN    CNAME    j.global-ssl.fastly.net.

j.global-ssl.fastly.net. 5    IN    A    199.27.79.68

 

;; AUTHORITY SECTION:

fastly.net.        5    IN    NS    ns4.p04.dynect.net.

fastly.net.        5    IN    NS    ns1.p04.dynect.net.

fastly.net.        5    IN    NS    ns2.p04.dynect.net.

fastly.net.        5    IN    NS    ns3.p04.dynect.net.

 

;; ADDITIONAL SECTION:

ns1.p04.dynect.net.    5    IN    A    208.78.70.4

ns2.p04.dynect.net.    5    IN    A    204.13.250.4

ns3.p04.dynect.net.    5    IN    A    208.78.71.4

ns4.p04.dynect.net.    5    IN    A    204.13.251.4

 

;; Query time: 5 msec

;; SERVER: 127.0.0.1#53(127.0.0.1) ##从本地获得解释

;; WHEN: Sun Aug 9 22:24:38 2015

;; MSG SIZE rcvd: 238

 

 

客户机hd2配置、使用

 

[grid_hd@hd2 Desktop]$ dig archive.cloudera.com

 

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.2 <<>> archive.cloudera.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43528

;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 4, ADDITIONAL: 4

 

;; QUESTION SECTION:

;archive.cloudera.com.        IN    A

 

;; ANSWER SECTION:

archive.cloudera.com.    5    IN    CNAME    j.global-ssl.fastly.net.

j.global-ssl.fastly.net. 5    IN    A    23.235.47.68

 

;; AUTHORITY SECTION:

fastly.net.        5    IN    NS    ns4.p04.dynect.net.

fastly.net.        5    IN    NS    ns3.p04.dynect.net.

fastly.net.        5    IN    NS    ns2.p04.dynect.net.

fastly.net.        5    IN    NS    ns1.p04.dynect.net.

 

;; ADDITIONAL SECTION:

ns1.p04.dynect.net.    5    IN    A    208.78.70.4

ns2.p04.dynect.net.    5    IN    A    204.13.250.4

ns3.p04.dynect.net.    5    IN    A    208.78.71.4

ns4.p04.dynect.net.    5    IN    A    204.13.251.4

 

;; Query time: 192 msec

;; SERVER: 192.168.145.151#53(192.168.145.151) ##从配置的主机hd1获得解释

;; WHEN: Sun Aug 9 22:30:14 2015

;; MSG SIZE rcvd: 238

转载于:https://www.cnblogs.com/asnjudy/p/4716557.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值