亮亮天天天篮 發表於 2017-3-2 14:59:32

CentOS里ifcfg的device详解

<p>#cat ifcfg-eth0 </p>
<p>device=eth0 </p>
<p>...</p>
<p>原因:有个多节点服务器迁移机房,怕碰坏了,先把硬盘拆下来,结果放回去的时候记错顺序了,造成开机&nbsp; 网卡对不上,原有的eth01变成eth23,知道怎么搞。</p>
<p><strong><font color="#ff0000">分析:</font></strong></p>
<p><strong>CentOS下找不到eth0设备的解决方法</strong></p>
<p>经过百度,了解了一些信息,特此记录在此,以备忘。 为什么eth0会变成eth1? 很多Linux&nbsp; distribution使用udev动态管理设备文件,并根据设备的信息对其进行持久化命名。udev会在系统引导的过程中识别网卡,将mac地址和网卡名称对应起来记录在udev的规则脚本中。而对于新的虚拟机,VMware会自动为虚拟机的网卡生成MAC地址,当你克隆或者重装虚拟机软件时,由于你使用的是以前系统虚拟硬盘的信息,而该系统中已经有eth0的信息,对于这个新的网卡,udev会自动将其命名为eth1(累加的原则),所以在你的系统启动后,你使用ifconfig看到的网卡名为eth1。</p>
<p>这里的eth0是在/etc/udev/rules.d/70-persistent-net.rules定义的</p>
<p># This file was automatically generated by the /lib/udev/write_net_rules </p>
<p># program, run by the persistent-net-generator.rules rules file. </p>
<p># </p>
<p># You can modify it, as long as you keep each rule on a single </p>
<p># line, and change only the value of the NAME= key. </p>
<p># PCI device 0x8086:0x100f (e1000) </p>
<p>SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;xx:xx:xx:xx:xx:xx&quot;, ATTR{type}==&quot;1&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;eth0&quot;</p>
<p><strong>解决:&nbsp; 为什么eth0会变成eth1?</strong></p>
<p>如何恢复到eth0?&nbsp; udev记录网络规则的脚本为:/etc/udev/rules.d/70-persistent-net.rules&nbsp; $ vi /etc/udev/rules.d/70-persistent-net.rules</p>
<p># This file was automatically generated by the /lib/udev/write_net_rules </p>
<p># program run by the persistent-net-generator.rules rules file. </p>
<p># </p>
<p># You can modify it, as long as you keep each rule on a single line. </p>
<p># PCI device 0x1022:0x2000 (pcnet32) </p>
<p>SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;00:0c:29:5a:6c:73&quot;, ATTR{type}==&quot;1&quot;,KERNEL==&quot;eth*&quot;, NAME=&quot;eth0&quot; </p>
<p>SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;00:0c:29:a9:22:9d&quot;, ATTR{type}==&quot;1&quot;,KERNEL==&quot;eth*&quot;, NAME=&quot;eth1&quot; </p>
<p>CentOS下找不到eth0设备的解决方法&nbsp; 打开该文件,这时你会发现,里面有eth0,eth1两个网卡的信息,但实际上你ifconfig时只能发现eth1一个网卡的信息,这时因为eth0根本就不存在。&nbsp; 将其中eth0的信息删掉,并将eth1信息中的设备名改为eth0,重启系统,你看到的网卡就是eth0了,或者删掉其中所有的信息重启系统udev会帮你发现新的设备的。&nbsp; 另外还有一个启动脚本文件/etc/sysconfig/network-scripts/ifcfg-eth0,该文件中的mac地址为原来eth0网卡的物理地址,而虚拟机为eth1分配新的物理地址,故启动脚本中的信息与实际信息时不匹配的,将MAC的地址信息修改为70-persistent-net.rules中的eth1的MAC地址,再次重启网络,就完全恢复到以前eth0网卡的状态了。</p>
頁: [1]
查看完整版本: CentOS里ifcfg的device详解