专栏首页授客的专栏Linux 下修改网卡接口名

Linux 下修改网卡接口名

Linux下修改网卡接口名

by:授客

(测试环境:CentOS-6.0-x86_64-bin-DVD1.iso+Vmware)

作用

可以用于解决类似如下Device not found的问题:

# ifconfig eth1

eth1: error fetching interface information: Device not found

例1:把网卡接口名从eth0改为eth1

#修改网卡接口名之前的相关信息如下

# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:F3:8B:8A

inet addr:172.25.75.4 Bcast:172.25.75.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fef3:8b8a/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:472 errors:0 dropped:0 overruns:0 frame:0

TX packets:95 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:42666 (41.6 KiB) TX bytes:11536 (11.2 KiB)

# ifconfig -a

eth0 Link encap:Ethernet HWaddr 00:0C:29:F3:8B:8A

inet addr:172.25.75.4 Bcast:172.25.75.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fef3:8b8a/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:503 errors:0 dropped:0 overruns:0 frame:0

TX packets:106 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:46425 (45.3 KiB) TX bytes:13230 (12.9 KiB)

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

# cat /etc/udev/rules.d/70-persistent-net.rules

[root@localhost ~]# cat /etc/udev/rules.d/70-persistent-net.rules

# 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:0x100f (e1000) (custom name provided by external tool)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:f3:8b:8a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

步骤1.修改网卡接口配置文件

#把eth0对应的配置文件ifcfg-eth0重命名为ifcfg-eth1--如要设置网卡接口名为ethN,则重命名为ifcfg-ethN

# cd /etc/sysconfig/network-scripts/

# mv ifcfg-eth0 ifcfg-eth1

说明:如果网卡接口名为ethN,则对应的配置文件为ifcfg-ethN

#修改ifcfg-eth1配置文件,把DEVICE="eth0"改成DEVICE="eth1"

# vi ifcfg-eth1

DEVICE="eth1"--如要设置网卡接口名为ethN,则此处DEVICE="ethN"

BOOTPROTO=static

HADDR="00:0c:29:f3:8b:8a"

IPADDR=172.25.75.4

NETMASK=255.255.255.0

NETWORK=172.25.75.0

NM_CONTROLLED="yes"

ONBOOT="yes"

GATEWAY=172.25.75.254

步骤2.修改70-persistent-net.rules配置文件

修改70-persistent-net.rules文件,找到包含原始MAC地址的记录,把NAME="eth0"改成NAME="eth1"

# vi /etc/udev/rules.d/70-persistent-net.rules

# 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:0x100f (e1000) (custom name provided by external tool)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:f3:8b:8a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" --如要设置网卡接口名为ethN,则此处为NAME="ethN"

注意:

1.如果存在多条仅NAME的值不一样的记录,则删除多余的记录,仅保留一条记录

2.如果有对网卡MAC地址进行修改过,即网卡mac地址并非原始mac地址,则推荐步骤2之前进行如下操作:

70-persistent-net.rules文件:

# rm /etc/udev/rules.d/70-persistent-net.rules

# reboot

说明:重启后,系统自动重新生成70-persistent-net.rules文件,里面记录中的包含的MAC地址为对应网卡的原始MAC地址

步骤3.重启系统

# reboot

注意:此处# service network restart 命令不起作用,必须重启

步骤4.验证是否已经修改

如下,网卡接口名已经变成eth1

[root@localhost ~]# ifconfig eth1

eth1 Link encap:Ethernet HWaddr 00:0C:29:F3:8B:8A

inet addr:172.25.75.4 Bcast:172.25.75.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fef3:8b8a/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:45 errors:0 dropped:0 overruns:0 frame:0

TX packets:53 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:4693 (4.5 KiB) TX bytes:7766 (7.5 KiB)

[root@localhost ~]# ifconfig -a

eth1 Link encap:Ethernet HWaddr 00:0C:29:F3:8B:8A

inet addr:172.25.75.4 Bcast:172.25.75.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fef3:8b8a/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:73 errors:0 dropped:0 overruns:0 frame:0

TX packets:60 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:7091 (6.9 KiB) TX bytes:9004 (8.7 KiB)

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

# cat /etc/udev/rules.d/70-persistent-net.rules

# 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:0x100f (e1000) (custom name provided by external tool)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:f3:8b:8a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • MySQL 纵表转横表查询实现

    INSERT INTO tb_test(attr, attr_value) VALUES('age', 18), ('sex', '男'), ('name', ...

    授客
  • loadrunner 运行脚本-Run-time Settings->General->Additional attributes设置

    为Vuser脚本提供额外自定义参数。额外参数设置可应用于所有Vuser脚本类型。

    授客
  • loadrunner 脚本开发-调用java jar文件远程操作Oracle数据库测试

    备注:想学oracle的同学,建议在Linux、Unix平台下进行学习,如果觉得安装麻烦,可以加全国软件性能测试交流群:7156436,免费获取Oracle_...

    授客
  • 想轻松复现深度强化学习论文?看这篇经验之谈

    选自Amid Fish 作者:Matthew Rahtz 机器之心编译 近期深度强化学习领域日新月异,其中最酷的一件事情莫过于 OpenAI 和 DeepMin...

    机器之心
  • 《长安十二时辰》背后的文娱大脑:如何提升爆款的确定性?

    大家好,我是来自优酷内容智能团队的资深技术专家牧己,主要负责基于大数据和人工智能去解决内容方面的问题。接下来,我将以《长安十二时辰》为例,分享优酷在提升“爆款确...

    LiveVideoStack
  • CSS入门

    大家都知道,学习前端,有三大神器,html+css+js。如果用武学来比喻,html就好像骨架身躯,学习html就是习武之人所谓的打熬身体,身体底子好,习武才能...

    love丁酥酥
  • 玩转「Wi-Fi」系列之常用命令(四)

    Ping是Linux系统常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着。它是通过发送ICMP ECHO_REQ...

    程序手艺人
  • 以色列神秘AI研究力量:深度学习的四大失败(视频+论文+ppt下载)

    编译 / 刘小芹 弗格森 转自 / 新智元(微信号:AI_era) 原文网址 / simons.berkeley.edu 近年来,深度学习已经成为了大量应用转...

    量化投资与机器学习微信公众号
  • 亚马逊云计算业务的营收明显减低

    电商巨头亚马逊的云计算服务AWS(Amazon Web Services)一直是公司在近几个季度增长比较快的业务,但是随着谷歌和微软等科技巨头以及一系列新创企业...

    静一
  • 以色列神秘AI研究力量:深度学习的四大失败

    【新智元导读】深度学习力量强大,但无论是理论研究者还是实际从业者,了解深度学习的局限也是十分重要的。耶路撒冷希伯来大学的一组研究人员,其中有两位任职于 Mobi...

    新智元

扫码关注云+社区

领取腾讯云代金券