注意:優(yōu)先配置 /etc/sysconfig/network-scripts/ifcfg-eth0 因?yàn)樵诰W(wǎng)絡(luò)初始化時(shí)候他會(huì)覆蓋 /etc/resolv.conf
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
DNS1=8.8.8.8
DNS2=8.8.4.4
The DNS servers specified with "DNS1/DNS2" directives will then automatically be added to /etc/resolv.conf when the interface is activated. So there is no need to modify /etc/resolv.conf yourself.
The above two methods can be applied similarly to a static IP address case. That is:
DEVICE=eth0
BOOTPROTO=manual
ONBOOT=yes
IPADDR=10.0.1.27
NETWORK=10.0.1.0
NETMASK=255.255.255.0
PEERDNS=no (then add DNS to /etc/resolv.conf)
Or:
DEVICE=eth0
BOOTPROTO=manual
ONBOOT=yes
IPADDR=10.0.1.27
NETWORK=10.0.1.0
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4