CentOS7修改网卡名

发布时间 2023-07-14 10:31:48作者: Gao科技

CentOS 7, 或RHEL7

[1] https://www.redhat.com/sysadmin/network-interfaces-linux, The name game: Naming network interfaces in Linux
可以使用nameif, ifrename, ip; centos7上没找到ifrename; nameif根据mac命令; 试过ip, 提示Resource Busy.
[2] http://www.mit.edu/afs.new/sipb/project/merakidev/src/openwrt-meraki/openwrt/build_mips/wireless_tools.28/IFRENAME-VS-XXX.txt
比较了各种方法, 没有操作步骤
[3] 11.2. Understanding the Device Renaming Procedure Red Hat Enterprise Linux 7 | Red Hat Customer Portal
[4] https://www.cyberciti.biz/faq/howto-linux-rename-ethernet-devices-named-using-udev/
我的系统中没有找到/etc/udev/rules.d/70-persistent-net.rules

下面操作根据规则60-net.rules[3]:

A rule in /usr/lib/udev/rules.d/60-net.rules instructs the udev helper utility, /lib/udev/rename_device, to look into all /etc/sysconfig/network-scripts/ifcfg-suffix files. If it finds an ifcfg file with a HWADDR entry matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive.

cd /etc/sysconfig/network-scripts/
cp ifcfg-old ifcfg-new
ifconfig -a | grep ether # 获取hwaddr
vi ifcfg-new # 把DEVICE和NAME改为'new', 添加HWADDR="11:22:...."

# cat ifcfg-em0
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="em0"
UUID="721603be-3ee4-4f93-af05-a3c6eb4cfef0"
DEVICE="em0"
ONBOOT="yes"
IPADDR="172.16.56.103"
PREFIX="24"
GATEWAY="172.16.56.1"
IPV6_PRIVACY="no"
HWADDR="00:15:5d:8c:01:06"

重启系统.

有没有不需要重启系统的办法? todo