CentOS6 udev 更改 nic 名稱的狀況

  • 因為透過 virt-clone 複製 vm 後, 新啟動 vm 內的 nic 就會變成 eth1 而不是原本的 eth0
    ifconfig -a
    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)
  • 這個問題可以經過開機的紀錄發現是由 udev 所更改
    dmesg | grep eth
    udev: renamed network interface eth0 to eth1
  • 原來是 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
      # 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"
    • 編輯後的 /etc/udev/rules.d/70-presistent-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.
      
      # net device ()
      SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:63:d3:2a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
  • 修改之後, 重新啟動就可生效.
如果要使用在 VM Image Template
  1. 去除 /etc/sysconfig/network-scripts/ifcfg-eth0 內的 UUID 以及 HWADDR Exp.
    :
    #UUID="0b2a4fa5-bc20-45cc-8981-e1a5ce59476c"
    #HWADDR=52:54:00:55:FD:A1
    :
  2. 刪除 /etc/udev/rules.d/70-persistent-net.rules 這個檔案 Exp.
    rm -f /etc/udev/rules.d/70-persistent-net.rules
  • tech/udev.txt
  • 上一次變更: 2013/05/09 14:28
  • jonathan