博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android(Linux) 网卡名修改
阅读量:6799 次
发布时间:2019-06-26

本文共 4971 字,大约阅读时间需要 16 分钟。

配置文件的信息:

[root@ora10g network-scripts]# catifcfg-eth0

DEVICE="eth0"

NM_CONTROLLED="yes"

ONBOOT=yes

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.1.12

PREFIX=24

GATEWAY=192.168.1.1

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=no

NAME="System eth0"

UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03

HWADDR=08:00:27:BD:A6:ED

 

[root@ora10g network-scripts]# catifcfg-eth1

DEVICE="eth1"

NM_CONTROLLED="yes"

ONBOOT=yes

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.1.13

PREFIX=24

GATEWAY=192.168.1.1

DNS1=8.8.8.8

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="System eth1"

UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04

HWADDR=08:00:27:6E:86:10

 

这里对应的是网卡名称是eth0eth1.

 

但是如果我们使用ifconfig 命令查看:

[root@ora10g network-scripts]# ifconfig -a

eth2     Link encap:Ethernet  HWaddr08:00:27:BD:A6:ED 

         inet addr:192.168.1.12 Bcast:192.168.1.255 Mask:255.255.255.0

         inet6 addr: fe80::a00:27ff:febd:a6ed/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:1000

         RX bytes:16356 (15.9 KiB)  TXbytes:6116 (5.9 KiB)

 

eth3     Link encap:Ethernet  HWaddr08:00:27:6E:86:10 

         inet addr:192.168.1.13 Bcast:192.168.1.255 Mask:255.255.255.0

         inet6 addr: fe80::a00:27ff:fe6e:8610/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:1000

         RX bytes:120604 (117.7 KiB)  TXbytes:115937 (113.2 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:8 errors:0 dropped:0 overruns:0 frame:0

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

         collisions:0 txqueuelen:0

         RX bytes:480 (480.0 b)  TXbytes:480 (480.0 b)

 

这里的网卡名称是eth2eth3.

 

 

二.解决方法

 

 

修改 /etc/udev/rules.d/70-persistent-net.rules文件中的映射关系就可以了。

 

--修改之前:

[root@ora10g network-scripts]# cat/etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated bythe /lib/udev/write_net_rules

# program, run by thepersistent-net-generator.rules rules file.

#

# You can modify it, as long as you keepeach rule on a single

# line, and change only the value of theNAME= key.

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:d4:ab:67",ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:af:2b:37",ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:bd:a6:ed",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="eth*", NAME="eth2"

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6e:86:10",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="eth*", NAME="eth3"

 

 

 

--修改之后:

 

[root@ora10g network-scripts]# cat/etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated bythe /lib/udev/write_net_rules

# program, run by thepersistent-net-generator.rules rules file.

#

# You can modify it, as long as you keepeach rule on a single

# line, and change only the value of theNAME= key.

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6E:86:10",ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:BD:A6:ED",ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

注意这里的MAC地址要和ifcfg-eth0 保持一致。

 

 

然后重启一下网卡和udev

--ifdown 网卡:

ifdown eth0

ifdown eth1

 

--重启udev

/etc/init.d/udev-post stop;

/etc/init.d/udev-post start

或者使用:

service udev-post stop service udev-post start

 

注意: 对与Oracle linux 是udev-post, 而redhat 是udev

 

--ifup:

Ifup eth0

Ifup eth1

 

 

不过在我的测试中,这2个都没有效果,我是把整个OS都重启了,才生效的。 小知识,随笔记之。

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Ubuntu下更改eth0网卡名称为eth1

网卡MAC地址改变之后,在Linux中找到网卡,新的网卡会被识别为eth1或者更为靠后的网卡写入到/etc/udev/rules.d/70-persistent-net.rules这个文件中,修改/etc/udev/rules.d/70-persistent-net.rules这个文件,将eth0的MAC地址修改为改变后的地址就可以。

编辑

/etc/udev/rules.d/70-persistent-net.rules
root@shangyuan-laptop:/etc/udev/rules.d# more 70-persistent-net.rules
# This file maintains persistent names for network interfaces.
# See udev(7) for syntax.
#
# Entries are automatically added by the 75-persistent-net-generator.rules
# file; however you are also free to add your own entries.
# PCI device 0x14e4:0x1713 (tg3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1e:ec:0f:79:f
6", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x4222 (iwl3945)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1f:3c:48:70:b
1", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"
将其中的eth0,改为eth1,保存后重启系统即可。

 

 

 

 

 

 

 

 

转载地址:http://mduwl.baihongyu.com/

你可能感兴趣的文章
[bzoj1924] 所驼门王的宝藏
查看>>
form表单属性及表单分组
查看>>
<dxwgv:ASPxGridView
查看>>
小程序中通过判断id来删除数据,当数据长度为0时,显示隐藏部分(交流QQ群:604788754)...
查看>>
php把数据转换为json格式
查看>>
Java线程(学习整理)--2---加入另一个线程join
查看>>
replace into 浅析之一
查看>>
软件工程15 个人阅读作业2—提出问题
查看>>
Windows Azure Traffic Manager的新的管理API
查看>>
1.5站立会议之个人
查看>>
remote机制的AdditionalFields
查看>>
MySQL 常用内置函数与所有内置函数
查看>>
bzoj千题计划105:bzoj3503: [Cqoi2014]和谐矩阵(高斯消元法解异或方程组)
查看>>
Mybatis学习(4)输入映射、输出映射、动态sql
查看>>
java设计模式-策略模式
查看>>
iOS随笔记录
查看>>
objective-c面向对象
查看>>
Windows 7下Git SSH 创建Key【待解决?】
查看>>
阿里云服务器Linux CentOS安装配置(七)域名解析
查看>>
最长公共前缀---简单
查看>>