修改/etc/resolv.conf,重启网卡或者重启电脑后,/etc/resolv.conf会恢复到原来的状态。
原因说明:
CentOS、redhat下面直接修改/etc/resolv.conf,达到临时效果,但是重启网络后会重置。
重启后,根据eth0设置中设置dns的相关信息,这样使/etc/resolv.conf恢复到原来的状态。
所以:
必须要在/etc /sysconfig/network-scripts/ifcfg-eth0里面最后加上dns的设置
修改/etc /sysconfig/network-scripts/ifcfg-eth0
DNS1=192.168.30.2
之后重启网卡
[root@master network-scripts]# service network restart
[root@master network-scripts]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=15.7 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=13.3 ms[root@master network-scripts]# cat /etc/resolv.conf ; generated by
/sbin/dhclient-script search localdomain nameserver 192.168.30.2