Linux下修改网卡接口名

简介: Linux下修改网卡接口名

                                     Linux下修改网卡接口名  



测试环境: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"

 

目录
相关文章
|
6月前
|
监控 网络协议 Linux
在Linux中,如何查看某个网卡是否连接着交换机?
在Linux中,如何查看某个网卡是否连接着交换机?
|
5月前
|
Linux 程序员 编译器
Linux内核驱动程序接口 【ChatGPT】
Linux内核驱动程序接口 【ChatGPT】
|
6月前
|
监控 Linux
在Linux中,如何查看网络接口的状态?
在Linux中,如何查看网络接口的状态?
|
5月前
|
域名解析 负载均衡 网络协议
Linux网络接口配置不当所带来的影响
总而言之,Linux网络接口的恰当配置是保证网络稳定性、性能和安全性的基础。通过遵循最佳实践和定期维护,可以最大程度地减少配置错误带来的负面影响。
225 0
|
5月前
|
Linux 测试技术 API
Linux PWM接口概述 【ChatGPT】
Linux PWM接口概述 【ChatGPT】
|
6月前
|
网络协议 Ubuntu Linux
在Linux中,如何将本地80端口的请求转发到8080端口,当前主机IP为192.168.16.1,其中本地网卡eth0。
在Linux中,如何将本地80端口的请求转发到8080端口,当前主机IP为192.168.16.1,其中本地网卡eth0。
|
6月前
|
Ubuntu Linux 网络安全
在Linux中,能否给⼀个网卡配置多个IP? 如果能,怎么配置?
在Linux中,能否给⼀个网卡配置多个IP? 如果能,怎么配置?
|
6月前
|
Ubuntu Linux
在Linux中,想修改ip,需要编辑哪个配置⽂件?修改完配置⽂件后,如何重启网卡?使配置生效?
在Linux中,想修改ip,需要编辑哪个配置⽂件?修改完配置⽂件后,如何重启网卡?使配置生效?
|
6月前
|
监控 Linux
在Linux中,如何实时查看网卡流量为多少?如何查看历史网卡流量?
在Linux中,如何实时查看网卡流量为多少?如何查看历史网卡流量?
|
6月前
|
网络协议 Ubuntu Linux
在Linux中, 如何配置网络接口?
在Linux中, 如何配置网络接口?