0%

本地dns解析

2016-10-25-dns

dnsmasq

1
yum install -y dnsmasq

默认情况 dnsmasq 读取本地/etc/resolv.conf /etc/hosts 文件,配置文件无须做修改直接启动

修改配置文件

1
2
3
4
5
6
7
8
9
10
vi /etc/dnsmasq.conf
user=dnsmasq #启动账号
group=users #启动组号
interface=eth0 #绑定网络接口
listen-address=192.168.238.135 #绑定IP
bind-interfaces
resolv-file=/etc/resolv.conf #域名解析文件
addn-hosts=/etc/hosts #域名解析文件
log-queries #开启日志查询
log-facility=/var/log/dnsmasq/dnsmasq.log #日志记录位置

编辑域名解析文件

1
echo "192.168.238.135 www.examp;e.com" >> /etc/hosts

启动

1
2
service dnsmasq start
chkconfig dnsmasq on //随机启动

检测

1
2
3
4
5
6
7
8
9
netstat -antop |grep 53

[root@ambari37 ~]# netstat -anop |grep 53
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 7727/dnsmasq off (0.00/0/0)
tcp 0 0 :::53 :::* LISTEN 7727/dnsmasq off (0.00/0/0)
udp 0 0 0.0.0.0:53 0.0.0.0:* 7727/dnsmasq off (0.00/0/0)
udp 0 0 :::53 :::* 7727/dnsmasq off (0.00/0/0)
unix 2 [ ] DGRAM 95352 4027/pickup
unix 3 [ ] STREAM CONNECTED 11253 1192/master
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
yum install -y bind-utils
nslookup

172-10-64-33:~ duanzq$ dig kafka32

; <<>> DiG 9.8.3-P1 <<>> kafka32
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38145
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;kafka32. IN A

;; Query time: 33 msec
;; SERVER: 192.168.100.37#53(192.168.100.37)
;; WHEN: Tue Oct 25 09:56:37 2016
;; MSG SIZE rcvd: 25

172-10-64-33:~ duanzq$

泛域名解析

1
2
vi /etc/dnsmasq.conf
address=/kkk.ptmind.com/118.126.32.53 #随便写一条不存在的域名,指向我们的一个页面!

【ps: addn-hosts=/etc/dnsmasq.hosts 的优先级大于 address=/domain.name/127.0.0.1】

dnsmasq wiki

https://www.freehao123.com/dnsmasq/

bind

https://blog.csdn.net/liang12360640/article/details/45219637