更改centos的网卡名
Centos6更改网卡名的方法:
1、修改皮配置文件/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)
- SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:7a:b6:42", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
NAME:设备名
address:MAC地址
CENTOS6主要是通过address(MAC)来确定网卡,然后修改NAME的值为目标网卡名来改名的,现在我们修改NAME的值为“Hello0”
修改配置文件之后,还没有加载到内核中,如何加载到内核中,要么重启,要么执行以下操作:
- [root@joker-6-01 rules.d]# dmesg | grep -i eth #dmesg(打印内核环内的缓冲区)
- e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:7a:b6:42
- e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
- e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
- eth0: no IPv6 routers present
- 8021q: adding VLAN 0 to HW filter on device eth0
或者使用 ethtool -i eth0 #查看指定网卡驱动也行
- [root@joker-6-01 rules.d]# ethtool -i eth0
- driver: e1000
- version: 7.3.21-k8-NAPI
- firmware-version:
- bus-info: 0000:02:01.0
- supports-statistics: yes
- supports-test: yes
- supports-eeprom-access: yes
- supports-register-dump: yes
- supports-priv-flags: no
- lsmod | grep e1000 #确认e1000是网卡模块
卸载网卡驱动:
- modprobe -r e1000 或 rmmod e1000 #慎重操作,执行之后,根据网络情况,网络会断开,请确认卸载之后能够操作到主机之后再执行此操作
装载网卡驱动:
- modprobe e1000
查看下网卡名:
- [root@joker-6-01 ~]# ip a s
- 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: Hello0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:7a:b6:42 brd ff:ff:ff:ff:ff:ff
- inet 192.168.253.130/24 brd 192.168.253.255 scope global Hello0
- inet6 fe80::20c:29ff:fe7a:b642/64 scope link
- valid_lft forever preferred_lft forever
OK修改完毕
Centos7更改网卡名的方法:
CentOS 6之前,网络接口使用连续号码命名:eth0、eth1等,当增加或删除网卡时,名称可能会发生变化,CentOS 7使用基于硬件,设备拓扑和设置类型命名方式,使网卡名唯一化,不变动。但是这项特性又增加个管理的的难度,所以一般我们都会把网卡名改回eth已方便我们的管理。
网卡设备的命名过程:
第一步:
udev, 辅助工具程序/lib/udev/rename_device /usr/lib/udev/rules.d/60-net.rules
第二步:
biosdevname 会根据/usr/lib/udev/rules.d/71-biosdevname.rules
第三步:
通过检测网络接口设备,根据 /usr/lib/udev/rules.d/75-net-description
ID_NET_NAME_ONBOARD
ID_NET_NAME_SLOT
ID_NET_NAME_PATH
改名方法和简单:
修改/etc/default/grub
1、“GRUB_CMDLINE_LINUX=” 这一行,在quiet 后面添加 net.ifnames=0
2、位grub2重新生成配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
3、reboot