Command to change Ubuntu hostname through CLI without rebooting
hostnamectl set-hostname new-hostname
There are other useful options that you can use with hostamectl command
If you are a developer than showing the host information in json format you can add the –json pretty options to display the host information in Json pretty format for you to import into another application.