内网Dnsmasq

测试环境:

[root@localhost dnsmasq.d]# cat /etc/redhat-release 
Rocky Linux release 8.3
[root@localhost dnsmasq.d]#

安装dnsmasq

yum -y install dnsmasq

备份默认配置文件

mv /etc/dnsmasq.conf /etc/dnsmasq.conf.rpm

配置dnsmasq

cat <<EOF > /etc/dnsmasq.conf
resolv-file=/etc/resolv.conf
strict-order
addn-hosts=/etc/dnsmasq.d/dnsmasq.hosts
listen-address=127.0.0.1,192.168.31.238
EOF
[root@localhost dnsmasq.d]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.31.1
nameserver fe80::8ac3:97ff:feea:24b5%ens33
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@localhost dnsmasq.d]# 

域名解析

[root@localhost dnsmasq.d]# cat /etc/dnsmasq.d/dnsmasq.hosts
192.168.31.238 ai.27ops.com
[root@localhost dnsmasq.d]#

测试

  • 1.修改适配器DNS

  • 2.在浏览器中输入域名访问

  • 3.查看浏览器中解析到的地址

测试结果如图所示:

dnsmasq