1、resolv.conf

/etc/resolv.conf 文件里面的dns服务器是实时生效的,发现ubuntu18.04和Centos系列的差别很大,ubuntu18.04是个软链接并建议不要去修改;centos系列是个配置文件,可以直接修改使用。

2、resolvconf 默认软链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
user@ubuntu:~$ ls -lh /etc/resolv.conf 
lrwxrwxrwx 1 root root 27 10月 22 2018 /etc/resolv.conf -> /run/resolvconf/resolv.conf

user@ubuntu:~$ netstat -tulpn|grep 53
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
udp 0 0 127.0.0.53:53 0.0.0.0:* -

user@ubuntu:~$ cat /run/resolvconf/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
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 114.114.114.114
nameserver 127.0.0.53

user@ubuntu:~$ cat /run/resolvconf/interface/eth0.inet
nameserver 114.114.114.114
mogo@mogo-desktop:~$ cat /run/resolvconf/interface/systemd-resolved
nameserver 127.0.0.53

3、systemd-resloved 修改软链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
user@ubuntu:~$ ls -lh /etc/resolv.conf 
lrwxrwxrwx 1 root root 27 10月 22 2018 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf

user@ubuntu:~$ cat /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
DNS=192.168.1.1
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes


user@ubuntu:~$ cat /run/systemd/resolve/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 192.168.1.1


user@ubuntu:~$ cat /run/systemd/resolve/stub-resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0

4、network-manager(图形界面)/network(服务器) 图形界面时可以直接桌面修改dns。如果不是图形界面直接network服务控制的/etc/network/interfaces配置文件dns-nameservers参数可以配置。经过测试,以上所有服务都开启时,systemd-resolved优先级大于network-manager。 综上可以推荐使用第三个systemd-resloved服务的软链接,通过修改/etc/systemd/resolved.conf配置文件来定义dns服务器,默认该服务是开机启动的。