Update history
2021-01-10 初稿。最近拼多多搞得太过分了,打工人们要联合起来呀
Dnsmasq
为什么要安装 DNS 呢? 因为上一篇 blog, 自定义的 domain 需要在每台机器上修改 hosts,有一点麻烦,干脆就直接在测试环境,搭建一个 DNS 服务器
stop systemd-resolve
- ubuntu 上面 systemd-resolve 会修改 /etc/resolv.conf 详情请看 https://www.cnblogs.com/breezey/p/9155988.html
- centos 上面 networkmanager 会修改 /etc/resolv.conf 这里有两种做法:
- 从源头上修改,这样每次上面 networkmanager 生成的话也是正确的 https://ma.ttias.be/centos-7-networkmanager-keeps-overwriting-etcresolv-conf/
- 禁止 networkmanager 修改 dns 参考 https://wiseindy.com/blog/linux/how-to-set-dns-in-centos-rhel-7-prevent-network-manager-from-overwriting-etc-resolv-conf/
1 | sudo systemctl disable systemd-resolved |
Install
1 | sudo apt-get install dnsmasq |
Adding DNS records
因为我们没有修改 resolv-file, 默认的就是 /etc/hosts
1 | root@ubuntu20:/home/feiyang# cat /etc/hosts |
重启 dnsmasq
1 | systemctl restart dnsmasq |
test
Ubuntu 20 为 DNS 服务器, 用 Ubuntu18 和 centos7 来进行测试,结果如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22root@ubuntu18:/home/feiyang# nslookup haha.feiyang.com
Server: 192.168.17.5
Address: 192.168.17.5#53
Name: haha.feiyang.com
Address: 233.233.233.233
[jy576@centos7 ~]$ nslookup gitlab.feiyang.com
Server: 192.168.17.5
Address: 192.168.17.5#53
Name: gitlab.feiyang.com
Address: 192.168.17.3
[jy576@centos7 ~]$ nslookup free.dns.com
Server: 192.168.17.5
Address: 192.168.17.5#53
Name: free.dns.com
Address: 1.1.1.1
Reference
DNS takeover