静态IP方式
修改/etc/network/interfaces,在它的网卡后面配置信息添加:
auto eth0
iface eth0 inet static
address 10.0.0.56
netmask 255.255.255.0
gateway 10.0.0.1
# 添加部分如下
dns-nameservers 223.5.5.5 223.6.6.6
修改完之后保存,然后执行
# resolvconf -u
重启后DNS就生效了,这时候再看/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 223.5.5.5
nameserver 223.6.6.6
DHCP方式
修改/etc/resolvconf/resolv.conf.d/base文件,该文件默认是空的,在里面写入:
nameserver 223.5.5.5
nameserver 223.6.6.6
修改完之后保存,然后执行
# resolvconf -u
重启后DNS就生效了,发现/etc/resolv.conf文件中多了几行,这几行是resolve程序自动写入的:
# 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 223.5.5.5
nameserver 223.6.6.6
临时修改
修改/etc/resolv.conf在文件里添加
nameserver 223.5.5.5
nameserver 223.6.6.6
当然这个方法是临时的,下一次重启或者重启网络服务之后,就会失效,如果需要一个临时的连接一个dns的话,那么这是一个好的选择。
注意修改/etc/resolv.conf配置文件不需要重启DNS