Inserting an external NIC Port sequence Chaos--linux System

Source: Internet
Author: User

This article is the author of the work of learning in understanding or sentiment, welcome everyone to ask questions, discuss together!!

I. Questions raised

The general motherboard has two NIC interface, Linux system is generally named after boot eth0,eth1, of course, if we do not eth0 and eth1 post-processing, each boot eth0 and eth1 location will not be fixed. Therefore, when the external network card, the problem of port confusion (port name and port of the PCI location is not fixed, each boot can be transformed, the kernel to the network port naming order is based on the detection of the Order of the NIC), especially the different drivers of the network card.

Two. Problem analysis

1, first we need to understand the kernel to the network port name execution process:

1) The Linux kernel typically executes/sbin/udevd-d in Rc.sysinit to begin the Udev program.

2) The process of executing UDEV detects all devices and loads different drives depending on the device

3) After the driver of the device is loaded, Udev receives a kernel event for the device, and Udev matches the corresponding rule according to the corresponding event, or executes some script to modify the device name rewrite rule (rules)

4) When the rule is generated, when the kernel event of this device is generated again, the rules are first matched

Here are two points to note about Udev:

1) We can modify the name of any device by Udev.

2) before we change the name, the kernel has assigned a name to the device (it is worth noting that otherwise the modified name and the kernel will conflict with the name assigned by the other device, the modification fails)

2. Different network card devices

So far I have known the following types of network cards (all Intel):

Driver for the NIC model

8086:1502 e1000e

8086:10d3 e1000e

8086:150e IGB

8086:105e e1000e

8086:1521 IGB

This is just a few of my contacts, different types of drivers to the name of the NIC port or will have an impact

Bus ID number of the 3.PCI interface

-bash-3.2# Lspci-n-D | grep 0200
0000:00:19.0 0200:8086:1502 (Rev 05)
0000:01:00.0 0200:8086:150e (Rev 01)
0000:01:00.1 0200:8086:150e (Rev 01)
0000:01:00.2 0200:8086:150e (Rev 01)
0000:01:00.3 0200:8086:150e (Rev 01)
0000:03:00.0 0200:8086:105e (Rev 06)
0000:03:00.1 0200:8086:105e (Rev 06)
0000:04:00.0 0200:8086:10d3

We can view all the BUSID (first column) and the device model (the last column) of all the devices connected to the PCI interface via Lspci-n-D, where 0200 represents the NIC device, and through a lot of experiments, no matter how the name of the network port (eth*) changes, On the same machine, their BUSID number is constant. Here the 8086:1502,8086:10D3 is the motherboard comes with two ports, 8086:150E is a 4-port Intel network card, 8086:105E is a two-port Intel network card. Thus, on this model of the machine, this model of the network card, can have passed the BUSID number, network card model to fixed the network port name.

Third, problem-handling

1) First we add the following code to the Udev Web-related rules file:

kernel== "eth*|ath*|wlan*|ra*|sta*", drivers== "? *", import{program}= "a.sh $attr {address}%b"

When there is a kernel event for the NIC, it matches this rule, executes the a.sh script, and passes the MAC address ($attr {address}), Busid (%b) as a parameter to the script

2) The function of a.sh is to modify the port name according to the MAC address and busid two parameters, and finally output the new rule to a new rule file B. Specific methods:

A) list the corresponding tables for a BUSID and network port name as follows:

0000:04:00.0 8086:10d3 eth0
0000:00:19.0 8086:1502 eth1
0000:01:00.0 8086:150e eth2
0000:01:00.1 8086:150e Eth3
0000:01:00.2 8086:150e Eth4
0000:01:00.3 8086:150e Eth5
0000:03:00.0 8086:105e Eth6
0000:03:00.1 8086:105e Eth7

b) based on busid and this table, to find the final port name

c) Generate a new rule based on the MAC address and the final port name, as follows:

# PCI Device 0x8086:0x150e (IGB)
bus== "NET", driver== "? *", sysfs{address}== "90:e2:ba:52:8e:b2", name= "Eth4"

# PCI Device 0x8086:0x1502 (e1000e)
bus== "NET", driver== "? *", sysfs{address}== "0c:c4:7a:06:03:f3", name= "eth1"

# PCI Device 0x8086:0x150e (IGB)
bus== "NET", driver== "? *", sysfs{address}== "90:e2:ba:52:8e:b3", name= "Eth5"

# PCI Device 0x8086:0x10d3 (e1000e)
bus== "NET", driver== "? *", sysfs{address}== "0c:c4:7a:06:03:f2", name= "eth0"

# PCI Device 0x8086:0x150e (IGB)
bus== "NET", driver== "? *", sysfs{address}== "90:e2:ba:52:8e:b0", name= "eth2"

#PCI device 0x8086:0x105e (e1000e)
bus== "NET", driver== "? *", sysfs{address}== "68:05:ca:12:e0:c5", name= "Eth7"

# PCI Device 0x8086:0x150e (IGB)
bus== "NET", driver== "? *", sysfs{address}== "90:e2:ba:52:8e:b1", name= "Eth3"

# PCI Device 0x8086:0x105e (e1000e)
bus== "NET", driver== "? *", sysfs{address}== "68:05:ca:12:e0:c4", name= "Eth6"

D) Subsequent Udev events are matched by the rule B file, so the renaming is done

  

3) After 2, a lot of testing, found that there is a problem, the probability is very large: that is, renaming failed, because the system is assigned the same port name, conflict

Analyze This conflict problem:

1) First we have three network card, two kinds of drive

2) Udev opens, scans the device, loads the drive, and the kernel names the device

3) If the kernel-named eth0 driver is e1000e and enters the Udev rules, we're going to change it to Eth3.

4) But when eth0 into Udev did not change into eth3, the kernel also named a network port device Eth3

5) Then we will change the eth0 to Eth3, it will conflict, eth0 into a eth3_rename

4) for the problem of 3), before the INIT.D Network service is started (net), that is, a section of code is added to the first part of the Web script to deal with the _rename problem.

1) Find the current port name via Ifconfig (show all plus parameter-a)

2) through 1) find the port name and rule B For comparison, there is a problem, then modify

Four, the above is for the external network card processing process, welcome everyone to discuss together. Reprint please specify the source!! Http://www.cnblogs.com/yuzhaoxin/p/4083760.html

Inserting an external NIC Port sequence Chaos--linux System

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.