Method 1:
To see hostname:
$ hostnamectl
$ hostnamectl status
$ hostname
To set host name to “centos7”, enter:
# hostnamectl set-hostname centos7
To set static host name to “centos7.example.com”, enter:
# hostnamectl set-hostname centos7.example.com --static
To restart the systemd-hostnamed service:
# systemctl restart systemd-hostnamed
To verify changes, enter:
# hostnamectl status
HOSTNAME=centos7.example.com
127.0.0.1 centos1.example.com
::1 centos1.example.com
To restart the systemd-hostnamed service:
# systemctl restart systemd-hostnamed
To verify changes, enter:
# hostnamectl status
To see hostname:
$ hostnamectl
$ hostnamectl status
$ hostname
To set host name to “centos7”, enter:
# hostnamectl set-hostname centos7
To set static host name to “centos7.example.com”, enter:
# hostnamectl set-hostname centos7.example.com --static
To restart the systemd-hostnamed service:
# systemctl restart systemd-hostnamed
To verify changes, enter:
# hostnamectl status
To reboot the system:
# rebootMethod 2:
Add the following entry to network file:
# nano /etc/sysconfig/networkHOSTNAME=centos7.example.com
Add the following entries to hosts file:
# nano /etc/hosts127.0.0.1 centos1.example.com
::1 centos1.example.com
To restart the systemd-hostnamed service:
# systemctl restart systemd-hostnamed
To verify changes, enter:
# hostnamectl status
To reboot the system:
# reboot