Each EC2 instance has a hostname, which is a label assigned to the instance that identifies it on the network.
The hostname is used to identify the instance when it communicates with other instances or services in the network. For example, if you have a web application running on an EC2 instance, the hostname is used to identify the instance when it communicates with a load balancer that distributes traffic to multiple instances.
launch the ec2 instance via connect or ssh method
login as sudo user sudo su
to know the details about hostname we type the command hostnamectl
now to change it we type
hostnamectl set-hostname rishi
got to directory /etc/hostname
here we have our hostname stored we can change it using any editor like vim nano etc i am using nano here
nano /etc/hostname it will open the editor now change the name and save the file using ctrl +S ctrl + x { to exit the editor }
hostnamectl to view the changed name !!