Ubuntu 18.04 LTS的网络经常变成问号导致网速很慢的解决办法

问题描述:

Ubuntu系统Gnome桌面顶部栏的网络图标经常变成了一个问号。期间不能打开网页,在终端里面ping公网有时能通但丢包严重,或者根本就不通,错误提示 Temporary failure in name resolution,表示域名解析失败。

问题原因:

  • Ubuntu默认安装的DNS解析工具systemd-resolved存在问题;
  • 系统频繁检查网络信号连接,导致无法上网。
    [En]

    the system frequently checks the connection of network signals, which makes it impossible to connect to the Internet.*

解决办法:

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/NetworkManeger/NetworkManager.conf

在该配置文件中,紧跟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/unbound/unbound.conf

查看unbound.conf的manual页面

man unbound.conf

你可以看到下面这段话:

[En]

You can see the following paragraph:

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/unbound/unbound.conf中:

Unbound configuration file for Debian.

#
See the unbound.conf(5) man page.

#
See /usr/share/doc/unbound/examples/unbound.conf for a commented
reference config file.

#
The following line includes additional configuration files from the
/etc/unbound/unbound.conf.d directory.

include: "/etc/unbound/unbound.conf.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/resolconf/resolv.conf.d/tail

查看unbound的manual页面,可以看到有以下一段内容:

To use a locally running Unbound for resolving put

             nameserver 127.0.0.1

into resolv.conf(5).

这里意思是,要使用某一个域名服务器,就要将该服务器的键值对写入到 /etc/resolv.conf中。比如要使用本地的unbound程序做域名解析,就把 nameserver 127.0.0.1加入到文件 /etc/resolv.conf中。

但是我们打开文件 /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
127.0.0.53 is the systemd-resolved stub resolver.

run "systemd-resolve --status" to see details about the actual nameservers.

这里说明文件 /etc/resolv.conf的内容是又 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/resolvconf/resolv.conf.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/resolvconf/resolv.conf.d/head
              File  to be prepended to the dynamically generated resolver con‐
              figuration file.  Normally this is just a comment line.

       /etc/resolvconf/resolv.conf.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/resolvconf/resolv.conf.d/original
              Copy  of the /etc/resolv.conf file before the resolvconf package
              was installed.  This file has no effect on  the  functioning  of
              resolvconf;  it  is  retained  so  that  /etc/resolv.conf 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/resolvconf/resolv.conf.d/ from tail to original  so
              that the contents of original are always added to the end of the
              dynamically generated file.

从中找到文件 /etc/resolvconf/resolv.conf.d/tail,该文件用来生成 /etc/resolv.conf的配置文件质之一。

在文件 /etc/resolvconf/resolv.conf.d/tail中加入需要的键值对之后,重启主机就能在文件 /etc/resolv.conf中看到配置好的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(备选)

/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
  • 重启主机使配置生效

Original: https://www.cnblogs.com/letsplayball/p/15542322.html
Author: 拍呀拍皮球
Title: Ubuntu 18.04 LTS的网络经常变成问号导致网速很慢的解决办法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/524375/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Windows 常用 Dos PowerShell 命令

    Dos #^.^ dir /a/s/p PowerShell #批量重命名文件 dir -Recurse *.png | foreach {Rename-Item $_ -NewN…

    Linux 2023年5月28日
    087
  • cobbler

    cobbler 1. cobbler简介 2. cobbler服务端部署 cobbler简介 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速…

    Linux 2023年6月7日
    076
  • 解析库的使用

    使用 Xpath 使用 pyquery from pyquery import PyQuery as pq doc = pq(html) print(doc) PyQuery对象可…

    Linux 2023年6月7日
    087
  • shell 中的EOF

    EOF是(END Of File)的缩写,表示自定义终止符。既然自定义,那么EOF就不是固定的,可以随意设置别名,在linux按ctrl-d 就代表EOF。EOF一般会配合cat能…

    Linux 2023年5月28日
    0103
  • APACHE快速安装流程梳理

    快速安装开始: 【环境配置1】 yum -y install gcc gcc-c++ wget 保留操作(可跳过): yum -y removeapr-util-devel apr…

    Linux 2023年6月6日
    086
  • Python 定义类时候加括号和不加括号的区别

    新式类与经典类 只有python2.x 中有新式类和经典类的说法,而python3.x 没有,因为其默认都是新式类 python2.x 中默认都是经典类,只有显式的继承了objec…

    Linux 2023年6月7日
    068
  • 冯·诺依曼体系结构

    cpu运算速度>寄存器速度>L1~L3Cache>内存>外设(磁盘)>光盘 外设(输入设备、输出设备)不和cpu直接数据交换 cpu直接和内存数据交换…

    Linux 2023年6月13日
    090
  • 网络设备配置–7、配置单臂路由实现跨vlan通信

    一、前言 同系列前几篇:网络设备配置–1、配置交换机enable、console、telnet密码网络设备配置–2、通过交换机划分vlan网络设备配置&#8…

    Linux 2023年6月8日
    0102
  • Ubuntu系统中防火墙的使用和开放端口

    sudo sudo apt-get install ufw sudo ufw status inactive: 不活跃,未开启 active:开启 sudo ufw enable …

    Linux 2023年5月27日
    079
  • spring boot实现不同生产环境下的文件配置

    spring boot项目开发时不同开发环境,打包生成不同的文件。(避免生产环境得到开发环境时的配置文件) 配置不同生产环境 本文适用于开发环境下需要打包项目至生产环境,避免开发环…

    Linux 2023年6月7日
    086
  • shell升级完整记录

    [root@localhost bash-4.3.30]# cat Makefile |grep prefix prefix = /usr/local exec_prefix = …

    Linux 2023年5月28日
    072
  • redisobject详解

    typedef struct redisObject { unsigned type:4; unsigned encoding:4; unsigned lru:REDIS_LRU_…

    Linux 2023年5月28日
    0101
  • vnc复制粘贴与禁止

    1.ubuntu服务器中安装了vncserver,启动服务。在另外一台机器上访问服务器,可以在服务器终端中执行vncconfig -nowin&(或者vncconfig&a…

    Linux 2023年6月13日
    084
  • Java引用类型

    1 强引用 当我们使用new创建对象时,被创建的对象就是强引用。只要有强引用,GC 永远不会回收掉该对象。 Map map = new HashMap(); 2 软引用 如果一个对…

    Linux 2023年6月7日
    0102
  • Linux下PAM模块学习总结

    Linux下PAM模块学习总结 转载自 https://www.cnblogs.com/kevingrace/p/8671964.html Original: https://ww…

    Linux 2023年6月7日
    099
  • hadoop分布式集群部署①

    Linux系统的安装和配置。(在VM虚拟机上) 一:安装虚拟机VMware Workstation 14 Pro 以上,虚拟机软件安装完成。 二:创建虚拟机。 三:安装CentOS…

    Linux 2023年6月13日
    082
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球