Login to your server: ssh user@server-name
Become a root user using either sudo -s or su -
To set the hostname to server1, run: hostnamectl set-hostname server1
Edit the file /etc/hosts and update entries: vi /etc/hosts
Verify it by running the hostnamectl command again.
hostnamectl set-hostname server1