首頁  >  文章  >  系統教程  >  解析CentOS中ifcfg檔案的設備字段

解析CentOS中ifcfg檔案的設備字段

WBOY
WBOY轉載
2024-01-12 15:48:13770瀏覽

#cat ifcfg-eth0

device=eth0

...

原因:有個多節點伺服器遷移機房,怕碰壞了,先把硬碟拆下來,結果放回去的時候記錯順序了,造成開機  網路卡對不上,原有的eth01變成eth23,知道怎麼搞。

分析:

CentOS下找不到eth0裝置的解決方法

#經過百度,了解了一些信息,特此記錄在此,以備忘。為什麼eth0會變成eth1? 很多Linux  distribution使用udev動態管理設備文件,並根據設備的資訊對其進行持久化命名。 udev會在系統引導的過程中識別網卡,將mac位址和網卡名稱對應起來記錄在udev的規則腳本中。而對於新的虛擬機,VMware會自動為虛擬機的網卡產生MAC位址,當你複​​製或重裝虛擬機軟體時,由於你使用的是以前系統虛擬硬碟的信息,而該系統中已經有eth0的訊息,對於這個新的網路卡,udev會自動將其命名為eth1(累積的原則),所以在你的系統啟動後,你使用ifconfig看到的網卡名為eth1。

這裡的eth0是在/etc/udev/rules.d/70-persistent-net.rules定義的

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

## You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{type}= ="1", KERNEL=="eth*", NAME="eth0"

解決:  為什麼eth0會變成eth1?

#如何恢復到eth0?  udev記錄網路規則的腳本為:/etc/udev/rules.d/70-persistent-net.rules  [user@localhost ~]$ vi /etc/udev/rules.d/70 -persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules

# program run by the persistent-net-generator.rules rules file.

## You can modify it, as long as you keep each rule on a single line.

# PCI device 0x1022:0x2000 (pcnet32)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:5a:6c:73", ATTR{type}= ="1",KERNEL=="eth*", NAME="eth0"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a9:22:9d", ATTR{type}= ="1",KERNEL=="eth*", NAME="eth1"

CentOS下找不到eth0設備的解決方法  打開該文件,這時你會發現,裡面有eth0,eth1兩個網卡的信息,但實際上你ifconfig時只能發現eth1一個網卡的信息,這時因為eth0根本就不存在。將其中eth0的資訊刪掉,並將eth1資訊中的設備名稱改為eth0,重啟系統,你看到的網卡就是eth0了,或者刪掉其中所有的信息重啟系統udev會幫你發現新的設備的。另外還有一個啟動腳本檔案/etc/sysconfig/network-scripts/ifcfg-eth0,該檔案中的mac位址為原來eth0網路卡的實體位址,而虛擬機器則為eth1分配新的實體位址,故啟動腳本中的資訊與實際資訊時不符的,將MAC的位址資訊修改為70-persistent-net.rules中的eth1的MAC位址,再次重啟網絡,就完全恢復到以前eth0網卡的狀態了。

以上是解析CentOS中ifcfg檔案的設備字段的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:jb51.net。如有侵權,請聯絡admin@php.cn刪除