[root@vagrant-centos65 yum.repos.d]# vim /etc/sysconfig/network-scripts/ifcfg-eth0#在这个文件最下面添加DNS1=42.121.236.241
DNS2=8.8.8.8
[root@vagrant-centos65 yum.repos.d]# service network restartShutting down interface eth0: [ OK ]Shutting down loopback interface: [ OK ]Bringing up loopback interface: [ OK ]Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ][root@vagrant-centos65 yum.repos.d]# cat /etc/resolv.conf; generated by /sbin/dhclient-script
search idreamsky.com vagrantup.com
nameserver 42.121.236.241
nameserver 8.8.8.8
重启 network 之后就能看到 dns 修改了.注意如果这里如果直接修改 /etc/resolv.conf 那么重启电脑 or 重启 network , resolv.conf 会恢复原状.因为它是根据 ifcfg-eth0来生成的..
如何刷新 dns cache
Linux下DNS缓存实现通常有两种方式:
一种是用DNS缓存程序NSCD(name service cache daemon)负责管理DNS缓存。
一种实现DNS缓存则是用Bind来架设Caching Name Server来实现。
如果是清除NSCD上的Cache,可重新启动NSCD服务来达成清除DNS Cache的效果。用这个命令:
# service nscd restart
或是
#/etc/init.d/nscd restart
# Preserving HOME has security implications since many programs# use it when searching for configuration files. Note that HOME# is already set when the the env_reset option is enabled, so# this option is only effective for configurations where either# env_reset is disabled or HOME is present in the env_keep list.#Defaults always_set_home
Defaults env_reset
Defaults env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"Defaults env_keep +="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"Defaults env_keep +="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"Defaults env_keep +="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"Defaults env_keep +="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"## Adding HOME to env_keep may enable a user to run unrestricted# commands via sudo.## Defaults env_keep += "HOME"Defaults secure_path= /sbin:/bin:/usr/sbin:/usr/bin