Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Before you get started, try running <code>hostname</code> and <code>hostname --fqdn</code> and take note of what the responses are.</p> <p>You can edit <code>/etc/hostname</code> and set a hostname, which will stick around after rebooting. You can force the hostname to be "reloaded" by using <code>hostname -F /etc/hostname</code> to read that value into the hostname. The bash prompt will change after you logout and login.</p> <p><strong>warning / note</strong>:<br> Yes, it is nice to have the hostname in the bash prompt set to something more useful than <code>ip-123-123-123-123</code> but I've decided to leave mine (at least for now) because it seems like a lot of things really count on having the hostname on ec2 instances set in a standard way. After editing <code>/etc/hostname</code> and changing the hostname to <code>webserver</code> a lot of the services seems to fail because the hostname would not resolve, and apache wouldn't start. Next I edited <code>/etc/hosts</code> and added in </p> <pre><code>127.0.0.1 webserver </code></pre> <p>as the second line. Apache would then start but complained that it couldn't find the FQDN. I confirmed that running <code>hostname --fqdn</code> no longer worked.</p> <p>Next I consulted <code>man hostname</code> and learned that while you can set the <code>hostname</code> it appears that the <code>FQDN</code> is what is returned via a DNS lookup. </p> <blockquote> <h3>THE FQDN</h3> <p>You can't change the FQDN (as returned by hostname --fqdn) or the DNS domain name (as returned by dnsdomainname) with this command. The FQDN of the system is the name that the resolver(3) returns for the host name.</p> <p>Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot.</p> <p>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.</p> </blockquote> <p>I think it might be possible to set the system / fool the system into return the FQDN, something like <code>ip-123-123-123-123.ec2.internal</code> even though the hostname is <code>webserver</code> but at this point it started to seem like more trouble than it was worth, and that for me to have a nicer bash prompt might cause a lot software and configuration problems down the road and so I decided to give up.</p> <p>I also learned that a lot of amazon ec2 instances use something called <a href="https://help.ubuntu.com/community/CloudInit" rel="noreferrer">cloud-init</a>:</p> <blockquote> <p>cloud-init is the Ubuntu package that handles early initialization of a cloud instance. It is installed in the Ubuntu Cloud Images and also in the official Ubuntu images available on EC2.</p> <p>Some of the things it configures are:</p> <ul> <li>setting a default locale</li> <li>setting hostname</li> <li>generate ssh private keys</li> <li>adding ssh keys to user's .ssh/authorized_keys so they can log in</li> <li>setting up ephemeral mount points</li> </ul> <p>cloud-init's behavior can be configured via user-data. User-data can be given by the user at instance launch time. This is done via the --user-data or --user-data-file argument to ec2-run-instances</p> </blockquote> <p><a href="https://code.launchpad.net/~clint-fewbar/cloud-init/glusterfs-mount-example" rel="noreferrer">I also found this</a> which talks about how the hostname is configured with cloud-init:</p> <blockquote> <p>On EBS instances, a shutdown and later start would end up with a different IP address. </p> <p>In the case where the user has not modified /etc/hostname from its original value (seeded by metadata's 'local-hostname'), then cloud-init will again set the hostname and update /etc/hostname. </p> <p>In the case where the user has modified /etc/hostname, it will remain user managed. </p> <p>Additionally, if /etc/cloud/cloud.cfg contains 'preserve_hostname' value set to a True value, then /etc/hostname will not ever be touched.</p> </blockquote> <p>The interesting takeaway is that if you don't change the hostname the cloud-init package will keep it up to date for you.</p> <p>If someone else has a workaround or can address some of the issues mentioned and help reassure that nothing will break on ec2 instances because of changing the hostname I would be happy to hear it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload