解决ubuntu16.04的apt-get update慢以及无法ping www.baidu.com的问题

1.Ubuntu 可以ping通DNS 无法访问外网的问题

  • 在解决解决ubuntu16.04的apt-get update慢之前,需要查看你的ubuntu是否能ping www.baidu.com,如果不可以需要按照以下的步骤来进行设置

  • (1)打开VMware的网络配置:编辑->虚拟网络编辑器
    在这里插入图片描述

  • (2)首先看一下你的静态ip地址,子网掩码,网关,dns地址(设置静态ip需要dns进行域名解析,需要配置dns地址)是否缺少

vim /etc/network/interfaces
进行相关的设置:参数如下,注意:下面的gateway 需要依据你的Vm虚拟机获取的网关进行设置

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto ens33
iface ens33 inet static
#onboot=yes
#

address 192.168.13.130
gateway 192.168.13.2

netmask 255.255.255.0
dns-nameserver 119.29.29.29
dns-nameserver 114.114.114.114
dns-nameserver 8.8.8.8
  • (3)ip地址—首先看一下ip地址和windows主机的地址是否在同一网段,可以ping测试一下

  • (4)DNS地址—查看dns地址,dns地址可以在/etc/network/interfaces文件中配置,也可以在/etc/resolvconf/resolv.conf.d/base中(具体配置可以看步骤一的图),
    配置完成执行/etc/init.d/networking restart;
    然后cat /etc/resolv.conf文件可以看到你配置的dns地址(注意不要直接修改/etc/resolv.conf这个文件,因为重启网络后,这里面的内容会重新生成);
    最后ping一下dns地址,看是否能够ping通.

/etc/init.d/networking restart
root@ubuntu:/home/jiwangreal# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=107 ms


root@ubuntu:/home/jiwangreal# cat /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
nameserver 119.29.29.29
nameserver 114.114.114.114
nameserver 8.8.8.8
  • (5)网关—使用netstat -rn命令查看路由信息,如果没有网关,需要在添加,
    如下说明网关已经配置好了
root@ubuntu:/home/jiwangreal# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.13.2    0.0.0.0         UG        0 0          0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 ens33
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0
192.168.13.0    0.0.0.0         255.255.255.0   U         0 0          0 ens33
192.168.13.0    0.0.0.0         255.255.255.0   U         0 0          0 br-8c703de3f949

  • (6)dns域名是否开启 --查看/etc/nsswitch.conf文件中的hosts一行是否dns
root@ubuntu:/home/jiwangreal# cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

  • 参考:
Ubuntu 可以ping通DNS 无法访问外网的问题
https://blog.csdn.net/gaoganghua/article/details/80386107

2.解决ubuntu16.04的apt-get update慢的问题

  • 直接修改国内的镜像源即可,因为ubuntu配置的默认源死过外的服务器,这可以通过以下的命令可以去查看相关的内容
vim /etc/apt/sources.list 
  • 参考:
【Ubuntu】Ubuntu 18.04 LTS 更换国内源——解决终端下载速度慢的问题
https://zhuanlan.zhihu.com/p/61228593
发布了556 篇原创文章 · 获赞 140 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/u011436427/article/details/104152964