星期二, 11月 13, 2012

[轉載] 修改redhat 6 NIC 順序 : Changing the ethX to Ethernet Device Mapping in EL6 and Fedora 12+

在新增或移除網卡時 , 常會遇到此問題 , 以下為redhat 6 的作法 , 如果在redhat 4 或redhat 5 只要手動把MAC address 修改到相對應的/etc/sysconfig/network-scripts/ethx  上面即可!

---

http://www.2mysite.net/Article/Changing_the_ethX_to_Ethernet_Device_Mapping_in_EL6_and_Fedora_12.aspx
When you have two or more ethernet devices in one machine, the Fedora install may not install them in the order you want. This document will show you how to change theethX to physical ethernet device mapping.
This is desirable in cases where specific network cards need to be used on specific networks, and you are interested in maintaining commonethX names across servers. A practical example is found in the Two Node Fedora 13 Clusterproject.

Contents

[hide]

For the Impatient

Assuming that NetworkManager is already removed.
/etc/init.d/network stop
vim/etc/sysconfig/network-scripts/ifcfg-eth*# Make changes as neededvim/etc/udev/rules.d/70-persistent-net.rules
# Make changes as needed
start_udev
/etc/init.d/network start
Thanks for fenris02 and mutk

Example

I find it easier to follow instructions when I have an example to follow, so let me provide one here:
I've got the same hardware in the same configuration in both of my storage nodes. To keep things simple, I want to make sure that both nodes use the same ethX name for the network devices on each of the given networks.

Desired Mapping

Let's assume that you want this:
  • eth0
    • Type: # Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
    • MAC: 90:E6:BA:71:82:EA
  • eth1
    • Type: # D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
    • MAC: 00:21:91:19:96:53
  • eth2
    • Type: # Intel Corporation 82540EM Gigabit Ethernet Controller
    • MAC: 00:0E:0C:59:46:E4

Initial Mapping

When the Fedora install finished, you may have gotten this:
  • eth0
    • Type: # D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
    • MAC: 00:21:91:19:96:53
  • eth1
    • Type: # Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
    • MAC: 90:E6:BA:71:82:EA
  • eth2
    • Type: # Intel Corporation 82540EM Gigabit Ethernet Controller
    • MAC: 00:0E:0C:59:46:E4

The Problem

In the above example, eth2 is where we want it, so we leave it alone. The problem is that eth0 and eth1are reversed.

The Fix

Traditionally, the ethX to physical ethernet device was linked via the HWADDR=... argument in each NIC'sifcfg-ethX configuration file. With the introduction of udev, the HWADDR=... is no longer needed. Instead, this mapping is now made in the 70-persistent-net.rules udev configuration file.
So the trick then is to remove or comment-out the HWADDR=... argument in each NIC's ifcfg-ethXconfiguration file, then, change the NAME="ethX" in the udev configuration file to match the MAC address you want.

Stopping the Network

First, stop the network. This is important because if you change the MAC address to ethX mapping while the network is still up, the init.d script will fail to bring down the network devices and you will need to reboot for the changes to take effect.
/etc/init.d/network stop

Interface Configuration

Go to the /etc/sysconfig/network-scripts/ directory and then use cat to see the contents of the ifcfg-eth*network configuration files:
cd/etc/sysconfig/network-scripts
cat ifcfg-eth0
# D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
DEVICE=eth0
BOOTPROTO=dhcp
DHCPCLASS=
HWADDR=00:21:91:19:96:53
ONBOOT=yes
DHCP_HOSTNAME=an-node01.alteeve.com
cat ifcfg-eth1
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth1
BOOTPROTO=dhcp
DEFROUTE=yes
HWADDR=90:E6:BA:71:82:EA
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
ONBOOT=yes
OPTIONS=layer2=1
PEERDNS=yes
PEERROUTES=yes
TYPE=Ethernet
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
DHCP_HOSTNAME=an-node01.alteeve.com
cat ifcfg-eth2
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth2
HWADDR=00:0E:0C:59:46:E4
ONBOOT=no
The important lines are the DEVICE=... and HWADDR=... lines. The rest of the lines will very likely differ from the output above, and most will likely be set to BOOTPROTO=static. One or more may also be set to ONBOOT=yes. It is outside the scope of this tutorial to cover the various settings
For an exhaustive list of available options, please see the Fedora documentation.
With networking stopped, all we need to do is remove the HWADDR=... lines. Personally, I like to keep the network card name and the HWADDR=... entries in my files, but comment them out. If you wish to do the same, move them to the appropriate file. Further, I use this time to further configure each interface to the values I want. Do whatever is right for you.
Here is the updated files with updated network settings:
cd/etc/sysconfig/network-scripts
cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
#HWADDR=90:E6:BA:71:82:EA
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.71
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.139.81.117
DNS2=192.139.81.1
DEFROUTE=yes
cat ifcfg-eth1
# D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
#HWADDR=00:21:91:19:96:53
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=10.0.0.71
NETMASK=255.255.255.0
cat ifcfg-eth2
# Intel Corporation 82540EM Gigabit Ethernet Controller
#HWADDR=00:0E:0C:59:46:E4
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=10.0.1.71
NETMASK=255.255.255.0

'udev' Configuration

The user-space device manager, udev, maintains a list of configuration files that help ensure that hardware to /dev (software) mappings stay consistent, even when hardware is hot swapped or moved between physical connections. For networking hardware, this mapping is recorded in the 70-persistent-net.rules.
Here, all that needs to be done is for the NAME="..." entry to be changed to reflect what you want.
Note that the entries do not need to be in any particular order.
cd/etc/udev/rules.d/cat70-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:0x100e (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:0c:59:46:e4", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
 
# PCI device 0x1186:0x4b00 (sky2) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:21:91:19:96:53", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 
# PCI device 0x10ec:0x8168 (r8169) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="90:e6:ba:71:82:ea", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
Make the changes and save the file. The file should now look like this:
cat70-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 0x10ec:0x8168 (r8169) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="90:e6:ba:71:82:ea", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
 
# PCI device 0x1186:0x4b00 (sky2) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:21:91:19:96:53", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
 
# PCI device 0x8086:0x100e (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:0c:59:46:e4", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

Making the Changes Take Effect

First, you need to reload udev so that it updates the mapping in memory. This is done using thestart_udev program:
start_udev
Starting udev:                                             [  OK  ]
With udev updated, the last step is to restart the network daemon:
/etc/init.d/network start
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:                                [  OK  ]
Bringing up interface eth2:                                [  OK  ]
Done! use ifconfig to verify that the network cards are properly assigned to the specified ethX names.

Caveat!

NOTE: If you are using a vlan, the device facing the vlan can not have the HWADDR=... value set! Set the others and leave this commented out. Otherwise, because of how the vlan loads, the OS will not see the physical device and will fail to bring up the interface at all.


沒有留言:

LinkWithin-相關文件

Related Posts Plugin for WordPress, Blogger...