修改linux中的网卡名

17 篇文章 0 订阅

如何修改linux中的网卡名

  • 用ip add 或者ip link 命令查看网络接口详细信息
[root@centos6 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3d:56:58 brd ff:ff:ff:ff:ff:ff
    inet 192.168.27.128/24 brd 192.168.27.255 scope global eth0
    inet6 fe80::20c:29ff:fe3d:5658/64 scope link 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 52:8f:9d:89:cb:a1 brd ff:ff:ff:ff:ff:ff
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3d:56:62 brd ff:ff:ff:ff:ff:ff
    inet 172.18.16.20/16 brd 172.18.255.255 scope global eth1
    inet6 fe80::20c:29ff:fe3d:5662/64 scope link 
       valid_lft forever preferred_lft forever


  • 从上面看出有一个为eth1 的网卡,就把这个名字改成GOOD 的名字

操作
  1. 首先修改/etc/udev/rules./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)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3d:56:58", ATTR
{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3d:56:62", ATTR
{type}=="1", KERNEL=="eth*", NAME="GOOD"  # 找到刚刚eth1的对应的物理地址,修改这一段的name中的字段,变成自己想要的
  1. 由于修改后并不是立马生效,需要重启后生效,不想重启要让这个配置文件生效的办法就是卸载网卡驱动然后在重装
  2. 如何查看网卡驱动,用ethtool -i eth1
[root@centos6 ~]# ethtool -i eth1
driver: e1000  #这行显示驱动为e1000
version: 7.3.21-k8-NAPI
firmware-version: 
bus-info: 0000:02:05.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
[root@centos6 ~]# 
  1. 卸载网卡 modprobe -r e1000 ,
[root@centos6 ~]# modprobe -r e1000
这需要特别注意,由于我们的用的都是同一型号的网卡,所以驱动也一样
虽然有两个网卡,但是取得的都是一样的,所以卸载之后不能上网,也远程连接不了!!!!
  1. 由于把网卡驱动卸载了,所以们要在本地主机上操作,在把网卡驱动装上 modprobe e1000
[root@centos6 ~]# modprobe -r e1000
[root@centos6 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 52:8f:9d:89:cb:a1 brd ff:ff:ff:ff:ff:ff
5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3d:56:58 brd ff:ff:ff:ff:ff:ff
    inet 192.168.27.128/24 brd 192.168.27.255 scope global eth0
    inet6 fe80::20c:29ff:fe3d:5658/64 scope link 
       valid_lft forever preferred_lft forever
6: GOOD: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:3d:56:62 brd ff:ff:ff:ff:ff:ff
    inet 172.18.16.20/16 brd 172.18.255.255 scope global GOOD
    inet6 fe80::20c:29ff:fe3d:5662/64 scope link 
       valid_lft forever preferred_lft forever
[root@centos6 ~]# 
  1. 这样就不用重启就可以生效了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值