ubuntu的dns设置与centos不一样,在ubuntu上直接修改/etc/resolv.conf会在系统重启后失效:

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

内容是一段警告:这个文件是resolvconf这个文件动态创建的,不要手动编辑,修改会被覆盖.

那么,如何在静态IP的情况下设置dns呢?有两个方法可以实现:

修改/etc/network/interfaces

echo dns-nameservers 114.114.114.114 >> /etc/network/interfaces

修改/etc/resolvonf/resolv.conf.d/base

echo -e "nameserver 114.114.114.114\nnameserver 8.8.8.8" > /etc/resolvonf/resolv.conf.d/base
resolvconf -u

Centos上直接修改/etc/resolv.conf即可