hostnamectl
Hostnamectl可用于查询和更改系统主机名及相关设置。
[waterruby@192 init.d]$ hostnamectl -h
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
Commands:
status Show current hostname settings
hostname [NAME] Get/set system hostname
icon-name [NAME] Get/set icon name for host
chassis [NAME] Get/set chassis type for host
deployment [NAME] Get/set deployment environment for host
location [NAME] Get/set location for host
Options:
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
--json=pretty|short|off
Generate JSON output
- status
See the hostnamectl(1) man page for details.
[waterruby@192 init.d]$ hostnamectl status
Static hostname: (unset)
Transient hostname: 192.168.0.110
Icon name: computer-vm
Chassis: vm ?
Machine ID: d586137836e24c218074ea62f04ba5e8
Boot ID: 1dd7c39875b74b759f451398b0a168e4
Virtualization: kvm
Operating System: AlmaLinux 9.2 (Turquoise Kodkod)
CPE OS Name: cpe:/o:almalinux:almalinux:9::baseos
Kernel: Linux 5.14.0-284.30.1.el9_2.x86_64
Architecture: x86-64
Hardware Vendor: QEMU
Hardware Model: Standard PC _Q35 + ICH9, 2009_
Firmware Version: 1.16.2-1.fc38
[waterruby@192 init.d]$
timedatectl
[waterruby@192 init.d]$ timedatectl
Local time: 三 2023-10-25 23:33:41 CST
Universal time: 三 2023-10-25 15:33:41 UTC
RTC time: 三 2023-10-25 15:33:41
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
list-timezones
Commands:
status Show current time settings
show Show properties of systemd-timedated
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Enable or disable network time synchronization