DNSmasq是一个小巧且方便地用于配置DNS和DHCP的工具,适用于小型网络,它提供了DNS功能和可选择的DHCP功能。它服务那些只在本地适用的域名,这些域名是不会在全球的DNS服务器中出现的(摘自百度百科)
环境:Centos7
一、服务端配置
1.使用yum安装dnsmasq
yum install dnsmasq
2.配置/etc/dnsmasq.conf
可以配置得很简单,只需要配置监听的IP和配置文件路径即可
listen-address=127.0.0.1,192.168.233.132
conf-dir=/etc/dnsmasq.d
3.配置映射文件
在/etc/dnsmasq.d目录下创建IP域名映射文件,文件名可以随意取,且可以多个,如:
[root@fl /etc/dnsmasq.d] $ cat address.conf
address=/redis/192.168.233.128
address=/mongodb/192.168.233.132
4.启动服务
systemctl start dnsmasq
5.防火墙中开通DNS服务端口
firewall-cmd --permanent --add-port=53/tcp
firewall-cmd --permanent --add-port=53/udp
firewall-cmd --reload
二、客户端配置
客户端只需要在/etc/resolv.conf中配置DNS服务地址就好了,如:
nameserver 192.168.233.132
测试
按照上面的配置后,客户端就可以解析DNS服务端配置的域名了
[root@fl /] $ping redis
PING redis (192.168.233.128) 56(84) bytes of data.
64 bytes from fl (192.168.233.128): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from fl (192.168.233.128): icmp_seq=2 ttl=64 time=0.076 ms
64 bytes from fl (192.168.233.128): icmp_seq=3 ttl=64 time=0.090 ms
^C
--- redis ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 11016ms
rtt min/avg/max/mdev = 0.017/0.061/0.090/0.031 ms
[root@fl /] $ping mongodb
PING mongodb (192.168.233.132) 56(84) bytes of data.
64 bytes from fl (192.168.233.132): icmp_seq=1 ttl=64 time=0.228 ms
64 bytes from fl (192.168.233.132): icmp_seq=2 ttl=64 time=0.977 ms
^C
--- mongodb ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.228/0.602/0.977/0.375 ms