The authenticity of host 'u20 (fe80::2d84:3ce5:ee20:b4c0%19)' can't be established.
ECDSA key fingerprint is SHA256:KLbEClAS3vA2XtrNKv+SpzX4Vds/UdgQrWnGzpzOoA0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
本次会话有效的临时修改
更改hostname需要root权限
root@cxxuAli:~# sudo hostname testNew
root@cxxuAli:~# hostname
testNew
root@cxxuAli:~#
#可以看到,这种修改会临时变更hostname的返回值,但是提示符上的主机名仍然是旧的主机名
长期有效的修改
使用 hostnamectl
HOSTNAMECTL(1) hostnamectl HOSTNAMECTL(1)
NAME
hostnamectl - Control the system hostname
SYNOPSIS
hostnamectl [OPTIONS...] {COMMAND}
DESCRIPTION
hostnamectl may be used to query and change the system hostname and related settings.
This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's Laptop"), the
static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which is a fallback value received from
network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.
Note that the pretty hostname has little restrictions on the characters and length used, while the static and transient hostnames are limited to the usually accepted
characters of Internet domain names, and 64 characters at maximum (the latter being a Linux limitation).
The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see
machine-info(5).
Use systemd-firstboot(1) to initialize the system host name for mounted (but not booted) system images.
hostnamectl set-hostname选项
该选项可以修改三个方面的hostname
set-hostname NAME
Set the system hostname to NAME. By default, this will alter the pretty, the static, and the transient hostname alike; however, if one or more of --static,
--transient, --pretty are used, only the selected hostnames are changed. If the pretty hostname is being set, and static or transient are being set as well, the
specified hostname will be simplified in regards to the character set used before the latter are updated. This is done by removing special characters and spaces. This
ensures that the pretty and the static hostname are always closely related while still following the validity rules of the specific name. This simplification of the
hostname string is not doneif only the transient and/or static host names are set, and the pretty host name is left untouched.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了