差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

tech:udev [2011/09/20 16:23] – 建立 jonathantech:udev [2013/05/09 14:28] (目前版本) jonathan
行 1: 行 1:
 +====== CentOS6 udev 更改 nic 名稱的狀況 ======
  
 +  * 因為透過 virt-clone 複製 vm 後, 新啟動 vm 內的 nic 就會變成 eth1 而不是原本的 eth0<code sh>
 +ifconfig -a
 +</code><file>
 +eth1      Link encap:Ethernet  HWaddr 00:16:36:63:D3:2A
 +          UP BROADCAST MULTICAST  MTU:1500  Metric:1
 +          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
 +          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
 +          collisions:0 txqueuelen:1000
 +          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
 +
 +lo        Link encap:Local Loopback
 +          inet addr:127.0.0.1  Mask:255.0.0.0
 +          inet6 addr: ::1/128 Scope:Host
 +          UP LOOPBACK RUNNING  MTU:16436  Metric:1
 +          RX packets:40350 errors:0 dropped:0 overruns:0 frame:0
 +          TX packets:40350 errors:0 dropped:0 overruns:0 carrier:0
 +          collisions:0 txqueuelen:0
 +          RX bytes:32604075 (31.0 MiB)  TX bytes:32604075 (31.0 MiB)
 +</file>
 +
 +  * 這個問題可以經過開機的紀錄發現是由 udev 所更改<code sh>
 +dmesg | grep eth
 +</code><file>
 +udev: renamed network interface eth0 to eth1
 +</file>
 +  * 原來是 nic 的 MAC 改變時, 會在 /etc/udev/rules.d/70-presistent-net.rules 內增加哪個 MAC 應該對應到哪個 eth 的規則, 所以如果確定之前的 MAC 是不需要的, 可以直接編輯這個檔案, 將不需要的規則刪除, 並修改正確 MAC 需要對應到的 eth 編號, 例如我要將目前 00:16:36:63:D3:2A 對應到 eth1 改回 eth0
 +    * 編輯前的 /etc/udev/rules.d/70-presistent-net.rules <file>
 +# 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.
 +
 +# net device ()
 +SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:42:8d:bb", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 +
 +# net device ()
 +SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:63:d3:2a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 +</file>
 +    * 編輯後的 /etc/udev/rules.d/70-presistent-net.rules <file>
 +# 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.
 +
 +# net device ()
 +SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:63:d3:2a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 +</file>
 +  * 修改之後, 重新啟動就可生效.
 +
 +<note>
 +**如果要使用在 VM Image Template**
 +  - 去除 /etc/sysconfig/network-scripts/ifcfg-eth0 內的 UUID 以及 HWADDR Exp.<file>
 +:
 +#UUID="0b2a4fa5-bc20-45cc-8981-e1a5ce59476c"
 +#HWADDR=52:54:00:55:FD:A1
 +:
 +</file>
 +  - 刪除 /etc/udev/rules.d/70-persistent-net.rules 這個檔案 Exp.<code sh>
 +rm -f /etc/udev/rules.d/70-persistent-net.rules
 +</code>
 +</note>
 +
 +===== 參考網址 =====
 +  * http://www.cyberciti.biz/faq/rhel-fedora-centos-howto-swap-ethernet-aliases/
 +  * http://www.cyberciti.biz/tips/vmware-linux-lost-eth0-after-cloning-image.html
 +
 +{{tag>centos6 udev nic}}