Linux命令 多种方式更改和查看系统的主机名hostname

1.设置主机名

(1)hostnamectl

# 设置新的主机名命令

hostnamectl set-hostname <新的主机名>

这条命令会删除/etc/hostname文件中的主机名,然后替换为新的主机名。

(2)配置/etc/hosts

# 主机添加一行包含主机IP地址与完整主机名的信息

vi /etc/hosts

内容如下:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
128.5.137.90 server1
128.5.137.91 agent1
128.5.137.92 agent2
128.5.137.93 agent3

# 重启网络服务

systemctl restart network

2.查看当前主机名

(1)查看主机名

hostname -f

[root@server1 home]# hostname -f
server1

(2)设置主机IP

hostname -i

[root@server1 home]# hostname -i
192.168.62.52

(3)主机名详细信息

 hostnamectl

[root@server1 home]# hostnamectl
Static hostname: server1
Icon name: computer-server
Chassis: server
Machine ID: cf266eb2f8074de9bfc37ad461213eb6
Boot ID: 5b2fdd387874499a9183bf6b9900d8cb
Operating System: CentOS Linux 7 (AltArch)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 4.14.0-115.el7a.0.1.aarch64
Architecture: arm64

猜你喜欢

转载自blog.csdn.net/qq_35260875/article/details/110450381