代码改变世界

Linux备份ifcfg-eth0文件导致的网络故障问题

2013-10-12 15:59  潇湘隐者  阅读(3473)  评论(0编辑  收藏  举报

     今天在给一台操作系统为Oracle Linux Server release 5.7的服务器配置网络时,遇到了备份ifcfg-eth0配置文件,导致网卡无法绑定IP地址的情况。觉得是个有意思的案例,特此记录一下,以供学习参考,避免以后再犯同类错误。

     在装系统的时候没有配置网络,等到装好系统后,从系统管理员那里了解了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

 

clip_image002

接下来添加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

 

clip_image004

在配置文件 /etc/sysconfig/network下增添网关信息后,重启网络服务,结果如下所示

[root@localhost network-scripts]# more  /etc/sysconfig/network

NETWORKING=yes

GATEWAY=192.168.7.1

NETWORKING_IPV6=no

HOSTNAME=localhost.localdomain

clip_image006

于是通过setup命令,进入图形化配置界面,结果如下所示,由于备份文件名为ifcfg-eth0_bak,结果Linux系统将其视为另外一块网卡的配置信息,结果导致无法为网卡绑定IP地址(因为该配置文件啥都没有)

[root@localhost ~]# setup

clip_image008

于是将备份文件重命名为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修改配置文件一定要千万小心,有时候那怕是一个空格就会导致结果逆转。