Ubuntu18.04LTS的⽹络经常变成问号导致⽹速很慢的解决办法问题描述:
Ubuntu系统Gnome桌⾯顶部栏的⽹络图标经常变成了⼀个问号。期间不能打开⽹页,在终端⾥⾯ping公⽹有时能通但丢包严重,或者根本就不通,错误提⽰Temporary failure in name resolution,表⽰域名解析失败。
问题原因:
Ubuntu默认安装的DNS解析⼯具systemd-resolved存在问题;
系统频繁对⽹络信号进⾏连接检查,导致不能联⽹。
解决办法:
⼀、将DNS解析⼯具从systemd-resolved切换为unbound
1、安装unbound
sudo apt-get install unbound
2、安装resolvconf
sudo apt-get install resolvconf
3、禁⽤默认域名解析⼯具systemd-resolved并停⽌正在运⾏的程序
sudo systemctl disable systemd-resolved.service
sudo systemctl disable systemd-resolved
4、配置NetworkManager,使其使⽤unbound作为系统的域名解析⼯具
sudo vim /etc/f
在该配置⽂件中,紧跟plugins在下⾯⼀⾏加上dns=unbound:
[main]
plugins=ifupdown,keyfile
dns=unbound
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
5、⼿动启⽤unbound
sudo systemctl enable unbound-resolvconf
sudo systemctl enable unbound
6、修改unbound配置⽂件/etc/f
查看f的manual页⾯
f
可以看到有以下⼀段内容:
server:
directory: "/etc/unbound"
username: unbound
# make sure unbound can access entropy from inside the chroot.
# e.g. on linux the use these commands (on BSD, devfs(8) is used):
# mount --bind -n /dev/random /etc/unbound/dev/random
# and mount --bind -n /dev/log /etc/unbound/dev/log
chroot: "/etc/unbound"
# logfile: "/etc/unbound/unbound.log" #uncomment to use logfile.
pidfile: "/etc/unbound/unbound.pid"
# verbosity: 1 # uncomment and increase to get more logging.
# listen on all interfaces, answer queries from the local subnet.
interface: 0.0.0.0
interface: ::0
access-control: 10.0.0.0/8 allow
access-control: 2001:DB8::/64 allow
把这段配置内容追加到⽂件/etc/f中:
# Unbound configuration file for Debian.
#
# See f(5) man page.
#
# See /usr/share/doc/unbound/f for a commented
# reference config file.
#
# The following line includes additional configuration files from the
# /etc/f.d directory.
include: "/etc/f.d/*.conf"
directory: "/etc/unbound"
username: unbound
# make sure unbound can access entropy from inside the chroot.
# e.g. on linux the use these commands (on BSD, devfs(8) is used):
# mount --bind -n /dev/random /etc/unbound/dev/random
# and mount --bind -n /dev/log /etc/unbound/dev/log
chroot: "/etc/unbound"
# logfile: "/etc/unbound/unbound.log" #uncomment to use logfile.
pidfile: "/etc/unbound/unbound.pid"
# verbosity: 1 # uncomment and increase to get more logging.
# listen on all interfaces, answer queries from the local subnet.
interface: 0.0.0.0
interface: ::0
access-control: 10.0.0.0/8 allow
access-control: 2001:DB8::/64 allow
7、修改resolvconf配置⽂件/etc/f.d/tail
查看unbound的manual页⾯,可以看到有以下⼀段内容:
To use a locally running Unbound for resolving put
nameserver 127.0.0.1
f(5).ubuntu网络配置
这⾥意思是,要使⽤某⼀个域名服务器,就要将该服务器的键值对写⼊到/f中。⽐如要使⽤本地的unbound程序做域名解析,就把nameserver 127.0.0.1加⼊到⽂件/f中。
但是我们打开⽂件/f,发现⽂件头部的描述如下:
# f(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.
这⾥说明⽂件/f的内容是⼜resolvconf软件⽣成的,⼿动修改只能临时起作⽤,⼀旦主机重启⽂件中的内容就会消失。因此我们必须在resolvconf软件中到配置该⽂件的配置⽂件。
查看resolvconf软件的manual页⾯,我们发现了如下内容:
FILES
/etc/default/resolvconf
See the ENVIRONMENT VARIABLES section.
/etc/resolvconf/interface-order
Determines the order of precedence of nameserver addresses and
search domain names. See above and interface-order(5).
/etc/f.d/base
File containing basic resolver information. The lines in this
file are included in the resolver configuration file even when
no interfaces are configured.
/etc/f.d/head
File to be prepended to the dynamically generated resolver con‐
figuration file. Normally this is just a comment line.
/etc/f.d/tail
File to be appended to the dynamically generated resolver con‐
figuration file. To append nothing, make this an empty file.
This file is a good place to put a resolver options line if one
is needed, e.g.,
/etc/f.d/original
Copy of the /f file before the resolvconf package
was installed. This file has no effect on the functioning of
resolvconf; it is retained so that /f can be
restored to its original state if the resolvconf package is
removed.
Note also that a copy of this file is included in the database
until the first reboot after installation of the resolvconf
package; this ensures that nameservers reachable before instal‐
lation of resolvconf are still reachable after installation of
resolvconf even though at that point not all suppliers of name‐
server information may have supplied their information to
resolvconf(8).
Note also that the administrator can choose to create a symbolic
link in /etc/f.d/ from tail to original so
that the contents of original are always added to the end of the
dynamically generated file.
从中到⽂件 /etc/f.d/tail,该⽂件⽤来⽣成/f的配置⽂件质之⼀。
在⽂件 /etc/f.d/tail中加⼊需要的键值对之后,重启主机就能在⽂件/f中看到配置好的DNS:
nameserver 119.29.29.29
nameserver 233.5.5.5
nameserver 114.114.114.114
nameserver 1.1.1.1
⽬前可⽤的DNS主要有以下:
腾讯的公⽤免费DNS: 119.29.29.29(⾸选)、182.254.116.116(备选)
阿⾥的公⽤免费DNS: 233.5.5.5(⾸选)、233.6.6.6(备选)
国内移动、电信和联通通⽤的公⽤免费DNS: 114.114.114.114
Cloudflare的公⽤免费DNS: 1.1.1.1(⾸选)、1.0.0.1(备选)
⼆、关闭系统的⽹络连接检查
⽹络信号的连接检查是导致WiFi图标经常变成问号的原因,不过这种状态下并不影响主机的⽹络连接,只是⽐较影响⼼情。
这⾥的⽅法是:进⼊设置-》隐私-》关闭连接检查。
三、如果不关闭⽹络连接检查可以配置⽂件/etc/ppp/options
这⾥的解决⽅法参考⼀篇博客
/etc/PPP/options其中的lcp-echo-failure默认设为4,lcp-echo-interval设为30秒,也就是说如果120秒钟之内ADSL⽹络服务器没有回echo-reply信号。
可能是国内ADSL⽹络本⾝的问题,服务器好像是不会回echo-reply信号(有待考证)或者很长时间才会回echo-reply信号。所以可以把上⾯两个参数适当地调⼤⼀些。
打开配置⽂件/etc/ppp/options
sudo vim /etc/ppp/options
在options⽂件中到以下两⾏代码
lcp-echo-failure 4
lcp-echo-interval 30
把lcp-echo-failure 4改为lcp-echo-failure 15
重启主机使配置⽣效
其他参考资料:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论