Before you start, try running hostname and hostname --fqdn and pay attention to the answers.
You can edit /etc/hostname and set the host name that will be inserted after reboot. You can force the hostname -F /etc/hostname be reloaded using hostname -F /etc/hostname to read this value in the hostname. The bash request will change after logging out and logging in.
warning / note :
Yes, itβs good if the host name in the bash prompt is set to something more useful than ip-123-123-123-123 , but I decided to leave mine (at least for now), because it seems that many things really count on the hostname on ec2 instances being set in a standard way. After editing /etc/hostname and changing the hostname on webserver many services seem to fail because the hostname will not be resolved and apache will not start. Then I edited /etc/hosts and added to
127.0.0.1 webserver
like the second line. Apache then started, but complained that it could not find the fully qualified domain name. I confirmed that running hostname --fqdn no longer works.
Next, I consulted with man hostname and found out that although you can set hostname , it seems that the FQDN is what is returned using DNS lookups.
FQDN
You cannot change the fully qualified domain name (as returned by the hostname --fqdn) or the DNS domain name (as returned by dnsdomainname) with this command. The fully qualified domain name of the system is the name that the resolver (3) returns for the host name.
Technically: FQDN is the name getaddrinfo (3) returns the host name returned by gethostname (2). The DNS domain is the part after the first dot.
Therefore it depends on the configuration (usually in /etc/host.conf) how you can change it. Usually (if the hosts file is parsed before DNS or NIS), you can change it in / etc / hosts.
I think that it would be possible to install the system / fool system in FQDN, something like ip-123-123-123-123.ec2.internal , although the host name is webserver , but at the moment it began to seem more unpleasant than it cost , and for me, a more pleasant bash hint might cause software and configuration problems in the future, and so I decided to give up.
I also found out that many instances of Amazon ec2 use something called cloud-init :
cloud-init is a Ubuntu package that handles the early initialization of a cloud instance. It is installed in Ubuntu cloud images, as well as in official Ubuntu images available on EC2.
Some of the settings that he configures are:
- default locale setting
- host name setting
- generate ssh private keys
- adding ssh keys to user .ssh / authorized_keys so that they can log in
- setting ephemeral mount points.
cloud-init behavior can be customized using custom data. User data can be provided by the user at the time the instance is started. This is done using the -user-data or -user-data-file argument to ec2-run instances
I also found this , which talks about how the hostname is configured using cloud-init:
On EBS instances, shutdown and subsequent start end with a different IP address.
In the case when the user has not changed / etc / hostname from its original value (seeded with metadata "local-hostname"), cloud-init will again set the host name and update / etc / hostname.
In the event that the user changes the name / etc / hostname, he will remain user-managed.
Also, if /etc/cloud/cloud.cfg contains the value "preserve_hostname" set to True, then the name / etc / hostname will never be affected.
An interesting conclusion is that if you do not change the host name, the cloud-init package will keep it relevant for you.
If someone has a workaround or can solve some of the problems mentioned, and help assure that nothing breaks on the ec2 instances due to a change in the host name, I would be glad to hear it.