今天在给一台操做系统为Oracle Linux Server release 5.7的服务器配置网络时,遇到了备份ifcfg-eth0配置文件,致使网卡没法绑定IP地址的状况。以为是个有意思的案例,特此记录一下,以供学习参考,避免之后再犯同类错误。linux
在装系统的时候没有配置网络,等到装好系统后,从系统管理员那里了解了IP、子网掩码、网关信息后,才开始配置网络。在修改ifcfg-eth0网卡配置文件前,先备份一份配置文件,以避免因为修改不当,致使没法还原到最初的配置。这也是事情的原由服务器
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0_bak [root@localhost network-scripts]# more ifcfg-eth0_bak # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00:50:56:92:56:05 ONBOOT=yes
接下来添加IP地址、子网掩码等网络
[root@localhost network-scripts]# vi ifcfg-eth0 # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) DEVICE=eth0 BOOTPROTO=static #BROADCAST=192.168.7.255 HWADDR=00:50:56:92:56:05 IPADDR=192.168.7.222 NETMASK=255.255.255.0 ONBOOT=yes TYPE=Ethernet
在配置文件 /etc/sysconfig/network下增添网关信息后,重启网络服务,结果以下所示dom
[root@localhost network-scripts]# more /etc/sysconfig/networkoop
NETWORKING=yespost
GATEWAY=192.168.7.1学习
NETWORKING_IPV6=nospa
HOSTNAME=localhost.localdomain操作系统
因而经过setup命令,进入图形化配置界面,结果以下所示,因为备份文件名为ifcfg-eth0_bak,结果Linux系统将其视为另一块网卡的配置信息,结果致使没法为网卡绑定IP地址(由于该配置文件啥都没有)3d
[root@localhost ~]# setup
因而将备份文件重命名为bak_ifcfg-eth0后,重启网络服务后,OK,网卡绑定了IP地址,网络畅通了。
[root@localhost network-scripts]# mv ifcfg-eth0_bak bak_ifcfg-eth0
[root@localhost network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@localhost network-scripts]#
同时我在网上也看到有网友遇到过相似问题:http://www.linuxfly.org/post/291/, Linux修改配置文件必定要千万当心,有时候那怕是一个空格就会致使结果逆转。