签到成功

知道了

CNDBA社区CNDBA社区

Linux修改网卡名称

2016-09-02 14:56 2330 0 原创 Linux
作者: Expect-乐

由于虚拟机之间老是复制来复制去,导致网卡配置,名称不对。

比如:

[root@lei network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.155
NETMASK=255.255.255.0
PREFIX=24
GATEWAY=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
HWADDR=08:00:27:BD:A6:ED

 

[root@lei network-scripts]# cat ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.156
NETMASK=255.255.255.0
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
HWADDR=08:00:27:6E:86:10

 

这里对应的是网卡名称是eth0和eth1.

 

但是如果我们使用ifconfig 命令查看:

[root@lei network-scripts]# ifconfig -a
eth2     Link encap:Ethernet  HWaddr08:00:27:BD:A6:ED
         inet addr:192.168.1.155
cast:192.168.1.255 Mask:255.255.255.0
         inet6 addr: fe80::a00:27ff:febd:a6ed/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST MTU:1500  Metric:1
         RX packets:187 errors:0 dropped:0 overruns:0 frame:0
         TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:16356 (15.9 KiB)  TXbytes:6116 (5.9 KiB)
 
eth3     Link encap:Ethernet  HWaddr08:00:27:6E:86:10
         inet addr:192.168.1.156 Bcast:192.168.1.255 Mask:255.255.255.0
         inet6 addr: fe80::a00:27ff:fe6e:8610/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:1357 errors:0 dropped:0 overruns:0 frame:0
         TX packets:1099 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:120604 (117.7 KiB)  TXbytes:115937 (113.2 KiB)
 
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:8 errors:0 dropped:0 overruns:0 frame:0
         TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:480 (480.0 b)  TXbytes:480 (480.0 b)

 

这里的网卡名称是eth2和eth3.

解决办法:

修改 /etc/udev/rules.d/70-persistent-net.rules文件中的映射关系就可以了。

 

--修改之前:

http://www.cndba.cn/Expect-le/article/168

http://www.cndba.cn/Expect-le/article/168

[root@lei network-scripts]# cat/etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated bythe /lib/udev/write_net_rules
# program, run by thepersistent-net-generator.rules rules file.
#
# You can modify it, as long as you keepeach rule on a single
# line, and change only the value of theNAME= key.
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:d4:ab:67",ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:af:2b:37",ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:bd:a6:ed",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="eth*",NAME="eth2"
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:6e:86:10",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="eth*",NAME="eth3"


 http://www.cndba.cn/Expect-le/article/168http://www.cndba.cn/Expect-le/article/168

 

 

--修改之后:

 

http://www.cndba.cn/Expect-le/article/168

[root@lei network-scripts]# cat/etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated bythe /lib/udev/write_net_rules
# program, run by thepersistent-net-generator.rules rules file.
#
# You can modify it, as long as you keepeach rule on a single
# line, and change only the value of theNAME= key.
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:6E:86:10",ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="08:00:27:BD:A6:ED",ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"


http://www.cndba.cn/Expect-le/article/168

 

注意这里的MAC地址要和ifcfg-eth0 保持一致。

 http://www.cndba.cn/Expect-le/article/168

 

然后重启一下网卡和udev:

--ifdown 网卡:

ifdown eth0
ifdown eth1

 

--重启udev

/etc/init.d/udev-post stop;
/etc/init.d/udev-post start

 

http://www.cndba.cn/Expect-le/article/168

或者使用:

http://www.cndba.cn/Expect-le/article/168

service udev-post stop
service udev-post start

 

注意: 对与Oracle linux 是udev-post, 而redhat 是udev

 

--ifup:http://www.cndba.cn/Expect-le/article/168

Ifup eth0
Ifup eth1

以上都不能生效的话,就重启操作系统。


版权声明:本文为博主原创文章,未经博主允许不得转载。

linux 修改网卡名称

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1547860次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ