您的位置:首页 > 运维架构 > Linux

redhat linux6.5下修改网卡名称

2015-01-05 11:39 204 查看
我们在安装RAC时,需要公有网络的网卡名对应一致,私有网络的网卡名对应一致。但是当两个物理机器由于网卡配置数量的不等,很容易出现一个机器有ETH12和ETH13,但另一个机器只有ETH9和ETH10。那么遇到这个问题,如何修改网卡名称使两个机器的网卡名能对应起来呢?
其实这个问题,跟克隆虚拟机后的网卡启动失败问题很相似。只是克隆后新生成的虚机需要将网卡的MAC与70-persistent-net.rules文件的MAC保持一致就可以了。但是如果你要修改一个物理网卡的名称,其实并没有改变它的MAC地址,只是修改了名称而已。下面我们看一下如何实现网卡名称的更改。
举个例子,我们把本机的ETH1改成ETH3.
[root@test2 Desktop]# ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:0C:29:65:02:FF
inet addr:192.168.199.119 Bcast:192.168.199.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:2ff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:87714 errors:0 dropped:0 overruns:0 frame:0
TX packets:45281 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:112756896 (107.5 MiB) TX bytes:3001189 (2.8 MiB)

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:87 errors:0 dropped:0 overruns:0 frame:0
TX packets:87 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5721 (5.5 KiB) TX bytes:5721 (5.5 KiB)

pan0 Link encap:Ethernet HWaddr 66:13:A7:AD:1E:79
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:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

[root@test2 Desktop]# ping 192.168.199.118
PING 192.168.199.118 (192.168.199.118) 56(84) bytes of data.
64 bytes from 192.168.199.118: icmp_seq=1 ttl=64 time=0.787 ms
64 bytes from 192.168.199.118: icmp_seq=2 ttl=64 time=0.880 ms
64 bytes from 192.168.199.118: icmp_seq=3 ttl=64 time=0.758 ms
^C
--- 192.168.199.118 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2973ms
rtt min/avg/max/mdev = 0.758/0.808/0.880/0.056 ms

下面先把eth1宕掉
[root@test2 Desktop]# ifdown eth1
然后进入这个配置目录
[root@test2 Desktop]# cd /etc/sysconfig/network-scripts
[root@test2 network-scripts]# ls -l ifcfg*
-rw-r--r--. 1 root root 140 Jul 6 05:30 ifcfg-eth1
-rw-r--r--. 1 root root 254 Jan 9 2013 ifcfg-lo
修改网卡文件名称
[root@test2 network-scripts]# mv ifcfg-eth1 ifcfg-eth3
[root@test2 network-scripts]# ls -l ifcfg*
-rw-r--r--. 1 root root 140 Jul 6 05:30 ifcfg-eth3
-rw-r--r--. 1 root root 254 Jan 9 2013 ifcfg-lo
编辑新文件,将其中的
DEVICE=eth1改成eth3,不需要修改MAC地址。
[root@test2 network-scripts]# vi ifcfg-eth3
然后进入UDEV目录
[root@test2 network-scripts]# cd /etc/udev/rules.d
找到70-persistent-net.rules文件
[root@test2 rules.d]# ls -l 70*
-rw-r--r--. 1 root root 1342 Feb 17 2014 70-persistent-cd.rules
-rw-r--r--. 1 root root 420 Apr 16 2014 70-persistent-net.rules
[root@test2 rules.d]# vi 70-persistent-net.rules
修改这个文件,将
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0C:29:65:02:FF", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
改成
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0C:29:65:02:FF", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
保存退出。
[root@test2 rules.d]# ifup eth3
Device eth3 does not seem to be present, delaying initialization.
[root@test2 rules.d]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth3: Device eth3 does not seem to be present, delaying initialization.

[FAILED]
这个时候是启不来的,需要重启机器使修改生效。

[root@test2 rules.d]# reboot

重启后我们发现名称已经变过来了。
[root@test2 etc]# ifconfig -a
eth3 Link encap:Ethernet HWaddr 00:0C:29:65:02:FF
inet addr:192.168.199.119 Bcast:192.168.199.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:2ff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:39217 errors:0 dropped:0 overruns:0 frame:0
TX packets:57 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3162496 (3.0 MiB) TX bytes:3905 (3.8 KiB)

还有一种情况,机器在新添加物理网卡后出现网卡名称断点不连续
eth12 Link encap:Ethernet HWaddr 00:90:FA:76:A5:7C
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)

eth14 Link encap:Ethernet HWaddr 00:90:FA:76:A5:80
inet addr:11.11.161.65 Bcast:11.11.161.255 Mask:255.255.255.0
inet6 addr: fe80::290:faff:fe76:a580/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:74621 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4516473 (4.3 MiB) TX bytes:816 (816.0 b)

我们看一下少了eth13,这时可以把网卡配置全删除,重启让系统重新分配就连续了。
[root@rac2 network-scripts]# cd /etc/udev/rules.d
[root@rac2 rules.d]# ls -l
total 44
-rw-r--r--. 1 root root 1652 Aug 26 2010 60-fprint-autosuspend.rules
-rw-r--r--. 1 root root 1060 Jun 29 2010 60-pcmcia.rules
-rw-r--r--. 1 root root 316 Aug 6 2013 60-raw.rules
-rw-r--r--. 1 root root 787 Dec 31 19:29 70-persistent-cd.rules
-rw-r--r-- 1 root root 2905 Jan 5 21:47 70-persistent-net.rules
-rw-r--r--. 1 root root 40 Oct 25 2013 80-kvm.rules
-rw-r--r--. 1 root root 320 Sep 12 2012 90-alsa.rules
-rw-r--r--. 1 root root 83 Apr 1 2011 90-hal.rules
-rw-r--r--. 1 root root 2486 Jun 30 2010 97-bluetooth-serial.rules
-rw-r--r--. 1 root root 308 Oct 22 2013 98-kexec.rules
-rw-r--r--. 1 root root 54 Nov 3 2011 99-fuse.rules
[root@rac2 rules.d]# rm -rf 70-persistent-net.rules
[root@rac2 rules.d]# cd /etc/sysconfig/network-scripts
[root@rac2 network-scripts]# ls -l ifcfg*
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth0
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth1
-rw-r--r--. 3 root root 203 Jan 5 00:14 ifcfg-eth10
-rw-r--r--. 3 root root 137 Dec 31 18:52 ifcfg-eth11
-rw-r--r-- 3 root root 202 Jan 5 00:12 ifcfg-eth12
-rw-r--r-- 3 root root 181 Jan 5 00:46 ifcfg-eth14
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth2
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth3
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth4
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth5
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth6
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth7
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth8
-rw-r--r--. 3 root root 136 Dec 31 18:52 ifcfg-eth9
-rw-r--r--. 1 root root 254 Oct 10 2013 ifcfg-lo
[root@rac2 network-scripts]# rm -rf ifcfg-eth*
[root@rac2 network-scripts]#reboot
重启后一切正常。
本文出自 “滴水穿石孙杰” 博客,请务必保留此出处http://xjsunjie.blog.51cto.com/999372/1599238
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: