使用CentOS6.X安装后发现yum命令链接不到服务器,检查发现根本就无法上网,所以找原因
修改eth0配置文件
vi /etc/sysconfig/network-scripts/ifcfg-eth0
引用本地文件内容:
————文件内容—————
DEVICE=”eth0″
HWADDR=”00:0C:29:BD:E1:19″
BOOTPROTO=dhcp
NM_CONTROLLED=”yes”
ONBOOT=”yes”
USECTL=no
TYPE=Ethernet
PEERDNS=yes
———————————–
上面的黄色部分至关重要,是解决问题的根本,设置完成之后我们
service network restart
重启网络服务,如果还没有成功,那么我们重启一下电脑(虚拟机)
reboot
完成上述操作后,我们观察/etc/resolv.conf
文件的内容,如下:
说明我们的主机现在已经分配到了IP地址,这要归功与最后一条语句,至于解释请参看注释。
注释(英文太水,不敢贸然翻译):
ONBOOT
=answer
where answer is one of the following:
-
yes
— This device should be activated at boot-time. -
no
— This device should not be activated at boot-time.
PEERDNS
=answer
where answer is one of the following:
-
yes
— Modify/etc/resolv.conf
if theDNS
directive is set, if usingDHCP
, or if using Microsoft’s RFC 1877IPCP
extensions withPPP
. In all casesyes
is the default. -
no
— Do not modify/etc/resolv.conf
. -
参考:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html
http://blog.csdn.net/ecjtuxuan/article/details/6765094