centos基础设置

1.设置网络

# 配置网络
vi /etc/sysconfig/network-scripts/ifcfg-ens33
#将里面的onboard设置为yes

image

2.修改计算机名

使用命令行:
打开终端。 使用 hostnamectl 命令可以直接修改主机名。例如,如果您想将主机名更改为 mynewhostname,您可以使用以下命令:

sudo hostnamectl set-hostname mynewhostname

这个命令会立即更改主机名,但为了让更改在重启后依然有效,还需要编辑 /etc/hostname 文件。
编辑 /etc/hostname 文件:

使用文本编辑器打开 /etc/hostname 文件。您可以使用如 nano 或 vi 的编辑器。例如:
sudo vim /etc/hostname
在文件中,您会看到当前的主机名。将其更改为您想要的新主机名。保存并关闭文件。

编辑 /etc/hosts 文件:

有时,您还需要在 /etc/hosts 文件中更新主机名。打开该文件:

sudo vim /etc/hosts

找到与您的旧主机名相关的条目,将其替换为新的主机名。保存并关闭文件。

重启网络服务(可选):
为了使更改生效,您可能需要重启网络服务,可以使用以下命令:
sudo systemctl restart network
或者,您可以简单地重启计算机。

验证更改:
要验证主机名是否已更改,可以使用 hostnamectl 命令:
hostnamectl
[root@MiWiFi-RD03-srv ~]# sudo hostnamectl set-hostname rocky2024
[root@MiWiFi-RD03-srv ~]# sudo vim /etc/hosts
sudo: vim:找不到命令
[root@MiWiFi-RD03-srv ~]# sudo vi /etc/hosts
[root@MiWiFi-RD03-srv ~]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(rocky) at 23:56:51.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 

Connecting to 172.16.211.215:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Thu Aug 29 07:57:25 2024
[root@rocky2024 ~]# cat /etc/hosts
127.0.0.1   rocky2024
::1         rocky2024
[root@rocky2024 ~]# 

posted @ 2024-08-29 00:00  西江月明  阅读(6)  评论(0编辑  收藏  举报