其他PC Server上的一块硬盘插入到了一个新的设备(原因是就设备故障),因此想仅把硬盘更换到其他机器上,这样就可以接着跑之前机器上的应用了。
把故障机上的硬盘插入到新机器上后,能顺利启动系统,不过有一点是,网卡名称变了,由原来的eth0,eth1 变成了eth4和eth5了。
[root@REMS-SVRTEST rules.d]# ifconfig
eth4 Link encap:Ethernet HWaddr 00:1E:68:65:61:41
inet addr:192.168.1.126 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21e:68ff:fe65:6141/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1489 errors:0 dropped:0 overruns:0 frame:0
TX packets:985 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:136728 (133.5 KiB) TX bytes:129583 (126.5 KiB)
Memory:fdde0000-fde00000
eth5 Link encap:Ethernet HWaddr 00:1E:68:65:61:40
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)
Memory:fddc0000-fdde0000
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:405 errors:0 dropped:0 overruns:0 frame:0
TX packets:405 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:24789 (24.2 KiB) TX bytes:24789 (24.2 KiB)
具体的操作过程,不太详细记得了,修改过的配置文件,是有影响,主要有下面几个步骤:
更换机器后,网卡的MAC地址会发生变更,因此需要更改ifcfg-eth0和ifcfg-eth1中的HWADDR值,修改如下:
[root@REMS-SVRTEST network-scripts]# cat ifcfg-eth0
DEVICE=eth0
HWADDR=00:1e:68:65:61:40 ---> HWADDR值要变更为新机器上的MAC地址。
NM_CONTROLLED=yes
ONBOOT=yes
IPADDR=192.168.1.126
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
TYPE=Ethernet
BOOTPROTO=none
DNS1=192.168.1.1
IPV6INIT=no
USERCTL=no
新机器上的MAC地址如何获得呢?可以通过dmesg命令查看,如:
[root@REMS-SVRTEST Desktop]# dmesg | grep eth0
0000:0a:00.0: eth0: (PCI Express:2.5GB/s:Width x4) 00:1e:68:65:61:40 ---> 此为eth0网卡的MAC地址
0000:0a:00.0: eth0: Intel(R) PRO/1000 Network Connection
0000:0a:00.0: eth0: MAC: 5, PHY: 5, PBA No: ffffff-0ff
udev: renamed network interface eth0 to eth5
[root@REMS-SVRTEST Desktop]# dmesg | grep eth1
0000:0a:00.1: eth1: (PCI Express:2.5GB/s:Width x4) 00:1e:68:65:61:41 ---> 此为eth1网卡的MAC地址
0000:0a:00.1: eth1: Intel(R) PRO/1000 Network Connection
0000:0a:00.1: eth1: MAC: 5, PHY: 5, PBA No: ffffff-0ff
udev: renamed network interface eth1 to eth4
接着修改规则文件,/etc/udev/rules.d/70-persistent-net.rules
备份原文件,然后将该文件中的内容全部清掉,添加如下内容:
[root@REMS-SVRTEST rules.d]# cat 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:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1e:68:65:61:40", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1e:68:65:61:41", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
接下需要重启下操作系统,即可发现网卡名称被改了过来。
在此配置过程中,你可能还会用到2个命令:
service NetworkManager restart
service network restart