How to Setup Hostname and Timezone On CentOS 7

Setting up host name and server time zone are part of initial basic server configuration. Hostname is the name of the machine.

Setting up Hostname

1. To setup hostname:

hostnamectl set-hostname hostname

2. You can verify by running the command:

hostname

3. You need to update the /etc/hosts file. This file creates static associations between IP addresses and hostnames, with higher priority than DNS.

nano /etc/hosts

4. Add a line for public IP address with the local hostname:

server-ip-address hostname

Setting up Timezone

By default, time zone is set to UTC time (Greenwich Mean Time).

1. To view the list of available time zones:

timedatectl list-timezones

Find the time zone which you want. Then, press q to exit the list.

2. To set the time zone:

timedatectl set-timezone 'America/New_York'

3 To view the current date and time according to your server:

date

That's it!