修改主机名
# 方式一:
[root@local-work ~]# hostnamectl set-hostname local-work
# 需要重新登录或者执行一个解析器
# 方式二:
[root@local-work ~]# echo "string" > /etc/hostname
[root@local-work ~]# cat /etc/hostname
string
# 直接修改文件,不会立即生效,需要重启。
查看系统IP
# 方式一:
[root@string ~]# ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:20:7e:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.15.100/24 brd 192.168.15.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::962c:f186:8d31:5eec/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# 方式二:
[root@string ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.15.100 netmask 255.255.255.0 broadcast 192.168.15.255
inet6 fe80::962c:f186:8d31:5eec prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:20:7e:96 txqueuelen 1000 (Ethernet)
RX packets 119 bytes 11208 (10.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 102 bytes 14496 (14.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# 查看某一个网卡的信息
[root@string ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.15.100 netmask 255.255.255.0 broadcast 192.168.15.255
inet6 fe80::962c:f186:8d31:5eec prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:20:7e:96 txqueuelen 1000 (Ethernet)
RX packets 119 bytes 11208 (10.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 102 bytes 14496 (14.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
系统时间
[root@string ~]# date
Fri Mar 5 09:50:27 CST 2021
[root@string ~]# date +%Y-%m-%d
2021-03-05
# 格式化时间
[root@string ~]# # 09:58:30
[root@string ~]# date +%H:%M:%S
10:01:44
[root@string ~]# date +%Y-%m-%d_%H:%M:%S
2021-03-05_10:02:05
# 设置时间
[root@string ~]# date -s "2029-03-05 10:02:44"
Mon Mar 5 10:02:44 CST 2029
[root@string ~]# date +%Y-%m-%d_%H:%M:%S
2029-03-05_10:03:03
# 同步互联网时间
[root@string ~]# yum install -y ntpdate
[root@string ~]# ntpdate ntp.aliyun.com
# 系统硬件时钟
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:10:40 AM CST -0.271305 seconds
# 系统软件时钟
[root@string ~]# date
Mon Mar 5 10:03:30 CST 2029
# 获取硬件时间
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:13:19 AM CST -0.473926 seconds
# 将硬件时间同步到系统时间
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:13:19 AM CST -0.473926 seconds
[root@string ~]# date
Mon Mar 5 10:06:20 CST 2029
[root@string ~]# hwclock -s
[root@string ~]# date
Fri Mar 5 10:14:19 CST 2021
# 查看时区状态
[root@string ~]# timedatectl status
Local time: Fri 2021-03-05 10:26:39 CST
Universal time: Fri 2021-03-05 02:26:39 UTC
RTC time: Fri 2021-03-05 02:26:33
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
# 设置时区
[root@string ~]# timedatectl set-timezone Asia/Shanghai
重启和关机机器
[root@string ~]# reboot
[root@string ~]# init 6
[root@string ~]# shutdown -r 0
[root@string ~]# halt
# 重启
reboot
# 关机
shutdown -h 0