有时要设定网卡 IP 时常常会搞不清楚哪个是哪张卡.下面可以看的出来吗??是我就不行了.
再加上之前遇到一个问题就是网络介面卡的顺序,不知道系统是怎么侦测的,常常在开关机后顺序大乱,写信询问 RedHat 他们建议我们可以使用 udev.来为每个装置个别命名.其实概念很简单先找出目前的网路卡顺序.
[root@benjr ~]# cat /etc/moprobe.conf alias eth0 tg3 alias eth1 e1000e alias eth2 e1000e |
目前我的网卡分别是 Broadcom - eth0 , Intel - eth1/eth2 3(eth0/eth1/eth2)个阜.接下来看一下 eth0 在 udev 储存了哪些资讯.可以使用指令 "udevinfo" 查看.
[root@benjr ~]# udevinfo -ap /sys/class/net/eth0 Udevinfo starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/class/net/eth0': looking at parent device '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0': ID=="0000:03:00.0" BUS=="pci" DRIVER=="tg3" SYSFS{broken_parity_status}=="0" SYSFS{enable}=="1" SYSFS{modalias}=="pci:v000014E4d0000165Asv00001014sd00000378bc02sc00i00" SYSFS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000" SYSFS{irq}=="58" SYSFS{class}=="0x020000" SYSFS{subsystem_device}=="0x0378" SYSFS{subsystem_vendor}=="0x1014" SYSFS{device}=="0x165a" SYSFS{vendor}=="0x14e4" looking at parent device '/devices/pci0000:00/0000:00:1c.1': looking at parent device '/devices/pci0000:00': |
udev 可以依据装置特性来个别命名,也就是说刚刚的 eth0 MAC 为 "00:1a:64:22:04:83" 我们就可以依据这个装置所提供的资讯来个别命名我们网路卡.udev 的设定档存放在 /etc/udev/rules.d/ 系统已经有一个是专门为网路卡预设的档案 "60-net.rules"
[root@benjr ~]# cd /etc/udev/rules.d/ |
60-net.rules 是系统预设的 rule
[root@benjr rules.d]# ll total 248 -rw-r--r-- 1 root root 515 Sep 12 17:34 05-udev-early.rules -rw-r--r-- 1 root root 920 Dec 11 06:03 40-multipath.rules -rw-r--r-- 1 root root 15647 Sep 12 17:34 50-udev.rules -rw-r--r-- 1 root root 163 Dec 4 05:32 51-dlm.rules -rw-r--r-- 1 root root 471 Sep 12 17:34 51-hotplug.rules -rw-r--r-- 1 root root 58016 Oct 13 2006 60-libsane.rules -rw-r--r-- 1 root root 143 Nov 13 23:48 60-net.rules -rw-r--r-- 1 root root 1088 Jul 18 2006 60-pcmcia.rules -rw-r--r-- 1 root root 452 Nov 26 07:15 60-raw.rules -rw-r--r-- 1 root root 8209 Sep 22 22:39 60-wacom.rules -rw-r--r-- 1 root root 129 Sep 10 00:11 61-uinput-stddev.rules -rw-r--r-- 1 root root 214 Sep 10 00:11 61-uinput-wacom.rules -rw-r--r-- 1 root root 1823 Sep 19 06:20 85-pcscd_ccid.rules -rw-r--r-- 1 root root 114 Aug 29 2008 90-alsa.rules -rw-r--r-- 1 root root 61 Sep 12 17:34 90-dm.rules -rw-r--r-- 1 root root 82 Oct 10 21:20 90-hal.rules -rw-r--r-- 1 root root 331 Oct 15 00:08 90-ib.rules -rw-r--r-- 1 root root 107 Sep 12 17:34 95-pam-console.rules -rw-r--r-- 1 root root 292 Dec 10 03:27 98-kexec.rules -rw-r--r-- 1 root root 2319 Jul 9 2008 bluetooth.rules -rw-r--r-- 1 root root 590 Dec 19 02:16 xen-backend.rules |
好的我们现在就依 "udevinfo" 所提供的资讯进行装置名称改变,我会依据系统的 driver 和 PCI Bus 顺序来为我的网卡命名.还记得 eth0 的资讯吗?
ID=="0000:03:00.0"
DRIVER=="tg3"
其他 eth1 /eth2 都是使用同样的方法 "udevinfo" 查出 ID 和 Driver
[root@benjr rules.d]# vi 60-net.rules ACTION=="add", SUBSYSTEM=="net", IMPORT{program}="/lib/udev/rename_device" SUBSYSTEM=="net", RUN+="/etc/sysconfig/network-scripts/net.hotplug" DRIVER=="tg3", ID=="0000:03:00.0", NAME="BCM1" DRIVER=="e1000e", ID=="0000:09:00.0", NAME="INTEL0" DRIVER=="e1000e", ID=="0000:09:00.1", NAME="INTEL1" |
重新将模组移除和载入.
[root@benjr rules.d]# rmmod tg3 [root@benjr rules.d]# rmmod e1000e [root@benjr rules.d]# modprobe tg3 [root@benjr rules.d]# modprobe e1000e [root@benjr rules.d]# ifconfig -a|grep -i HWaddr BCM1 Link encap:Ethernet HWaddr 00:1A:64:22:04:83 INTEL0 Link encap:Ethernet HWaddr 00:15:17:78:5D:D6 INTEL1 Link encap:Ethernet HWaddr 00:15:17:78:5D:D7 virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00 |
你会发现名称都依据你的需求改变了. 当然方式是千千万万种你也可以依据 MAC Address 的方式作依据.
#KERNEL=="eth*", SYSFS{address}=="00:1a:64:22:04:83", NAME="BCM1"
不过工作还没完成在 /etc/sysconfig/network-scripts/ 目录下还是有之前储存下来的装置名称,可以用手动方式移除修改或是用 #system-config-network 来修改!!