一、更新系统时间与网络时间同步
1. 安装ntpdate工具
# yum -y install ntp ntpdate
2. 设置系统时间与网络时间同步
# ntpdate cn.pool.ntp.org
3. 将系统时间写入硬件时间
# hwclock --systohc
4.强制系统时间写入CMOS中防止重启失效
#hwclock -w
二、关机重启以及注销命令
1.关机
[root@jindada ~]# shutdown -h 10 #10分钟之后关机 以分钟为级别
[root@jindada ~]# shutdown -h now #立刻关机
[root@jindada ~]# shutdown -h 0 #立刻关机
[root@jindada ~]# shutdown -h 10:00 #定时关机
[root@jindada ~]# init 0 #立刻关机 通过切换运行级别进行关机
[root@jindada ~]# poweroff #立刻关机
[root@jindada ~]# halt #只关闭系统,需要手动关闭电源
[root@jindada ~]# halt -p #完全关闭主机
2.重启
[root@jindada ~]# shutdown -r now #立刻重启
[root@jindada ~]# shutdown -r 0 #立刻重启
[root@jindada ~]# shutdown -r 10 #10分钟之后进行重启
[root@jindada ~]# shutdown -r 10:05 #指定时间进行重启
[root@jindada ~]# init 6 #立刻重启,根据运行级别
[root@jindada ~]# reboot #立刻重启
3.取消定时关机或者重启
shutdown -c # 取消定时的关机或者重启
举例:
[root@jindada ~]# shutdown -h 12:00
Shutdown scheduled for Wed 2020-07-08 12:00:00 CST, use ‘shutdown -c‘ to cancel.
[root@jindada ~]# shutdown -c
Broadcast message from root@jindada (Tue 2020-07-07 15:16:37 CST):
The system shutdown has been cancelled at Tue 2020-07-07 15:17:37 CST!
[root@jindada ~]# shutdown -r 10:00
Shutdown scheduled for Wed 2020-07-08 10:00:00 CST, use ‘shutdown -c‘ to cancel.
[root@jindada ~]# shutdown -c
Broadcast message from root@jindada (Tue 2020-07-07 15:17:35 CST):
The system shutdown has been cancelled at Tue 2020-07-07 15:18:35 CST!
4.注销命令 退出当前登录的用户
1)Ctrl键 + d #注销 快捷键帮你执行了一个logout命令
2)logout #退出当前登录的用户,不能退出非登录式shell
3)exit #退出当前登录的用户,主要用于脚本退出
三、查看IP常用命令
Centos7默认显示IP地址的命令
#获取所有网卡的IP地址
[root@jindada ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:eb:ea:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::3310:9d15:9ee4:43e8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
====
[root@jindada ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:eb:ea:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::3310:9d15:9ee4:43e8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
#单独查看某个网卡的IP地址
[root@jindada ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:eb:ea:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::3310:9d15:9ee4:43e8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@jindada ~]# ip address show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:eb:ea:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::3310:9d15:9ee4:43e8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ifconfig是Centos6默认显示IP地址的命令
[root@jindada ~]# yum install -y net-tools
#所有的网卡的IP地址信息
[root@jindada ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::3310:9d15:9ee4:43e8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:eb:ea:8d txqueuelen 1000 (Ethernet)
RX packets 669 bytes 367883 (359.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 376 bytes 48482 (47.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#获取某一个网卡的信息
[root@jindada ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::3310:9d15:9ee4:43e8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:eb:ea:8d txqueuelen 1000 (Ethernet)
RX packets 699 bytes 370373 (361.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 394 bytes 51180 (49.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
hostname
#显示所有的IP地址,会显示IPv6的地址
[root@jindada ~]# hostname -i
fe80::3310:9d15:9ee4:43e8%eth0 10.0.0.100
#只显示IPv4地址
[root@jindada ~]# hostname -I
10.0.0.100
#如何获取到公网地址
[root@jindada ~]# curl ifconfig.me
139.226.13.64
[root@jindada ~]# curl cip.cc
IP : 139.226.13.64
地址 : 中国 上海
运营商 : 联通
数据二 : 上海市 | 联通
数据三 : 中国上海上海 | 联通
URL : http://www.cip.cc/139.226.13.64
注:常用命令总结:链接:https://pan.baidu.com/s/1XPTYYwC5VPHiVLi1e5Oaiw 提取码:370l
专用记事本链接:链接:https://pan.baidu.com/s/1nBxeLmO8YL6iGt0m2cfhyA 提取码:0bow