修改linux中的网卡名

如何修改linux中的网卡名

  • 用ip add 或者ip link 命令查看网络接口详细信息
[root@centos6 ~]# ip add
1: lo:  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:  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:  mtu 1500 qdisc noop state DOWN 
    link/ether 52:8f:9d:89:cb:a1 brd ff:ff:ff:ff:ff:ff
4: eth1:  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:  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:  mtu 1500 qdisc noop state DOWN 
    link/ether 52:8f:9d:89:cb:a1 brd ff:ff:ff:ff:ff:ff
5: eth0:  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:  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. 这样就不用重启就可以生效了。

你可能感兴趣的:(linux,基础)