CentOS修改網卡名稱

來源:互聯網
上載者:User

標籤:

一.問題說明

測試環境中出現的小問題,因為虛擬機器之間經常複製來複製去,導致網卡配置這塊的不一致現象。

 

設定檔的資訊:

[[email protected] network-scripts]# catifcfg-eth0

DEVICE="eth0"

NM_CONTROLLED="yes"

ONBOOT=yes

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.1.12

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

 

[[email protected] network-scripts]# catifcfg-eth1

DEVICE="eth1"

NM_CONTROLLED="yes"

ONBOOT=yes

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.1.13

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 命令查看:

[[email protected] network-scripts]# ifconfig -a

eth2     Link encap:Ethernet  HWaddr08:00:27:BD:A6:ED 

         inet addr:192.168.1.12 Bcast: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.13 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檔案中的映射關係就可以了。

 

--修改之前:

[[email protected] 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"

 

 

 

--修改之後:

 

[[email protected] 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"

 

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

 

 

然後重啟一下網卡和udev:

--ifdown 網卡:

ifdown eth0

ifdown eth1

 

--重啟udev

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

/etc/init.d/udev-post start
 

或者使用:

service udev-post stop
service udev-post start

 

注意: 對與Oracle linux 是udev-post, 而redhat 是udev

 

--ifup:

Ifup eth0

Ifup eth1

 

 

不過在我的測試中,這2個都沒有效果,我是把整個OS都重啟了,才生效的。 小知識,隨筆記之。

CentOS修改網卡名稱

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.