分享

linux(CentOS 6)下如何调整eth网卡顺序

nettman 发表于 2014-1-19 01:10:34 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 0 17135
本帖最后由 nettman 于 2014-1-19 01:13 编辑

在虚拟机下安装的CentOS6.0,用克隆的方法,一下搞了好几个CentOS6.0的虚拟机,进入系统之后却发现网卡的序号不再是eth0,而是eth1。

运行ifconfig -a的效果如下:

CentOS6-ifconfig-a-150x150.png

以前CentOS 5.x版本的时候,在/etc/modprobe.conf里面可以定义网卡的顺序,通过:
  1. alias eth0 e1000e
复制代码
这种方法来定义。

但是在CentOS6中,已经不存在/etc/modprobe.conf文件了,在/etc/modprobe.d下也不存在对网卡进行配置的配置文件:
  1. [root@localhost modprobe.d]# pwd
  2. /etc/modprobe.d
  3. [root@localhost modprobe.d]# grep eth0 *
  4. [root@localhost modprobe.d]#
复制代码
经过分析发现,CentOS 6.0开始通过udev来管理网卡,具体网卡序号的配置文件在:/etc/udev/rules.d/70-persistent-net.rules文件中,其内容为:
  1. # This file was automatically generated by the /lib/udev/write_net_rules
  2. # program, run by the persistent-net-generator.rules rules file.
  3. #
  4. # You can modify it, as long as you keep each rule on a single
  5. # line, and change only the value of the NAME= key.
  6. # PCI device 0x15ad:0x07b0 (vmxnet3) (custom name provided by external tool)
  7. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:00:00", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
  8. # PCI device 0x15ad:0x07b0 (vmxnet3)
  9. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:00:0e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
复制代码
从上面可以看出,原来的eth0网卡是安装CentOS6那台虚拟机的网卡配置(关键是MAC地址),克隆后虚拟网卡的MAC修改了,所以系统自动生成相应的配置文件,网卡序号为eth1,所以在系统中只能看到eth1。

将/etc/udev/rules.d/70-persistent-net.rules修改:
  1. # This file was automatically generated by the /lib/udev/write_net_rules
  2. # program, run by the persistent-net-generator.rules rules file.
  3. #
  4. # You can modify it, as long as you keep each rule on a single
  5. # line, and change only the value of the NAME= key.
  6. # PCI device 0x15ad:0x07b0 (vmxnet3)
  7. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:00:0e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
复制代码
加微信w3aboutyun,可拉入技术爱好者群

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条