linux 网口名称变了_Linux 下修改网卡接口名

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

https://jingyan.baidu.com/article/a3aad71afbcc99b1fb0096ba.html

作用

可以用于解决类似如下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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux系统中,网卡通常对应着网口。要确定网口对应的配置文件,可以通过以下几种方法来查找: 1. 使用ifconfig命令查看当前系统中的网卡信息。在终端中输入ifconfig命令,会列出当前系统中所有的网卡及其对应的IP地址、MAC地址等信息。通过观察网卡名称,如eth0、eth1等,可以确定网口对应的配置文件。 2. 查看/etc/sysconfig/network-scripts/目录下的配置文件。在该目录下,每个网卡对应一个配置文件,文件的格式通常为ifcfg-网卡名称,如ifcfg-eth0、ifcfg-eth1等。通过查看这些配置文件,可以确定网口对应的配置文件。 3. 使用ethtool命令查看网卡的详细信息。在终端中输入ethtool 网卡名称命令,如ethtool eth0,可以查看该网卡的详细信息,包括网口的标识符、驱动程序等。通过这些信息,可以确定网口对应的配置文件。 总结起来,要确定Linux系统中网口对应的配置文件,可以通过使用ifconfig命令、查看/etc/sysconfig/network-scripts/目录下的配置文件以及使用ethtool命令来获取相关信息。 #### 引用[.reference_title] - *1* [linux(服务器)如何确认网卡网口)对应的配置文件](https://blog.csdn.net/dbdd_cf/article/details/88863064)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值