如何防止网卡名被修改和还原已被修改的网卡名

防止网卡名被修改的方法:

1.  修改/etc/grub.conf,添加biosdevname=0。修改之后,执行reboot,设备重启之后会生成/etc/udev/rules.d/70-persistent-net.rules文件。

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-279.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=e7856c23-1a60-489c-ba2b-4560b7235335 rd_NO_LUKS rd_NO_LVM crashkernel=auto selinux=0 rd_NO_MD SYSFONT=latarcyrheb-sun16  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM LANG=en_US.UTF-8 rhgb quiet biosdevname=0
    initrd /initramfs-2.6.32-279.el6.x86_64.img

 

网卡名已被udev修改,还原方法:

1.  对于名字已经被修改的网卡,在/etc/udev/rules.d/70-persistent-net.rules文件中显示的是修改后的网卡名(根据文件中的描述,只能修改NAME项)。修改该文件,把网卡名改为原来的名字,执行reboot,网卡便可恢复原来的名字。网上还有一种还原方法直接删除该文件即可,未尝试是否可行。

# 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:0x1521 (igb) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ca:3a:66:26:40", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"  # 把eth0改为em1

# PCI device 0x8086:0x1521 (igb) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ca:3a:66:26:42", ATTR{type}=="1", KERNEL=="eth*", NAME="em3"

# PCI device 0x8086:0x1521 (igb) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ca:3a:66:26:43", ATTR{type}=="1", KERNEL=="eth*", NAME="em4"

# PCI device 0x8086:0x1521 (igb) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ca:3a:66:26:41", ATTR{type}=="1", KERNEL=="eth*", NAME="em2"

 

问题

biosdevname是什么?

Biosdevname is a udev helper utility developed by Dell and released under the GNU General Public License (GPL). It provides a consistent naming mechanism for network devices based on their physical location as suggested by the system BIOS. 

biosdevname 是一款 udev 帮助程序,可根据系统 BIOS 提供的信息对网络接口进行重命名。

 

udev是什么?

udev 是linux用户空间设备管理(Linux userspace device management),在kernel 2.6.13后被使用,动态提供了在系统中实际存在的设备节点。

udev是提供/dev设备节点文件的动态创建和删除策略。

 

命名规则:

em<port>[_<virtual instance>]

for embedded NICs(主板嵌入式网卡,取代主板集成网口过去使用的 ethN 名称)

 

p<slot>p<port>[_<virtual instance>]

for cards in PCI slots(PCI 扩展网络接口)

 

参考:

http://linux.dell.com/biosdevname/

http://www.ibm.com/developerworks/cn/linux/l-cn-udev/

http://blog.sina.com.cn/s/blog_6abb5ca101018k09.html

http://blog.itpub.net/29479238/viewspace-1092035/

http://blog.chinaunix.net/uid-434226-id-3511206.html

http://manpages.ubuntu.com/manpages/quantal/en/man1/biosdevname.1.html

 

posted on 2015-11-27 10:44  yilipika  阅读(2202)  评论(0编辑  收藏  举报