Linux _ multi-Nic recognition sequence

Source: Internet
Author: User
This may occur when you use a linux system. when you install a NIC driver or a program related to the NIC. The network card may experience so-called drift. (Note: it is not elegant ). The possible appearance is: (1): the network card order is reversed, for example, the network connecting your network cable... this may occur when you use a linux system. when you install a NIC driver or a program related to the NIC.
 
The network card may experience so-called drift. (Note: it is not elegant ). The possible appearance is:
 
(1): The Nic sequence is reversed. for example, if your network port is eth0 and the driver of a Nic is installed, its name may change to eth0 or eth3.
 
(2): The nic name is changed. this is not a change from eth0 to eth1, but a very strange change. for example, eth0 cannot be found, the name of an Eni is _ tmp3183941582193 __
 
This is really annoying. Someone may obtain information through ifconfig | grep eth to complete some development work. if the nic name becomes invalid, the program will definitely fail.
 
(3): optical network card and electrical network card are in disorder or crosstab.
 
In short, our goal is to specify the name of a network card as the physical device we want. The procedure is as follows:
 
Step 1: Identify who is.
 
To use the network card, you must first know which physical device corresponds to the name. the practice is to pull a network cable from the switch and connect it from top to bottom to the network card, note that only one network adapter can be connected at a time. then, run the ethtool command to check whether the network adapter is connected. for example
 
[Root @ AS5 ~] # Ethtool eth0
Settings for eth0:
Supported ports: [MII]
Supported link modes: 10 baseT/Half 10 baseT/Full
100 baseT/Half 100 baseT/Full
1000 baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10 baseT/Half 10 baseT/Full
100 baseT/Half 100 baseT/Full
1000 baseT/Full
Advertised auto-negotiation: Yes
Speed: 100 Mb/s
Duplex: Full
Port: MII
PHYAD: 2
Transceiver: external
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes
 
The eth0 status is connected to the network cable. If Linked detected: no, the network cable is not connected.
 
Mark the name of the device that is separated in this way.
 
Step 2: obtain the MAC address of each Nic
 
Ifconfig-a can view all network devices.
 
Use ifconfig-a | grep HWaddr to obtain the MAC address of each device.
 
For example:
 
[Root @ AS5 ~] # Ifconfig-a | grep HWaddr
Eth0 Link encap: Ethernet HWaddr 00: 30: 48: 7F: B5: CA
Eth1 Link encap: Ethernet HWaddr 00: 30: 48: 7F: B5: CB
Eth2 Link encap: Ethernet HWaddr 00: 04: 23: A6: 81: E0
Eth3 Link encap: Ethernet HWaddr 00: 04: 23: A6: 81: E1
 
The MAC address of each Nic is obtained.
 
Step 3: bind the MAC address and Nic name.
 
We all know that for the RedHat system, the network configuration file is:/etc/sysconfig/network-scripts/ifcfg-ethX
 
Where N = 0, 1, 2...
 
For example, root @ AS5 ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0
# NVidia Corporation MCP55 Ethernet
DEVICE = eth0
ONBOOT = yes
HWADDR = 00: 30: 48: 7f: b5: ca
TYPE = Ethernet
NETMASK = 255.255.255.0
IPADDR = 192.168.42.231
GATEWAY = 192.168.42.1
BOOTPROTO = static
# NAMESERVER = 202.106.0.20
 
This file is the configuration file for Nic initialization.
 
For example, if you want to specify the device whose MAC address is MAC1 as ethn, modify the file
 
/Etc/sysconfig/network-scripts/ifcfg-ethn
 
Add configuration information for MAC address binding and name
 
DEVICE = ethn
 
HWADDR = MAC1 (for example, 00: 30: 48: 7f: b5: ca)
 
Other configuration information is not affected.
 
After binding all NICs, the reboot system should be ready.
 
Note the following:
 
/Etc/modprobe. conf
 
To modify the file, make sure that a device uses the corresponding driver, for example:
 
Cat/etc/modprobe. conf
Alias eth0 forcedeth
Alias eth1 forcedeth
Alias scsi_hostadapter aic79xx
Alias scsi_hostadapter1 sata_nv
Alias scsi_hostadapter2 usb-storage
Alias eth2 e1000
Alias eth3 e1000
 
The forcedeth driver is used for eth0 and eth1, and eth2 and eth3 are driven by e1000.
 
 
 
 
Solution:
 
Cd/etc/udev/rules. d
 
Find 60-net.rules and back up the file.
 
Mv 60-net.rules 60-net.rules.bak
 
Create a file named 60-net.rules with the following content:
 
[Root @ localhost rules. d] # cat 60-net.rules
 
SUBSYSTEM = "net", ACTION = "add", SYSFS {address} = "mac address of your Nic 1 ",
 
IMPORT = "/lib/udev/rename_device % k eth0"
 
SUBSYSTEM = "net", ACTION = "add", SYSFS {address} = "mac address of your Nic 2 ",
 
IMPORT = "/lib/udev/rename_device % k eth1"
 
Note that you need to change the mac address of your network card.
 
Restart your computer. everything is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.