November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

hostnamectl and timedatectl and date and HWCLOCK

Modify CentOS 7 hostname

In CentOS, there are three definitions hostname: static (static), transient (transient), and flexible (pretty). “Static” host name is also called kernel hostname, is the system at boot time from /etc/hostname
automatic initialization of the host name. “Transient” host name is in the system is running temporarily assigned host name, for example, assigned by DHCP or mDNS server.
Static hostname and transient hostname comply with the same character as the Internet domain restriction rules. On the other hand, a “flexible” is allowed to use
the hostname of free-form (including special / whitespace) host name, to show to the end user (eg Linuxidc).

In CentOS 7, a man named hostnamectl command-line tool that allows you to view or modify the host name associated with the configuration.

[root@keeplive ~]# hostnamectl
Static hostname: keeplive
Icon name: computer
Chassis: n/a
Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15
Boot ID: 57772bec11854cd08ee72db54a1441d3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.9.3.el7.x86_64
Architecture: x86_64
[root@keeplive ~]# hostnamectl status
Static hostname: keeplive
Icon name: computer
Chassis: n/a
Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15
Boot ID: 57772bec11854cd08ee72db54a1441d3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.9.3.el7.x86_64
Architecture: x86_64
[root@keeplive ~]# hostnamectl –static
keeplive
[root@keeplive ~]# hostnamectl –transient
keeplive
[root@keeplive ~]# hostnamectl –pretty

timedatectl

How to display the current date and time using timedatectl ?

[root@keeplive ~]# timedatectl
Local time: Mon 2014-11-17 07:50:53 SGT
Universal time: Sun 2014-11-16 23:50:53 UTC
RTC time: Sun 2014-11-16 23:50:53
Timezone: Asia/Singapore (SGT, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

How to change the current date using timedatectl ?

timedatectl set-time YYYY-MM-DD

Example of change the current date :
[root@centos7 ~]# timedatectl set-time 2014-11-17

How to change the current time using timedatectl ?
timedatectl set-time HH:MM:SS

Example of change the current time :
[root@centos7 ~]# timedatectl set-time 00:50:00

[root@keeplive ~]# timedatectl list-timezones | grep Asia
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Chita
Asia/Choibalsan
Asia/Colombo
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Gaza
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kathmandu
Asia/Khandyga
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Kuwait
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Muscat
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Phnom_Penh
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qyzylorda
Asia/Rangoon
Asia/Riyadh
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Thimphu
Asia/Tokyo
Asia/Ulaanbaatar
Asia/Urumqi
Asia/Ust-Nera
Asia/Vientiane
Asia/Vladivostok
Asia/Yakutsk
Asia/Yekaterinburg
Asia/Yerevan
[root@keeplive ~]#

In order to change the time zone to Asia/Kuala_Lumpur, type the following command as a root user :
[root@centos7 ~]# timedatectl set-timezone Asia/Singapore

date Utility

The date utility is available on all Linux systems. date allows you to display and change the current date and time and it is frequently used in scripts to display the system clock.

2.1. How to display the current Date and Time using date ?

To display the current date and time, run the date command with no additional command line options:
[root@centos7 ~]# date
Tue Nov 4 01:12:39 MYT 2014

This displays the day of the week followed by the current date, local time, abbreviated time zone, and year.

2.2. How to display the current Date and Time in customized the format ?

You can also customize the format of the displayed information by providing the +”format” option on the command line:
date +”format”

Example :
[root@centos7 ~]# date +”%Y-%m-%d %H:%M”
2014-11-17 01:20

2.3. How to change the current time using date ?

In order to change the current date and time, type the date command with the –set or -s option as a root user :

To change the current time, run the date command with the –set or -s option as root:
date +%T -s HH:MM:SS

Replace HH with an hour, MM with a minute, and SS with a second, all typed in a two-digit form.

As an example change the current time to 11:56 p.m., as a root, run the following command :
[root@centos7 ~]# date +%T –set 23:56:00

[root@keeplive ~]# hwclock
Mon 17 Nov 2014 07:54:18 SGT -0.396692 seconds
[root@keeplive ~]#

How to change the current Date and Time using hwclock ?

In order to change the hardware clock date and time, you can do so by appending –set and –date options along with your specification:
hwclock –set –date “dd mmm yyyy HH:MM”

As an example, if we want to set the date and time to to “15:20, October 29, 2015?, run the command in the following format:
[root@centos7 ~]# hwclock –set –date “29 Oct 2015 15:20”

3.2. How to change the current Date and Time using hwclock ?

In order to change the hardware clock date and time, you can do so by appending –set and –date options along with your specification:
hwclock –set –date “dd mmm yyyy HH:MM”

As an example, if we want to set the date and time to to “15:20, October 29, 2015?, run the command in the following format:
[root@centos7 ~]# hwclock –set –date “29 Oct 2015 15:20”

Note : In Red Hat Enterprise Linux 6 / CentOS 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7 /CentOS 7.

For more information on how to configure the date and time in Red Hat Enterprise Linux 7 and CentOS 7, please read the manual page for the timedatectl, date and hwclock.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>