影響ubuntu18.04系統DNS的幾個因素

1、resolv.conf

/etc/resolv.conf 文件裏面的dns服務器是實時生效的,發現ubuntu18.04和Centos系列的差別很大,ubuntu18.04是個軟鏈接並建議不要去修改;centos系列是個配置文件,可以直接修改使用。

2、resolvconf
默認軟鏈接

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
修改軟鏈接

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服務器,默認該服務是開機啓動的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章