Linux主机名和网卡名修改

网卡设备的命名过程:
第一步:
udev, 辅助工具程序/lib/udev/rename_device
/usr/lib/udev/rules.d/60-net.rules
第二步:
biosdevname 会根据/usr/lib/udev/rules.d/71biosdevname.rules
第三步:
通过检测网络接口设备,根据/usr/lib/udev/rules.d/75-net-description
ID_NET_NAME_ONBOARD
ID_NET_NAME_SLOT
ID_NET_NAME_PATH

Centos6

网络接口识别并命名相关的udev配置文件:
[root@centos6 ~]#cat /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:23:71:94", ATTR{type}=="1", KERNEL=="eth", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="00:0c:29:23:71:9e", ATTR{type}=="1", KERNEL=="eth", NAME="eth1"
[root@centos6 ~]#
通过修改配置文件,可以修改网卡名称

Centos7

采用传统命名方式
使用传统命名方式:
(1) 编辑/etc/default/grub配置文件
GRUB_CMDLINE_LINUX="rhgb quiet net.ifnames=0"
sed -r 's/(quiet)/\1 net.ifnames=0/' /etc/default/grub
或直接修改/boot/grub2/grub.cfg 
(2) 为grub2生成其配置文件
grub2-mkconfig -o /etc/grub2.cfg
(3) 重启系统

CentOS 7网络配置工具
CentOS7主机名
配置文件:/etc/hostname 默认没有此文件,通过DNS反向解析获取主机名,主机名默认为:localhost.localdomain
显示主机名信息
hostname hostnamectl status
设置主机名
hostnamectl set-hostname centos7.magedu.com
删除文件/etc/hostname,恢复主机名localhost.localdomain
CentOS 7网络配置工具
图形工具:nm-connection-editor
字符配置tui工具:nmtui

你可能感兴趣的:(Linux主机名和网卡名修改)