方法一:在ifcfg-eth0 直接加入DNS1=8.8.8.8或其他DNS地址,然后执行service network restart
DEVICE=”eth0″
BOOTPROTO=”static”
HWADDR=”00:0C:5D:A3:B5:11″
NM_CONTROLLED=”yes”
ONBOOT=”yes”
IPADDR=103.155.122.56
NETMASK=255.255.255.0
GATEWAY=103.155.122.1
DNS1=8.8.8.8
再来查看resolv.conf 多了一行 namerserver 8.8.8.8
# Generated by NetworkManager
nameserver 8.8.8.8
方法二:
vim /etc/resolvconf/resolv.conf.d/head 文件
显示与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
保存退出,
resolvconf -u
此时就可以正常上网了,重启后不用在重新设置DNS了。