With the help of hostname command you can set and view hostname of the system.
Look at the above snapshot, our hostname is JavaTpoint.
Using hostname command you can set it on the system.
Look at the above snapshot, we have set xyz.com as our hostname.
The above hostname is not permanent. Hostname set with command hostname are not permanent. On rebooting the system, hostname will change to the one that is specified in hostname file.
To set hostname permanently you have to save it in hostname file present on the server. After setting you have to reboot the box.
For Ubuntu, /etc/hostname file is used.
For RHEL, /etc/sysconfig/network is used.