机器人 救救瓜
Toggle navigation
Home
SCM-tool
Linux
Jenkins
SVN
other
About Me
Archives
Tags
搭建DNS服务 dnsmasq
2020-04-28 15:32:23
920
0
0
gua_l
### 系统:ubuntu ### 软件:dnsmasq ### 安装: apt-get install -y dnsmasq ### 配置 /etc/dnsmasq.conf: root@node248:/etc/resolvconf/resolv.conf.d# cat /etc/dnsmasq.conf | grep -v "^#\|^$" port=53 resolv-file=/etc/resolv.conf strict-order listen-address=172.0.11.248 addn-hosts=/etc/hosts ### 配置 /etc/hosts root@node248:/etc/resolvconf/resolv.conf.d# cat /etc/hosts #..... 172.0.11.2 vm2 172.0.11.3 vm3 172.0.11.4 vm4.com ### 配置 上游 nameserver 1. 使用服务器本身的dns 列表,则resolv-file=/etc/resolv.conf 2. 使用服务器上另外的dns 列表文件,即上游dns,则resolv-file=/etc/dnsmasq.d/ 此目录下放置 *conf ### 重启服务: #14 service dnsmasq restart #18 systemctl restart dnsmasq ### 解析过程: 客户端将此服务器ip 设置为dns 之后,查找域名时,会通过服务器的/etc/hosts 去解析域名,然后再通过resolv-file 中列的dns 去解析。 ### 附不同ubuntu系统dns-nameserver的设置: UBUNTU 14 root@vm1:/etc/dnsmasq.d# cat /etc/resolvconf/resolv.conf.d/base nameserver 172.0.11.248 root@vm1:/etc/dnsmasq.d# cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 172.0.11.248 测试中发现 ubuntu 14 的resolv.conf 总是被 重写, 解决: ``` # 查看 interfaces 配置的DNS root@node248:/etc/resolvconf# cat /etc/network/interfaces| grep dns dns-nameservers 8.8.8.8 # 查看run 下 interface 目录加载的有效 dns 信息 root@node248:/etc/resolvconf# ls /run/resolvconf/interface/ eth0.inet lo.dnsmasq # 查看 eth0 的dns 是否加载正确 root@node248:/etc/resolvconf# cat /run/resolvconf/interface/eth0.inet nameserver 8.8.8.8 # 查看 etc 下 的interface-order 里是否加入了eth0.net cat /etc/resolvconf/interface-order | grep eth0 # 结果是没有这一行,加入,resolv.conf 会按排列顺序自动追加这些dns 条目 root@node248:/etc/resolvconf# cat /etc/resolvconf/interface-order | grep eth0 eth0.inet ``` UBUNTU 18/19 root@vm2:~# cat /etc/netplan/01-netcfg.yaml # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: ens3: addresses: [172.0.11.173/24] gateway4: 172.0.11.1 nameservers: addresses: [172.0.11.248] dhcp4: no dhcp6: no netplan appply systemd-resolve --status ### 客户机测试: 一台机器vm8已经配置了上面的dns 服务器172.0.11.248 作为DNS,仅一个dns 在vm8 上,ping 11.248 hosts 里的主机名 ping vm4.com 在vm8 上,ping www.baidu.com ping www.baidu.com 1. vm4.com 能通过172.0.11.248的addn-hosts=/etc/hosts解析到ip . 2. www.baidu.coma能通过172.0.11.248的 resolv-file=/etc/resolv.conf解析到ip .
Pre:
Accurev 创建 stream
Next:
FluxCD
0
likes
920
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.