重启网卡:
/etc/init.d/networking restart
-
ifconfig方式
ifconfig eth0 down
ifconfig eth0 up
eth0
指代你的网卡名字
修改dns:
参考:https://www.cnblogs.com/cehui0303/p/5735289.html
https://www.cnblogs.com/chris-jia/articles/9870112.html
通过修改:
apt install openresolv
apt install resolvconf
sudo vi /etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)
在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4
如果有多个DNS就一行一个
修改好保存,然后执行
sudo resolvconf -u
再看/etc/resolv.conf,最下面就多了2行:
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 8.8.8.8
nameserver 8.8.4.4
可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。