Ubuntu16.04连上wifi不能上网解决

连上wifi,能上google,能上medium等网站,就是不能github、baidu和stackoverflow等,更让人尴尬,让我确定这就是DNS错误,废话不多说,解决办法很简单

方法一

编辑/etc/resolv.conf,添加或修改为nameserver 8.8.8.8/nameserver 8.8.4.4(Google Public DNS)
或者直接使用命令:sudo echo nameserver 8.8.8.8 > /etc/resolv.conf

可能不少人像我这样做了,结果发现只能一段时间有效,认真看resolv.conf后发现下面的注释
$ cat /etc/resolvconf/resolv.conf.d/head

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
看不懂的话我说下大概意思这个文件手动修改是无效的,由于这个文件是被动态生成,修改的会被覆盖。这样就尴尬了。
然后我们直接修改动态生成的模板
sudo vim /etc/resolvconf/resolv.conf.d/head
添加一句 nameserver 8.8.8.8/nameserver 8.8.4.4
(这里注意不是/etc/resolvconf/resolv.conf.d/base)

方法二

sudo vim /etc/dhcp/dhclient.conf
prepend domain-name-servers 8.8.8.8(, 8.8.4.4);
参考/扩展阅读

  1. What does “sudo echo nameserver 8.8.8.8 > /etc/resolv.conf” do?-AskUbuntu
  2. Ubuntu连上WiFi不能上网了,求解决办法–开源中国
  3. Containers cannot resolve DNS if docker host uses 127.0.0.1 as resolver #541
  4. How do I set my DNS when resolv.conf is being overwritten?
  5. nameserver 127.0.1.1 in resolv.conf won’t go away!-AskUbuntu

你可能感兴趣的:(Linux)