0%

Ubuntu17.04 vmware能够ping通内网,上不了外网的解决方法(DNS)

一般这是由于里面的路由域名服务器没有配置好。

issta@ubuntu:~$ ping www.baidu.com
ping: unknown host www.baidu.com
先看一下地址解析器:

1
2
3
4
issta@ubuntu:~$ 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 127.0.0.1

发现只是解析内网循环的。

所以添加google的域名服务器

1
2
3
4
5
6
issta@ubuntu:~$ 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 127.0.0.1
nameserver 202.98.96.68
nameserver 61.139.2.69

加了这两个一般就可以了。后续雄起。。哈哈。

1
2
3
4
5
6
7
8
9
issta@ubuntu:~$ ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_req=1 ttl=48 time=8.43 ms
64 bytes from 115.239.210.27: icmp_req=2 ttl=48 time=7.95 ms
^C64 bytes from 115.239.210.27: icmp_req=3 ttl=48 time=8.05 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 10134ms
rtt min/avg/max/mdev = 7.957/8.147/8.434/0.219 ms

按照上面的做法,只能解决一时的问题。再次启动的时候,DNS还是被换掉

方法一

1.需要创建一个文件/etc/resolvconf/resolv.conf.d/tail

1
sudo vi /etc/resolvconf/resolv.conf.d/tail

2.在该文件中写入自己需要的dns服务器,格式与/etc/resolv.conf相同

1
nameserver 8.8.8.8  

3.重启下resolvconf程序

1
sudo /etc/init.d/resolvconf restart

再去看看/etc/resolv.conf文件,可以看到自己添加的dns服务器已经加到该文件中

方法二

在/etc/network/interfaces中

1
2
3
4
5
6
7
###interfaces中#######     
auto eth0
iface eth0 inet static
address 192.168.3.250
netmask 255.255.255.0 #子网掩码
gateway 192.168.3.1 #网关
dns-nameservers 8.8.8.8 8.8.4.4 #设置dns服务器

这样再次启动也不会造成被替换的问题了