This is an English translation of a Japanese blog. Some content may not be fully translated.
AWS

Changing the EC2 Instance Hostname

Introduction


The prompt displayed when logging into EC2 looks ugly, so I want to explicitly change it. It’s slightly different from RHEL 7, so here’s a note.

[ec2-user@ip-10-0-0-9 local]#

Configuration Method


Change with hostnamectl
sudo hostnamectl set-hostname --static awsstg-db001
Edit /etc/cloud/cloud.cfg

Add preserve_hostname: true to the cfg file

sudo vi /etc/cloud/cloud.cfg
~ omitted ~
preserve_hostname: true
Reboot
[ec2-user@awsstg-db001 ~]$
[ec2-user@awsstg-db001 ~]$ hostname
awsstg-db001

Reference


AMAZON EC2 LINUX STATIC HOSTNAME RHEL7 CENTOS7 https://aws.amazon.com/jp/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/


Assigning a static hostname to a private Amazon EC2 instance on RHEL, CentOS, or Amazon Linux https://aws.amazon.com/jp/premiumsupport/knowledge-center/linux-static-hostname-rhel-centos-amazon/

Suggest an edit on GitHub