• Linux的网卡由eth0变成了eth1,如何修复 (转载)


    Linux的网卡由eth0变成了eth1,如何修复
     
    使用wmware安装了linux,安装成功后,使用的网卡是eth0,没有eth1。但是用过一段时间后,不知道为什么eth0无法使用,系统却自动生成了eth1网卡,这可以使用ifconfig命令看的到。
     
    [user@localhost ~]$ ifconfig
    eth1      Link encap:Ethernet  HWaddr 00:0C:29:A9:22:9D  
              inet addr:192.168.1.108  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fea9:229d/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:313 errors:0 dropped:0 overruns:0 frame:0
              TX packets:182 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:67356 (65.7 KiB)  TX bytes:26612 (25.9 KiB)
              Interrupt:19 Base address:0x2000 
     
    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:1788 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1788 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:89560 (87.4 KiB)  TX bytes:89560 (87.4 KiB)
     
    使用service network restart指令来重新启动网络服务时,会看到有eth0网卡不存在的提示。
     
    经过百度,了解了一些信息,特此记录在此,以备忘。
     
    为什么eth0会变成eth1?
     
    很多Linux distribution使用udev动态管理设备文件,并根据设备的信息对其进行持久化命名。udev会在系统引导的过程中识别网卡,将mac地址和网卡名称对应起来记录在udev的规则脚本中。而对于新的虚拟机,VMware会自动为虚拟机的网卡生成MAC地址,当你克隆或者重装虚拟机软件时,由于你使用的是以前系统虚拟硬盘的信息,而该系统中已经有eth0的信息,对于这个新的网卡,udev会自动将其命名为eth1(累加的原则),所以在你的系统启动后,你使用ifconfig看到的网卡名为eth1。
     
    如何恢复到eth0?
     
    在fedora中,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"
     
    打开该文件,这时你会发现,里面有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网卡的状态了。
  • 相关阅读:
    shell进行mysql统计
    java I/O总结
    Hbase源码分析:Hbase UI中Requests Per Second的具体含义
    ASP.NET Session State Overview
    What is an ISAPI Extension?
    innerxml and outerxml
    postman
    FileZilla文件下载的目录
    how to use webpart container in kentico
    Consider using EXISTS instead of IN
  • 原文地址:https://www.cnblogs.com/AliceAn/p/4211970.html
Copyright © 2020-2023  润新知